From 3118faafd8e5b232ac583bb091b340908f026e36 Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 19:51:58 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20conftest.py=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D1=8F=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 96baa556..e056f886 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,6 @@ pytest_plugins = [ # Should be the first custom one: 'plugins.django_settings', - + 'plugins.identity.user' # TODO: add your own plugins here! ] From 5a133ef252701af53b23eaab8b0048978753877d Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 19:52:19 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20identity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugins/identity/user.py | 102 ++++++++++++++++++ .../test_identity/test_identity_models.py | 18 ++++ .../test_identity/test_indentity_user_url.py | 60 +++++++++++ 3 files changed, 180 insertions(+) create mode 100644 tests/plugins/identity/user.py create mode 100644 tests/test_apps/test_identity/test_identity_models.py create mode 100644 tests/test_apps/test_identity/test_indentity_user_url.py diff --git a/tests/plugins/identity/user.py b/tests/plugins/identity/user.py new file mode 100644 index 00000000..9ac7c5c0 --- /dev/null +++ b/tests/plugins/identity/user.py @@ -0,0 +1,102 @@ +import pytest +import datetime as dt +from typing import Protocol, Unpack, final, TypedDict + +from server.apps.identity.models import User, _UserManager + + +class UserData(TypedDict, total=False): + email: str + first_name: str + last_name: str + date_of_birth: dt.datetime + address: str + job_title: str + phone: str + password: str + + +@final +class RegistrationData(UserData): + password1: str + password2: str + + +@pytest.fixture +def user_factory(): + def factory(UserData) -> User: + return User.objects.create(**UserData) + return factory + + +@pytest.fixture +def user_model_data() -> UserData: + ''' + можно использовать генерацию данных + но у меня было не так много времени + поэтому делаю как могу T_T + проблема была в poetry + ''' + return UserData( + email='amongusguy@email.com', + first_name='imposter', + last_name='crewmate', + date_of_birth=dt.date.today(), + address='address', + job_title='docker-guy', + phone='+79991231234', + password='123456789' + ) + + +@pytest.fixture +def registration_data() -> RegistrationData: + return RegistrationData( + email='amon@email.com', + first_name='imposter', + last_name='crewmate', + date_of_birth=dt.date.today(), + address='address', + job_title='docker-guy', + phone='+79991231234', + password1='1241', + password2='1241' + ) + + +@pytest.fixture +def create_user(user_factory, user_model_data) -> User: + return user_factory(user_model_data) + + +@pytest.fixture +def create_superuser() -> User: + manager = _UserManager() + return manager.create_superuser( + email='password@mail.com', + password='password' + ) + + +@pytest.fixture(scope='session') +def assert_user(): + def factory( + email: str, + superuser: bool = False, + expected: UserData | None = None) -> None: + user = User.objects.get(email=email) + # Special fields: + assert user.id + assert user.is_active + match superuser: + case True: + assert user.is_superuser + assert user.is_staff + case False: + assert not user.is_superuser + assert not user.is_staff + # All other fields: + if expected: + for field_name, data_value in expected.items(): + assert getattr(user, field_name) == data_value + return factory diff --git a/tests/test_apps/test_identity/test_identity_models.py b/tests/test_apps/test_identity/test_identity_models.py new file mode 100644 index 00000000..f00a5349 --- /dev/null +++ b/tests/test_apps/test_identity/test_identity_models.py @@ -0,0 +1,18 @@ +import pytest + + +@pytest.mark.django_db +def test_user_model( + create_user, + assert_user, + user_model_data) -> None: + user = create_user + assert_user(email=user.email, expected=user_model_data) + + +@pytest.mark.django_db +def test_super_user( + create_superuser, + assert_user) -> None: + user = create_superuser + assert_user(email=user.email, superuser=True) diff --git a/tests/test_apps/test_identity/test_indentity_user_url.py b/tests/test_apps/test_identity/test_indentity_user_url.py new file mode 100644 index 00000000..c44821d2 --- /dev/null +++ b/tests/test_apps/test_identity/test_indentity_user_url.py @@ -0,0 +1,60 @@ +from server.apps.identity.models import User +from http import HTTPStatus + +import pytest +from django.test import Client +from django.urls import reverse + + +@pytest.mark.django_db +def test_registration_view( + client: Client, + user_model_data, + registration_data, + assert_user +) -> None: + response = client.post( + '/identity/registration', + data=registration_data + ) + assert response.status_code == HTTPStatus.FOUND + assert response.get('Location') == reverse('identity:login') + assert_user(registration_data['email'], user_model_data) + + +@pytest.mark.django_db +def test_login( + client: Client, + user_model_data, + assert_user, + create_user +) -> None: + user = create_user + data = { + 'username': user.email, + 'password': user.password + } + response = client.post( + '/identity/login', + data=data + ) + assert response.status_code == HTTPStatus.OK + assert_user(data['username'], user_model_data) + + +@pytest.mark.django_db +def test_user_update( + client: Client, + create_user, + user_model_data, + assert_user +): + user = create_user + user_model_data['email'] = 'mail@mail.com' + data = user_model_data + response = client.put( + '/identity/update', + data=data + ) + assert response.status_code == HTTPStatus.FOUND + assert_user(user.email, user_model_data) From b6732791ceb39de2224070cce1e71afdbe25b469 Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 21:02:14 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20pictures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugins/pictures/pictures.py | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/plugins/pictures/pictures.py diff --git a/tests/plugins/pictures/pictures.py b/tests/plugins/pictures/pictures.py new file mode 100644 index 00000000..3947e6ec --- /dev/null +++ b/tests/plugins/pictures/pictures.py @@ -0,0 +1,35 @@ +from typing import TypedDict +import pytest + +from server.apps.identity.models import User +from server.apps.pictures.models import FavouritePicture + + +class FavouritePictureData(TypedDict): + user: User + foreign_id: int + url: str + + +@pytest.fixture +def picture_factory(): + def factory( + favourite_picture: FavouritePictureData) -> FavouritePicture: + return FavouritePicture.objects.create( + **favourite_picture + ) + return factory + + +def assert_favourite_picture(): + def assert_model( + favourite_picture_id: int, + expected: FavouritePictureData + ): + favourite_picture = FavouritePicture.objects.filter( + id=favourite_picture_id) + assert favourite_picture.id + if expected: + for field_name, data_value in expected.items(): + assert getattr(favourite_picture, field_name) == data_value + return assert_model From 4f6df2d34f5b0f1b817388806dd188b9bf0a0dc6 Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 21:24:59 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20Favourite?= =?UTF-8?q?Picture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 3 ++- tests/plugins/pictures/pictures.py | 26 +++++++++++++------ .../test_pictures/test_picture_models.py | 14 ++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/test_apps/test_pictures/test_picture_models.py diff --git a/tests/conftest.py b/tests/conftest.py index e056f886..f534a447 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ pytest_plugins = [ # Should be the first custom one: 'plugins.django_settings', - 'plugins.identity.user' + 'plugins.identity.user', + 'plugins.pictures.pictures' # TODO: add your own plugins here! ] diff --git a/tests/plugins/pictures/pictures.py b/tests/plugins/pictures/pictures.py index 3947e6ec..36e49d99 100644 --- a/tests/plugins/pictures/pictures.py +++ b/tests/plugins/pictures/pictures.py @@ -11,6 +11,16 @@ class FavouritePictureData(TypedDict): url: str +@pytest.fixture +def favourite_picture_data(create_user): + # ! рекомендую перейти по ссылке :) + return FavouritePictureData( + user=create_user, + foreign_id=1, + url='https://www.youtube.com/watch?v=dQw4w9WgXcQ' + ) + + @pytest.fixture def picture_factory(): def factory( @@ -21,15 +31,15 @@ def factory( return factory +@pytest.fixture def assert_favourite_picture(): - def assert_model( - favourite_picture_id: int, + def factory( + favourite_picture: FavouritePicture, expected: FavouritePictureData ): - favourite_picture = FavouritePicture.objects.filter( - id=favourite_picture_id) + # favourite_picture = FavouritePicture.objects.filter( + # id=favourite_picture_id) assert favourite_picture.id - if expected: - for field_name, data_value in expected.items(): - assert getattr(favourite_picture, field_name) == data_value - return assert_model + for field_name, data_value in expected.items(): + assert getattr(favourite_picture, field_name) == data_value + return factory diff --git a/tests/test_apps/test_pictures/test_picture_models.py b/tests/test_apps/test_pictures/test_picture_models.py new file mode 100644 index 00000000..60146810 --- /dev/null +++ b/tests/test_apps/test_pictures/test_picture_models.py @@ -0,0 +1,14 @@ +import pytest + + +@pytest.mark.django_db +def test_favourite_picture( + picture_factory, + favourite_picture_data, + assert_favourite_picture +) -> None: + favourite_picture = picture_factory(favourite_picture_data) + assert_favourite_picture( + favourite_picture=favourite_picture, + expected=favourite_picture_data) + From 061138ab3864b0befdc856692ba7751c7ed0b848 Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 21:51:36 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B5=20url=20=D0=B2?= =?UTF-8?q?=20pictures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test_identity/test_indentity_user_url.py | 1 - tests/test_apps/test_pictures/conftest.py | 14 +++++++++ .../test_pictures/test_pictures_logic.py | 23 +++++++++++++++ ...ture_models.py => test_pictures_models.py} | 3 +- .../test_pictures/test_pictures_url.py | 29 +++++++++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/test_apps/test_pictures/conftest.py create mode 100644 tests/test_apps/test_pictures/test_pictures_logic.py rename tests/test_apps/test_pictures/{test_picture_models.py => test_pictures_models.py} (86%) create mode 100644 tests/test_apps/test_pictures/test_pictures_url.py diff --git a/tests/test_apps/test_identity/test_indentity_user_url.py b/tests/test_apps/test_identity/test_indentity_user_url.py index c44821d2..d479e543 100644 --- a/tests/test_apps/test_identity/test_indentity_user_url.py +++ b/tests/test_apps/test_identity/test_indentity_user_url.py @@ -1,4 +1,3 @@ -from server.apps.identity.models import User from http import HTTPStatus import pytest diff --git a/tests/test_apps/test_pictures/conftest.py b/tests/test_apps/test_pictures/conftest.py new file mode 100644 index 00000000..8ca2426c --- /dev/null +++ b/tests/test_apps/test_pictures/conftest.py @@ -0,0 +1,14 @@ +import pytest + + +@pytest.fixture +def create_two_favourite_picture( + picture_factory, + favourite_picture_data +) -> int: + # Странно получать из create_two_favourite_picture user_id + favourite_picture = picture_factory(favourite_picture_data) + second_picture_data = favourite_picture_data + second_picture_data['foreign_id'] = 2 + picture_factory(second_picture_data) + return favourite_picture.user_id diff --git a/tests/test_apps/test_pictures/test_pictures_logic.py b/tests/test_apps/test_pictures/test_pictures_logic.py new file mode 100644 index 00000000..9b5e9a4c --- /dev/null +++ b/tests/test_apps/test_pictures/test_pictures_logic.py @@ -0,0 +1,23 @@ +import pytest + +from server.apps.pictures.logic.repo.queries import favourite_pictures +from server.apps.pictures.logic.usecases.favourites_list import FavouritesList + + +@pytest.mark.django_db +def test_by_user( + create_two_favourite_picture +) -> None: + # Недостаточная проверка + queryset = favourite_pictures.by_user( + user_id=create_two_favourite_picture) + assert len(queryset) == 2 + + +@pytest.mark.django_db +def test_favourites_list( + create_two_favourite_picture +) -> None: + # Недостаточная проверка + favorites_list = FavouritesList() + assert len(favorites_list(create_two_favourite_picture)) == 2 diff --git a/tests/test_apps/test_pictures/test_picture_models.py b/tests/test_apps/test_pictures/test_pictures_models.py similarity index 86% rename from tests/test_apps/test_pictures/test_picture_models.py rename to tests/test_apps/test_pictures/test_pictures_models.py index 60146810..44ed23b4 100644 --- a/tests/test_apps/test_pictures/test_picture_models.py +++ b/tests/test_apps/test_pictures/test_pictures_models.py @@ -10,5 +10,6 @@ def test_favourite_picture( favourite_picture = picture_factory(favourite_picture_data) assert_favourite_picture( favourite_picture=favourite_picture, - expected=favourite_picture_data) + expected=favourite_picture_data + ) diff --git a/tests/test_apps/test_pictures/test_pictures_url.py b/tests/test_apps/test_pictures/test_pictures_url.py new file mode 100644 index 00000000..6b6abca9 --- /dev/null +++ b/tests/test_apps/test_pictures/test_pictures_url.py @@ -0,0 +1,29 @@ +from http import HTTPStatus + +import pytest +from django.test import Client +from django.urls import reverse + + +@pytest.mark.django_db +def test_dashboard_view( + client: Client, + create_two_favourite_picture +) -> None: + create_two_favourite_picture + response = client.get( + '/pictures/dashboard' + ) + assert response.status_code == HTTPStatus.FOUND + + +@pytest.mark.django_db +def test_favourite_picture( + client: Client, + create_two_favourite_picture +) -> None: + create_two_favourite_picture + response = client.get( + '/pictures/favourites' + ) + assert response.status_code == HTTPStatus.FOUND From 1d897925968b847e29828869fe4fd5e83169c916 Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 16 Sep 2023 21:56:40 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D1=82=D1=81=D1=82=D1=83=D0=BF=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/plugins/identity/user.py | 3 ++- tests/plugins/pictures/pictures.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/plugins/identity/user.py b/tests/plugins/identity/user.py index 9ac7c5c0..d7be9c00 100644 --- a/tests/plugins/identity/user.py +++ b/tests/plugins/identity/user.py @@ -83,7 +83,8 @@ def assert_user(): def factory( email: str, superuser: bool = False, - expected: UserData | None = None) -> None: + expected: UserData | None = None + ) -> None: user = User.objects.get(email=email) # Special fields: assert user.id diff --git a/tests/plugins/pictures/pictures.py b/tests/plugins/pictures/pictures.py index 36e49d99..ffbbe02d 100644 --- a/tests/plugins/pictures/pictures.py +++ b/tests/plugins/pictures/pictures.py @@ -12,7 +12,7 @@ class FavouritePictureData(TypedDict): @pytest.fixture -def favourite_picture_data(create_user): +def favourite_picture_data(create_user) -> FavouritePictureData: # ! рекомендую перейти по ссылке :) return FavouritePictureData( user=create_user, @@ -24,7 +24,8 @@ def favourite_picture_data(create_user): @pytest.fixture def picture_factory(): def factory( - favourite_picture: FavouritePictureData) -> FavouritePicture: + favourite_picture: FavouritePictureData + ) -> FavouritePicture: return FavouritePicture.objects.create( **favourite_picture ) From 68b540f6d18a9dc20498d6e9edb8f27a134dfa9f Mon Sep 17 00:00:00 2001 From: Andrey K Date: Sat, 23 Sep 2023 21:56:40 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BD=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85=20=D0=98=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?mixer=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=D1=82=D1=83=D1=80=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20seed=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D0=BE=D0=BC=D0=B0=20=D0=B2=20pytest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/db.json | 19 +++ docker-compose.yml | 13 ++ poetry.lock | 152 +++++++++++++++++- pyproject.toml | 2 + setup.cfg | 3 + tests/conftest.py | 21 +++ tests/plugins/django_settings.py | 1 + tests/plugins/identity/user.py | 2 +- tests/plugins/pictures/pictures.py | 10 +- .../test_identity/test_indentity_user_url.py | 3 + tests/test_apps/test_pictures/conftest.py | 21 ++- .../test_pictures/test_pictures_logic.py | 28 +++- .../test_pictures/test_pictures_models.py | 5 +- .../test_pictures/test_pictures_url.py | 8 +- tests/test_server/test_urls.py | 1 + 15 files changed, 254 insertions(+), 35 deletions(-) create mode 100644 data/db.json diff --git a/data/db.json b/data/db.json new file mode 100644 index 00000000..f2ae48df --- /dev/null +++ b/data/db.json @@ -0,0 +1,19 @@ +{ + "posts": [ + { + "id": 1, + "title": "json-server", + "author": "typicode" + } + ], + "comments": [ + { + "id": 1, + "body": "some comment", + "postId": 1 + } + ], + "profile": { + "name": "typicode" + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0a60a951..ec73e825 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -59,6 +59,19 @@ services: retries: 5 start_period: 30s + json-server: + image: "vimagick/json-server" + command: -H 0.0.0.0 -p 5200 --watch db.json + container_name: "json_server" + ports: + - "5200:5200" + volumes: + - ./data:/data + restart: always + networks: + - webnet + + # This task is an example of how to extend existing ones: # some_worker: # <<: *web diff --git a/poetry.lock b/poetry.lock index ebbbafa3..75895ad5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1034,6 +1034,20 @@ files = [ [package.extras] tests = ["asttokens", "littleutils", "pytest", "rich"] +[[package]] +name = "faker" +version = "12.0.1" +description = "Faker is a Python package that generates fake data for you." +optional = false +python-versions = ">=3.6" +files = [ + {file = "Faker-12.0.1-py3-none-any.whl", hash = "sha256:1dc2811f20e163892fefe7006f2ce00778f8099a40aee265bfa60a13400de63d"}, + {file = "Faker-12.0.1.tar.gz", hash = "sha256:aa7103805ae793277abbb85da9f6f05e76a1a295a9384a8e17c2fba2b3a690cb"}, +] + +[package.dependencies] +python-dateutil = ">=2.4" + [[package]] name = "flake8" version = "6.1.0" @@ -1274,6 +1288,42 @@ files = [ [package.dependencies] flake8 = "*" +[[package]] +name = "flask" +version = "2.3.3" +description = "A simple framework for building complex web applications." +optional = false +python-versions = ">=3.8" +files = [ + {file = "flask-2.3.3-py3-none-any.whl", hash = "sha256:f69fcd559dc907ed196ab9df0e48471709175e696d6e698dd4dbe940f96ce66b"}, + {file = "flask-2.3.3.tar.gz", hash = "sha256:09c347a92aa7ff4a8e7f3206795f30d826654baf38b873d0744cd571ca609efc"}, +] + +[package.dependencies] +blinker = ">=1.6.2" +click = ">=8.1.3" +itsdangerous = ">=2.1.2" +Jinja2 = ">=3.1.2" +Werkzeug = ">=2.3.7" + +[package.extras] +async = ["asgiref (>=3.2)"] +dotenv = ["python-dotenv"] + +[[package]] +name = "flask-cors" +version = "4.0.0" +description = "A Flask extension adding a decorator for CORS support" +optional = false +python-versions = "*" +files = [ + {file = "Flask-Cors-4.0.0.tar.gz", hash = "sha256:f268522fcb2f73e2ecdde1ef45e2fd5c71cc48fe03cffb4b441c6d1b40684eb0"}, + {file = "Flask_Cors-4.0.0-py2.py3-none-any.whl", hash = "sha256:bc3492bfd6368d27cfe79c7821df5a8a319e1a6d5eab277a3794be19bdc51783"}, +] + +[package.dependencies] +Flask = ">=0.9" + [[package]] name = "flatten-dict" version = "0.4.2" @@ -1599,6 +1649,17 @@ pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib" plugins = ["setuptools"] requirements-deprecated-finder = ["pip-api", "pipreqs"] +[[package]] +name = "itsdangerous" +version = "2.1.2" +description = "Safely pass data to untrusted environments and back." +optional = false +python-versions = ">=3.7" +files = [ + {file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"}, + {file = "itsdangerous-2.1.2.tar.gz", hash = "sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a"}, +] + [[package]] name = "jedi" version = "0.19.0" @@ -1660,6 +1721,22 @@ files = [ editorconfig = ">=0.12.2" six = ">=1.13.0" +[[package]] +name = "json-server" +version = "0.1.3" +description = "" +optional = false +python-versions = "*" +files = [ + {file = "json_server-0.1.3-py3-none-any.whl", hash = "sha256:5cde2ee14ae3f9feea62823522dadcbfe03846e6fa3c7500237c0d06bc995d8e"}, + {file = "json_server-0.1.3.tar.gz", hash = "sha256:c512a0d8e7244f13d5deda2c6b054116b68384c0ff3a60b09defa8543b512f8e"}, +] + +[package.dependencies] +click = "*" +flask = "*" +flask-cors = "*" + [[package]] name = "json5" version = "0.9.14" @@ -1743,6 +1820,16 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -1844,6 +1931,23 @@ files = [ {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, ] +[[package]] +name = "mixer" +version = "7.2.2" +description = "Mixer -- Is a fixtures replacement. Supported Django ORM, SqlAlchemy ORM, Mongoengine ODM and custom python objects." +optional = false +python-versions = ">=3.7" +files = [ + {file = "mixer-7.2.2-py3-none-any.whl", hash = "sha256:8089b8e2d00288c77e622936198f5dd03c8ac1603a1530a4f870dc213363b2ae"}, + {file = "mixer-7.2.2.tar.gz", hash = "sha256:9b3f1a261b56d8f2394f39955f83adbc7ff3ab4bb1065ebfec19a10d3e8501e0"}, +] + +[package.dependencies] +Faker = ">=5.4.0,<12.1" + +[package.extras] +tests = ["Django (>=3.0)", "Flask (>=1.0)", "Marshmallow (>=3.9)", "SQLAlchemy (>=1.1.4)", "flask-sqlalchemy (>=2.1)", "mongoengine (>=0.10.1)", "peewee (>=3.7.0)", "pony (>=0.7)", "psycopg2-binary (>=2.8.4)", "pytest"] + [[package]] name = "more-itertools" version = "10.1.0" @@ -2543,6 +2647,20 @@ files = [ [package.dependencies] pytest = ">=5.0.0" +[[package]] +name = "python-dateutil" +version = "2.8.2" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, + {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "python-decouple" version = "3.8" @@ -2583,6 +2701,7 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -2590,8 +2709,15 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -2608,6 +2734,7 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -2615,6 +2742,7 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -2831,7 +2959,8 @@ files = [ {file = "ruamel.yaml.clib-0.2.7-cp310-cp310-win32.whl", hash = "sha256:763d65baa3b952479c4e972669f679fe490eee058d5aa85da483ebae2009d231"}, {file = "ruamel.yaml.clib-0.2.7-cp310-cp310-win_amd64.whl", hash = "sha256:d000f258cf42fec2b1bbf2863c61d7b8918d31ffee905da62dede869254d3b8a"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:045e0626baf1c52e5527bd5db361bc83180faaba2ff586e763d3d5982a876a9e"}, - {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_12_6_arm64.whl", hash = "sha256:721bc4ba4525f53f6a611ec0967bdcee61b31df5a56801281027a3a6d1c2daf5"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:1a6391a7cabb7641c32517539ca42cf84b87b667bad38b78d4d42dd23e957c81"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:9c7617df90c1365638916b98cdd9be833d31d337dbcd722485597b43c4a215bf"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:41d0f1fa4c6830176eef5b276af04c89320ea616655d01327d5ce65e50575c94"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-win32.whl", hash = "sha256:f6d3d39611ac2e4f62c3128a9eed45f19a6608670c5a2f4f07f24e8de3441d38"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-win_amd64.whl", hash = "sha256:da538167284de58a52109a9b89b8f6a53ff8437dd6dc26d33b57bf6699153122"}, @@ -3407,6 +3536,23 @@ pygments = ">=2.4,<3.0" setuptools = "*" typing_extensions = ">=4.0,<5.0" +[[package]] +name = "werkzeug" +version = "2.3.7" +description = "The comprehensive WSGI web application library." +optional = false +python-versions = ">=3.8" +files = [ + {file = "werkzeug-2.3.7-py3-none-any.whl", hash = "sha256:effc12dba7f3bd72e605ce49807bbe692bd729c3bb122a3b91747a6ae77df528"}, + {file = "werkzeug-2.3.7.tar.gz", hash = "sha256:2b8c0e447b4b9dbcc85dd97b6eeb4dcbaf6c8b6c3be0bd654e25553e0a2157d8"}, +] + +[package.dependencies] +MarkupSafe = ">=2.1.1" + +[package.extras] +watchdog = ["watchdog (>=2.3)"] + [[package]] name = "win32-setctime" version = "1.1.0" @@ -3441,5 +3587,5 @@ dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"] [metadata] lock-version = "2.0" -python-versions = "3.11.5" -content-hash = "b6f24d93edb443bee450e4b8200340134cc77eb2441c980e0ea264df4b23da94" +python-versions = "3.11.4" +content-hash = "46cabaaa204e879d48347b2836baa0c44a3e5a0defbb78d1b124a34e2b63b74d" diff --git a/pyproject.toml b/pyproject.toml index 19bbf6e4..8e6f2ff4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,6 +66,8 @@ dennis = "^1.1" dump-env = "^1.3" ipython = "^8.15" import-linter = "^1.11" +mixer = "^7.2.2" +json-server = "^0.1.3" [tool.poetry.group.docs] optional = true diff --git a/setup.cfg b/setup.cfg index 34c14369..ef52e1ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -100,6 +100,9 @@ filterwarnings = ignore::DeprecationWarning:password_reset.*: ignore::DeprecationWarning:pytest_freezegun: +markers = + slow + [coverage:run] # Coverage configuration: diff --git a/tests/conftest.py b/tests/conftest.py index f534a447..033c8130 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,10 @@ 2. https://docs.pytest.org/en/latest/doctest.html """ +import pytest +import random + + pytest_plugins = [ # Should be the first custom one: 'plugins.django_settings', @@ -13,3 +17,20 @@ 'plugins.pictures.pictures' # TODO: add your own plugins here! ] + + +def pytest_configure(config: pytest.Config) -> None: + seed_value = config.getoption("randomly_seed") + # рандомный seed: + default_seed = random.Random().getrandbits(32) + + if seed_value == 'last': + seed = config.cache.get('randomly_seed', default_seed) + elif seed_value == 'default': + seed = default_seed + else: + seed = seed_value + + if hasattr(config, 'cache'): + config.cache.set('randomly_seed', seed) + config.option.randomly_seed = seed diff --git a/tests/plugins/django_settings.py b/tests/plugins/django_settings.py index 3b916ed3..dd8dbb12 100644 --- a/tests/plugins/django_settings.py +++ b/tests/plugins/django_settings.py @@ -51,3 +51,4 @@ def cache(settings: LazySettings) -> BaseCache: # Clearing cache: caches[test_cache].clear() return caches[test_cache] + diff --git a/tests/plugins/identity/user.py b/tests/plugins/identity/user.py index d7be9c00..294dc866 100644 --- a/tests/plugins/identity/user.py +++ b/tests/plugins/identity/user.py @@ -1,6 +1,6 @@ import pytest import datetime as dt -from typing import Protocol, Unpack, final, TypedDict +from typing import final, TypedDict from server.apps.identity.models import User, _UserManager diff --git a/tests/plugins/pictures/pictures.py b/tests/plugins/pictures/pictures.py index ffbbe02d..6ea72b83 100644 --- a/tests/plugins/pictures/pictures.py +++ b/tests/plugins/pictures/pictures.py @@ -1,5 +1,6 @@ from typing import TypedDict import pytest +from mixer.backend.django import mixer from server.apps.identity.models import User from server.apps.pictures.models import FavouritePicture @@ -22,13 +23,12 @@ def favourite_picture_data(create_user) -> FavouritePictureData: @pytest.fixture -def picture_factory(): +def picture_factory(create_user): def factory( - favourite_picture: FavouritePictureData + cycle_number: int = 1 ) -> FavouritePicture: - return FavouritePicture.objects.create( - **favourite_picture - ) + user = create_user + return mixer.cycle(cycle_number).blend(FavouritePicture, user=user) return factory diff --git a/tests/test_apps/test_identity/test_indentity_user_url.py b/tests/test_apps/test_identity/test_indentity_user_url.py index d479e543..d58343c6 100644 --- a/tests/test_apps/test_identity/test_indentity_user_url.py +++ b/tests/test_apps/test_identity/test_indentity_user_url.py @@ -5,6 +5,7 @@ from django.urls import reverse +@pytest.mark.timeout(5) @pytest.mark.django_db def test_registration_view( client: Client, @@ -21,6 +22,7 @@ def test_registration_view( assert_user(registration_data['email'], user_model_data) +@pytest.mark.timeout(5) @pytest.mark.django_db def test_login( client: Client, @@ -41,6 +43,7 @@ def test_login( assert_user(data['username'], user_model_data) +@pytest.mark.timeout(5) @pytest.mark.django_db def test_user_update( client: Client, diff --git a/tests/test_apps/test_pictures/conftest.py b/tests/test_apps/test_pictures/conftest.py index 8ca2426c..ce41104d 100644 --- a/tests/test_apps/test_pictures/conftest.py +++ b/tests/test_apps/test_pictures/conftest.py @@ -1,14 +1,11 @@ -import pytest +# import pytest +# from mixer.backend.django import mixer +# from server.apps.pictures.models import FavouritePicture -@pytest.fixture -def create_two_favourite_picture( - picture_factory, - favourite_picture_data -) -> int: - # Странно получать из create_two_favourite_picture user_id - favourite_picture = picture_factory(favourite_picture_data) - second_picture_data = favourite_picture_data - second_picture_data['foreign_id'] = 2 - picture_factory(second_picture_data) - return favourite_picture.user_id +# @pytest.fixture +# def create_favourite_pictures( +# picture_factory, +# favourite_picture_data +# ) -> int: +# return mixer.blend(FavouritePicture, user=) diff --git a/tests/test_apps/test_pictures/test_pictures_logic.py b/tests/test_apps/test_pictures/test_pictures_logic.py index 9b5e9a4c..2b5a1a21 100644 --- a/tests/test_apps/test_pictures/test_pictures_logic.py +++ b/tests/test_apps/test_pictures/test_pictures_logic.py @@ -5,19 +5,33 @@ @pytest.mark.django_db +@pytest.mark.parametrize( + 'cycle_number', + [1, 3, 9] +) def test_by_user( - create_two_favourite_picture + picture_factory, + cycle_number ) -> None: - # Недостаточная проверка + + pictures = picture_factory(cycle_number) + user_id = pictures[0].user_id queryset = favourite_pictures.by_user( - user_id=create_two_favourite_picture) - assert len(queryset) == 2 + user_id=user_id) + assert len(queryset) == cycle_number @pytest.mark.django_db +@pytest.mark.parametrize( + 'cycle_number', + [1, 3, 7] +) def test_favourites_list( - create_two_favourite_picture + picture_factory, + cycle_number ) -> None: - # Недостаточная проверка + + pictures = picture_factory(cycle_number) + user_id = pictures[0].user_id favorites_list = FavouritesList() - assert len(favorites_list(create_two_favourite_picture)) == 2 + assert len(favorites_list(user_id)) == cycle_number diff --git a/tests/test_apps/test_pictures/test_pictures_models.py b/tests/test_apps/test_pictures/test_pictures_models.py index 44ed23b4..10a1694d 100644 --- a/tests/test_apps/test_pictures/test_pictures_models.py +++ b/tests/test_apps/test_pictures/test_pictures_models.py @@ -4,12 +4,11 @@ @pytest.mark.django_db def test_favourite_picture( picture_factory, - favourite_picture_data, assert_favourite_picture ) -> None: - favourite_picture = picture_factory(favourite_picture_data) + favourite_picture = picture_factory()[0] assert_favourite_picture( favourite_picture=favourite_picture, - expected=favourite_picture_data + expected=favourite_picture.__dict__ ) diff --git a/tests/test_apps/test_pictures/test_pictures_url.py b/tests/test_apps/test_pictures/test_pictures_url.py index 6b6abca9..764f6c9b 100644 --- a/tests/test_apps/test_pictures/test_pictures_url.py +++ b/tests/test_apps/test_pictures/test_pictures_url.py @@ -8,9 +8,9 @@ @pytest.mark.django_db def test_dashboard_view( client: Client, - create_two_favourite_picture + picture_factory ) -> None: - create_two_favourite_picture + picture_factory response = client.get( '/pictures/dashboard' ) @@ -20,9 +20,9 @@ def test_dashboard_view( @pytest.mark.django_db def test_favourite_picture( client: Client, - create_two_favourite_picture + picture_factory ) -> None: - create_two_favourite_picture + picture_factory response = client.get( '/pictures/favourites' ) diff --git a/tests/test_server/test_urls.py b/tests/test_server/test_urls.py index 6b59b382..01146242 100644 --- a/tests/test_server/test_urls.py +++ b/tests/test_server/test_urls.py @@ -19,6 +19,7 @@ def test_admin_unauthorized(client: Client) -> None: assert response.status_code == HTTPStatus.FOUND +@pytest.mark.timeout(5) @pytest.mark.django_db() def test_admin_authorized(admin_client: Client) -> None: """This test ensures that admin panel is accessible."""