|
1 | 1 | from http import HTTPStatus
|
2 | 2 |
|
3 | 3 | import pytest
|
4 |
| -from django.contrib.auth.models import User |
5 | 4 | from django.test import Client
|
6 |
| -from plugins.identity.user import ProfileAssertion, ProfileDataFactory |
| 5 | +from plugins.identity.user import ( |
| 6 | + ProfileAssertion, |
| 7 | + ProfileDataFactory, |
| 8 | + logged_user_client |
| 9 | +) |
7 | 10 |
|
8 | 11 |
|
9 | 12 | @pytest.mark.django_db()()
|
@@ -45,57 +48,49 @@ def test_admin_docs_authorized(admin_client: Client) -> None:
|
45 | 48 | assert b'docutils' not in response.content
|
46 | 49 |
|
47 | 50 |
|
48 |
| -def test_picture_pages_unauthorized(client: Client) -> None: |
| 51 | +@pytest.mark.parametrize("url_found", [ |
| 52 | + '/pictures/dashboard', |
| 53 | + '/pictures/favourites' |
| 54 | +]) |
| 55 | +def test_picture_pages_unauthorized(client: Client, url_found: str) -> None: |
49 | 56 | """This test ensures that picture management pages require auth."""
|
50 |
| - response = client.get('/pictures/dashboard') |
51 |
| - assert response.status_code == HTTPStatus.FOUND |
52 |
| - |
53 |
| - response = client.get('/pictures/favourites') |
| 57 | + response = client.get(url_found) |
54 | 58 | assert response.status_code == HTTPStatus.FOUND
|
55 | 59 |
|
56 | 60 |
|
57 | 61 | @pytest.mark.django_db()
|
| 62 | +@pytest.mark.parametrize("url_accessible", [ |
| 63 | + '/pictures/dashboard', |
| 64 | + '/pictures/favourites' |
| 65 | +]) |
58 | 66 | def test_picture_pages_authorized(
|
59 |
| - client: Client, |
60 |
| - django_user_model: User, |
| 67 | + logged_user_client: Client, |
| 68 | + url_accessible: str |
61 | 69 | ) -> None:
|
62 | 70 | """Ensures picture management pages are accessible for authorized user."""
|
63 |
| - password, email = 'password', '[email protected]' |
64 |
| - user = django_user_model.objects.create_user( |
65 |
| - email, |
66 |
| - password, |
67 |
| - ) |
68 |
| - client.force_login(user) |
69 |
| - |
70 |
| - response = client.get('/pictures/dashboard') |
71 |
| - assert response.status_code == HTTPStatus.OK |
72 | 71 |
|
73 |
| - response = client.get('/pictures/favourites') |
| 72 | + response = logged_user_client.get(url_accessible) |
74 | 73 | assert response.status_code == HTTPStatus.OK
|
75 | 74 |
|
76 | 75 |
|
77 | 76 | @pytest.mark.django_db()
|
78 | 77 | def test_profile_update_authorized(
|
79 |
| - client: Client, |
80 |
| - django_user_model: User, |
| 78 | + logged_user_client: Client, |
81 | 79 | profile_data_factory: 'ProfileDataFactory',
|
82 | 80 | assert_correct_profile: 'ProfileAssertion',
|
83 | 81 | assert_incorrect_profile: 'ProfileAssertion',
|
84 | 82 | ) -> None:
|
85 | 83 | """This test ensures profile updating for an authorized user."""
|
86 | 84 | user_data = profile_data_factory()
|
87 | 85 |
|
88 |
| - password, email = 'password', '[email protected]' |
89 |
| - user = django_user_model.objects.create_user( |
90 |
| - email, |
91 |
| - password, |
92 |
| - ) |
93 |
| - client.force_login(user) |
| 86 | + # that is an email for `logged_user_client` fixture |
| 87 | + # maybe add indirect parametrization? |
| 88 | + |
94 | 89 |
|
95 | 90 | # there might be a probability of accidental match, but disregard it for now
|
96 | 91 | assert_incorrect_profile(email, user_data)
|
97 | 92 |
|
98 |
| - response = client.post( |
| 93 | + response = logged_user_client.post( |
99 | 94 | '/identity/update',
|
100 | 95 | data=user_data,
|
101 | 96 | )
|
|
0 commit comments