from nose.tools import *  # flake8: noqa

from tests.base import ApiTestCase
from osf_tests.factories import InstitutionFactory, UserFactory

from api.base.settings.defaults import API_BASE

class TestInstitutionUsersList(ApiTestCase):
    def setUp(self):
        super(TestInstitutionUsersList, self).setUp()
        self.institution = InstitutionFactory()
        self.user1 = UserFactory()
        self.user1.affiliated_institutions.add(self.institution)
        self.user1.save()
        self.user2 = UserFactory()
        self.user2.affiliated_institutions.add(self.institution)
        self.user2.save()

        self.institution_user_url = '/{0}institutions/{1}/users/'.format(API_BASE, self.institution._id)

    def test_return_all_users(self):
        res = self.app.get(self.institution_user_url)

        assert_equal(res.status_code, 200)

        ids = [each['id'] for each in res.json['data']]
        assert_equal(len(res.json['data']), 2)
        assert_in(self.user1._id, ids)
        assert_in(self.user2._id, ids)

import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
    InstitutionFactory,
    UserFactory,
)

@pytest.mark.django_db
class TestInstitutionUsersList:

    @pytest.fixture()
    def institution(self):
        return InstitutionFactory()

    @pytest.fixture()
    def user_one(self, institution):
        user_one = UserFactory()
        user_one.affiliated_institutions.add(institution)
        user_one.save()
        return user_one

    @pytest.fixture()
    def user_two(self, institution):
        user_two = UserFactory()
        user_two.affiliated_institutions.add(institution)
        user_two.save()
        return user_two

    @pytest.fixture()
    def url_institution_user(self, institution):
        return '/{0}institutions/{1}/users/'.format(API_BASE, institution._id)

    def test_return_all_users(self, app, institution, user_one, user_two, url_institution_user):
        res = app.get(url_institution_user)

        assert res.status_code == 200

        ids = [each['id'] for each in res.json['data']]
        assert len(res.json['data']) == 2
        assert user_one._id in ids
        assert user_two._id in ids

Convert institutions users to pytest
Convert institutions users to pytest

+ import pytest
- from nose.tools import *  # flake8: noqa
- 
- from tests.base import ApiTestCase
- from osf_tests.factories import InstitutionFactory, UserFactory
  
  from api.base.settings.defaults import API_BASE
+ from osf_tests.factories import (
+     InstitutionFactory,
+     UserFactory,
+ )
  
+ @pytest.mark.django_db
- class TestInstitutionUsersList(ApiTestCase):
+ class TestInstitutionUsersList:
-     def setUp(self):
-         super(TestInstitutionUsersList, self).setUp()
-         self.institution = InstitutionFactory()
-         self.user1 = UserFactory()
-         self.user1.affiliated_institutions.add(self.institution)
-         self.user1.save()
-         self.user2 = UserFactory()
-         self.user2.affiliated_institutions.add(self.institution)
-         self.user2.save()
  
-         self.institution_user_url = '/{0}institutions/{1}/users/'.format(API_BASE, self.institution._id)
+     @pytest.fixture()
+     def institution(self):
+         return InstitutionFactory()
  
-     def test_return_all_users(self):
-         res = self.app.get(self.institution_user_url)
+     @pytest.fixture()
+     def user_one(self, institution):
+         user_one = UserFactory()
+         user_one.affiliated_institutions.add(institution)
+         user_one.save()
+         return user_one
  
+     @pytest.fixture()
+     def user_two(self, institution):
+         user_two = UserFactory()
+         user_two.affiliated_institutions.add(institution)
+         user_two.save()
+         return user_two
+ 
+     @pytest.fixture()
+     def url_institution_user(self, institution):
+         return '/{0}institutions/{1}/users/'.format(API_BASE, institution._id)
+ 
+     def test_return_all_users(self, app, institution, user_one, user_two, url_institution_user):
+         res = app.get(url_institution_user)
+ 
-         assert_equal(res.status_code, 200)
+         assert res.status_code == 200
  
          ids = [each['id'] for each in res.json['data']]
-         assert_equal(len(res.json['data']), 2)
+         assert len(res.json['data']) == 2
-         assert_in(self.user1._id, ids)
-         assert_in(self.user2._id, ids)
+         assert user_one._id in ids
+         assert user_two._id in ids
  
Convert institutions users to pytest
## Code Before:
from nose.tools import *  # flake8: noqa

from tests.base import ApiTestCase
from osf_tests.factories import InstitutionFactory, UserFactory

from api.base.settings.defaults import API_BASE

class TestInstitutionUsersList(ApiTestCase):
    def setUp(self):
        super(TestInstitutionUsersList, self).setUp()
        self.institution = InstitutionFactory()
        self.user1 = UserFactory()
        self.user1.affiliated_institutions.add(self.institution)
        self.user1.save()
        self.user2 = UserFactory()
        self.user2.affiliated_institutions.add(self.institution)
        self.user2.save()

        self.institution_user_url = '/{0}institutions/{1}/users/'.format(API_BASE, self.institution._id)

    def test_return_all_users(self):
        res = self.app.get(self.institution_user_url)

        assert_equal(res.status_code, 200)

        ids = [each['id'] for each in res.json['data']]
        assert_equal(len(res.json['data']), 2)
        assert_in(self.user1._id, ids)
        assert_in(self.user2._id, ids)

## Instruction:
Convert institutions users to pytest
## Code After:
import pytest

from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
    InstitutionFactory,
    UserFactory,
)

@pytest.mark.django_db
class TestInstitutionUsersList:

    @pytest.fixture()
    def institution(self):
        return InstitutionFactory()

    @pytest.fixture()
    def user_one(self, institution):
        user_one = UserFactory()
        user_one.affiliated_institutions.add(institution)
        user_one.save()
        return user_one

    @pytest.fixture()
    def user_two(self, institution):
        user_two = UserFactory()
        user_two.affiliated_institutions.add(institution)
        user_two.save()
        return user_two

    @pytest.fixture()
    def url_institution_user(self, institution):
        return '/{0}institutions/{1}/users/'.format(API_BASE, institution._id)

    def test_return_all_users(self, app, institution, user_one, user_two, url_institution_user):
        res = app.get(url_institution_user)

        assert res.status_code == 200

        ids = [each['id'] for each in res.json['data']]
        assert len(res.json['data']) == 2
        assert user_one._id in ids
        assert user_two._id in ids
