This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
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
a010229
commit 1ec0e1f
Showing
3 changed files
with
39 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
from django.test import Client | ||
from django.contrib.auth.models import User | ||
from mimesis.locales import Locale | ||
from mimesis.schema import Field, Schema | ||
|
||
|
@@ -85,3 +87,15 @@ def factory(email: str, expected: ProfileData) -> None: | |
assert not all(matches) | ||
|
||
return factory | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def logged_user_client(client: Client, django_user_model: User): | ||
"""Client for a logged in user.""" | ||
password, email = 'password', '[email protected]' | ||
user = django_user_model.objects.create_user( | ||
email, | ||
password, | ||
) | ||
client.force_login(user) | ||
return client |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
from django.contrib.auth.models import User | ||
from django.test import Client | ||
from plugins.identity.user import ProfileAssertion, ProfileDataFactory | ||
from plugins.identity.user import ( | ||
ProfileAssertion, | ||
ProfileDataFactory, | ||
logged_user_client | ||
) | ||
|
||
|
||
@pytest.mark.django_db()() | ||
|
@@ -45,57 +48,49 @@ def test_admin_docs_authorized(admin_client: Client) -> None: | |
assert b'docutils' not in response.content | ||
|
||
|
||
def test_picture_pages_unauthorized(client: Client) -> None: | ||
@pytest.mark.parametrize("url_found", [ | ||
'/pictures/dashboard', | ||
'/pictures/favourites' | ||
]) | ||
def test_picture_pages_unauthorized(client: Client, url_found: str) -> None: | ||
"""This test ensures that picture management pages require auth.""" | ||
response = client.get('/pictures/dashboard') | ||
assert response.status_code == HTTPStatus.FOUND | ||
|
||
response = client.get('/pictures/favourites') | ||
response = client.get(url_found) | ||
assert response.status_code == HTTPStatus.FOUND | ||
|
||
|
||
@pytest.mark.django_db() | ||
@pytest.mark.parametrize("url_accessible", [ | ||
'/pictures/dashboard', | ||
'/pictures/favourites' | ||
]) | ||
def test_picture_pages_authorized( | ||
client: Client, | ||
django_user_model: User, | ||
logged_user_client: Client, | ||
url_accessible: str | ||
) -> None: | ||
"""Ensures picture management pages are accessible for authorized user.""" | ||
password, email = 'password', '[email protected]' | ||
user = django_user_model.objects.create_user( | ||
email, | ||
password, | ||
) | ||
client.force_login(user) | ||
|
||
response = client.get('/pictures/dashboard') | ||
assert response.status_code == HTTPStatus.OK | ||
|
||
response = client.get('/pictures/favourites') | ||
response = logged_user_client.get(url_accessible) | ||
assert response.status_code == HTTPStatus.OK | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_profile_update_authorized( | ||
client: Client, | ||
django_user_model: User, | ||
logged_user_client: Client, | ||
profile_data_factory: 'ProfileDataFactory', | ||
assert_correct_profile: 'ProfileAssertion', | ||
assert_incorrect_profile: 'ProfileAssertion', | ||
) -> None: | ||
"""This test ensures profile updating for an authorized user.""" | ||
user_data = profile_data_factory() | ||
|
||
password, email = 'password', '[email protected]' | ||
user = django_user_model.objects.create_user( | ||
email, | ||
password, | ||
) | ||
client.force_login(user) | ||
# that is an email for `logged_user_client` fixture | ||
# maybe add indirect parametrization? | ||
email = '[email protected]' | ||
|
||
# there might be a probability of accidental match, but disregard it for now | ||
assert_incorrect_profile(email, user_data) | ||
|
||
response = client.post( | ||
response = logged_user_client.post( | ||
'/identity/update', | ||
data=user_data, | ||
) | ||
|