def test_user_get(self):
        """Test authenticated user can access user info"""
        request = self.factory.get('/', **self.extra)

        # users list
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)

        # user with username BoB, mixed case
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.data, self.data)

        # user bob is_active = False
        self.user.is_active = False
        self.user.save()

        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 404)
示例#2
0
    def test_user_get(self):
        """Test authenticated user can access user info"""
        request = self.factory.get('/', **self.extra)

        # users list
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)

        # user with username BoB, mixed case
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.data, self.data)

        # user bob is_active = False
        self.user.is_active = False
        self.user.save()

        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 404)
示例#3
0
    def test_user_get(self):
        """Test authenticated user can access user info"""
        request = self.factory.get('/', **self.extra)

        # users list
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)
    def test_user_get(self):
        """Test authenticated user can access user info"""
        request = self.factory.get('/', **self.extra)

        # users list
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)
    def test_get_non_org_users(self):
        self._org_create()

        view = UserViewSet.as_view(
            {'get': 'list'}
        )

        all_users_request = self.factory.get('/')
        all_users_response = view(all_users_request)

        self.assertEquals(all_users_response.status_code, 200)
        self.assertEquals(
            len(filter(
                lambda user: user['username'] == 'denoinc',
                all_users_response.data)),
            1)

        no_orgs_request = self.factory.get('/', data={'orgs': 'false'})
        no_orgs_response = view(no_orgs_request)

        self.assertEquals(no_orgs_response.status_code, 200)
        self.assertEquals(
            len(filter(
                lambda user: user['username'] == 'denoinc',
                no_orgs_response.data)),
            0)
示例#6
0
    def test_user_get(self):
        """Test authenticated user can access user info"""
        request = self.factory.get('/', **self.extra)

        # users list
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)

        # user with username BoB, mixed case
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertNotEqual(response.get('Cache-Control'), None)
        self.assertEqual(response.data, self.data)

        # Test can retrieve profile for usernames with _ . @ symbols
        alice_data = {
            'username': '******',
            'email': '*****@*****.**'
        }
        alice_profile = self._create_user_profile(alice_data)
        extra = {
            'HTTP_AUTHORIZATION': f'Token {alice_profile.user.auth_token}'
        }

        request = self.factory.get('/', **extra)
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['username'], alice_data['username'])

        # user bob is_active = False
        self.user.is_active = False
        self.user.save()

        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 404)
示例#7
0
    def test_user_anon(self):
        """Test anonymous user can access user info"""
        request = self.factory.get('/')

        # users list endpoint
        view = UserViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [self.data])

        # user with username bob
        view = UserViewSet.as_view({'get': 'retrieve'})
        response = view(request, username='******')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)

        # Test with primary key
        response = view(request, username=self.user.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, self.data)
示例#8
0
    def test_get_user_using_email(self):
        alice_data = {
            'username': '******',
            'email': '*****@*****.**',
            'first_name': u'Alice',
            'last_name': u'Kamande'
        }
        alice_profile = self._create_user_profile(alice_data)
        data = [{
            'id': alice_profile.user.pk,
            'username': u'alice',
            'first_name': u'Alice',
            'last_name': u'Kamande'
        }]
        get_params = {
            'search': alice_profile.user.email,
        }
        view = UserViewSet.as_view({'get': 'list'})
        request = self.factory.get('/', data=get_params)

        response = view(request)
        self.assertEquals(response.status_code, 401)
        error = {'detail': 'Authentication credentials were not provided.'}
        self.assertEqual(response.data, error)

        # authenticated
        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEqual(response.data, data)

        get_params = {
            'search': '*****@*****.**',
        }

        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        # empty results
        self.assertEqual(response.data, [])

        get_params = {
            'search': '*****@*****.**',
        }

        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        # empty results
        self.assertEqual(response.data, [])
示例#9
0
    def test_get_user_using_email(self):
        alice_data = {'username': '******', 'email': '*****@*****.**',
                      'name': u'Alice'}
        alice_profile = self._create_user_profile(alice_data)
        data = [{'id': alice_profile.user.pk, 'username': u'alice',
                'first_name': u'Alice', 'last_name': u''}]
        get_params = {
            'search': alice_profile.user.email,
        }
        view = UserViewSet.as_view(
            {'get': 'list'}
        )
        request = self.factory.get('/', data=get_params)

        response = view(request)
        self.assertEquals(response.status_code, 401)
        error = {'detail': 'Authentication credentials were not provided.'}
        self.assertEqual(response.data, error)

        # authenticated
        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEqual(response.data, data)

        get_params = {
            'search': '*****@*****.**',
        }

        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        # empty results
        self.assertEqual(response.data, [])

        get_params = {
            'search': '*****@*****.**',
        }

        request = self.factory.get('/', data=get_params, **self.extra)
        response = view(request)

        self.assertEquals(response.status_code, 200)
        # empty results
        self.assertEqual(response.data, [])
    def test_get_non_org_users(self):
        self._org_create()

        view = UserViewSet.as_view({'get': 'list'})

        all_users_request = self.factory.get('/')
        all_users_response = view(all_users_request)

        self.assertEquals(all_users_response.status_code, 200)
        self.assertEquals(
            len(
                filter(lambda user: user['username'] == 'denoinc',
                       all_users_response.data)), 1)

        no_orgs_request = self.factory.get('/', data={'orgs': 'false'})
        no_orgs_response = view(no_orgs_request)

        self.assertEquals(no_orgs_response.status_code, 200)
        self.assertEquals(
            len(
                filter(lambda user: user['username'] == 'denoinc',
                       no_orgs_response.data)), 0)
示例#11
0
 def test_user_get(self):
     view = UserViewSet.as_view({'get': 'retrieve'})
     request = self.factory.get('/', **self.extra)
     response = view(request, username='******')
     data = {'username': u'bob', 'first_name': u'Bob', 'last_name': u''}
     self.assertContains(response, json.dumps(data))
示例#12
0
 def test_user_list(self):
     view = UserViewSet.as_view({'get': 'list'})
     request = self.factory.get('/', **self.extra)
     response = view(request)
     data = [{'username': u'bob', 'first_name': u'Bob', 'last_name': u''}]
     self.assertContains(response, json.dumps(data))