-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5a6871
commit 6f8928c
Showing
8 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pytest_factoryboy import register | ||
|
||
from api.tests.factories import UserFactory | ||
from api.tests.fixtures import * # noqa: F403 | ||
|
||
register(UserFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib.auth import get_user_model | ||
from factory.django import DjangoModelFactory | ||
|
||
|
||
class UserFactory(DjangoModelFactory): | ||
username = "[email protected]" | ||
email = "[email protected]" | ||
|
||
class Meta: | ||
model = get_user_model() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
|
||
@pytest.fixture | ||
def regular_user(user_factory): | ||
return user_factory.create(is_active=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_users_me_unauthorized(client): | ||
response = client.get(reverse("api-users-me")) | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_users_me_authorized(api_client, regular_user): | ||
api_client.force_authenticate(user=regular_user) | ||
response = api_client.get(reverse("api-users-me")) | ||
assert response.status_code == status.HTTP_200_OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.