コード例 #1
0
    def test_get_users(self, api_client):
        api_client.force_authenticate(UserFactory.create_admin())

        UserFactory.create_batch(5)
        response = api_client.get(reverse('v1-users:user-list'))

        assert response.status_code == status.HTTP_200_OK
        assert len(response.data['results']) == User.objects.count()
コード例 #2
0
    def test_get_user_details_not_found(self, api_client):
        api_client.force_authenticate(UserFactory.create_admin())

        response = api_client.get(reverse('v1-users:user-detail',
                                          args=(100, )))

        assert response.status_code == status.HTTP_404_NOT_FOUND
コード例 #3
0
    def test_get_user_details_when_not_logged_it(self, api_client):
        user = UserFactory()

        response = api_client.get(
            reverse('v1-users:user-detail', args=(user.id, )))

        assert response.status_code == status.HTTP_401_UNAUTHORIZED
コード例 #4
0
def api_client_with_token():
    """A Django REST Framework test client instance with headers required by v1 API and already obtained token."""
    skip_if_no_django()
    user = UserFactory()
    api_client = APIClient()
    api_client.force_authenticate(user)
    api_client.user = user

    return api_client
コード例 #5
0
    def test_get_user_details(self, api_client):
        user = UserFactory()
        api_client.force_authenticate(user)

        response = api_client.get(
            reverse('v1-users:user-detail', args=(user.id, )))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['first_name'] == user.first_name
コード例 #6
0
    def test_user_details_me_endpoint(self, api_client):
        user = UserFactory(first_name="John", last_name="Doe")
        api_client.force_authenticate(user)

        response = api_client.get(reverse('v1-users:user-me'))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['email'] == user.email
        assert response.data['first_name'] == user.first_name
        assert response.data['last_name'] == user.last_name
        assert response.data['city'] == user.city
        assert response.data['parish'] == user.parish
        assert response.data['community'] == user.community
コード例 #7
0
    def test_get_users_for_not_admin_user(self, api_client_with_token):
        UserFactory.create_batch(3)
        response = api_client_with_token.get(reverse('v1-users:user-list'))

        assert response.status_code == status.HTTP_403_FORBIDDEN
コード例 #8
0
    def create_user(self):
        user = UserFactory(email=self.sample_email)
        user.set_password(self.sample_password)
        user.save()

        return user
コード例 #9
0
    def test_unique_email(self):
        email = '*****@*****.**'

        with pytest.raises(IntegrityError):
            UserFactory.create_batch(2, email=email)