diff --git a/factories/users.py b/access/factories.py similarity index 100% rename from factories/users.py rename to access/factories.py diff --git a/tests/conftest.py b/access/tests/conftest.py similarity index 90% rename from tests/conftest.py rename to access/tests/conftest.py index d491651..1b6b7c1 100644 --- a/tests/conftest.py +++ b/access/tests/conftest.py @@ -2,14 +2,11 @@ import os import shutil import pytest -from django.db import transaction from tests.client import BetterAPIClient pytest_plugins = [ - 'tests.fixtures.users', - 'tests.fixtures.finance', - 'tests.fixtures.courses' + 'access.tests.fixtures', ] diff --git a/tests/fixtures/users.py b/access/tests/fixtures.py similarity index 97% rename from tests/fixtures/users.py rename to access/tests/fixtures.py index fb96d00..2849c01 100644 --- a/tests/fixtures/users.py +++ b/access/tests/fixtures.py @@ -1,6 +1,6 @@ import pytest -from factories.users import UserFactory, AccountFactory +from access.factories import UserFactory, AccountFactory from access import groups diff --git a/tests/test_user.py b/access/tests/test_access_view.py similarity index 64% rename from tests/test_user.py rename to access/tests/test_access_view.py index 9c32d22..10487a4 100644 --- a/tests/test_user.py +++ b/access/tests/test_access_view.py @@ -7,7 +7,7 @@ from django.urls import reverse from rest_framework import status from rest_framework.generics import get_object_or_404 -from factories.users import USER_PASSWORD +from access.factories import USER_PASSWORD @pytest.mark.django_db @@ -76,48 +76,45 @@ def test_generate_password_by_manager_for_not_active_student(manager_client, stu @pytest.mark.django_db -def test_login_user(api_client, student): - """ - Test login user - """ - data = { - 'email': student.email, - 'password': USER_PASSWORD - } - assert api_client.post( - reverse('users:login'), - data=data, - status=status.HTTP_200_OK - ) - - -@pytest.mark.django_db -def test_login_user_wrong_password(api_client, student): - """ - Test login user with wrong password - """ - data = { - 'email': student.email, - 'password': USER_PASSWORD + '1' - } - assert api_client.post( - reverse('users:login'), - data=data, - status=status.HTTP_403_FORBIDDEN - ) +class TestLogin: + def test_login_user(self, api_client, student): + """ + Test login user + """ + data = { + 'email': student.email, + 'password': USER_PASSWORD + } + assert api_client.post( + reverse('users:login'), + data=data, + status=status.HTTP_200_OK + ) + def test_login_user_wrong_password(self, api_client, student): + """ + Test login user with wrong password + """ + data = { + 'email': student.email, + 'password': USER_PASSWORD + '1' + } + assert api_client.post( + reverse('users:login'), + data=data, + status=status.HTTP_403_FORBIDDEN + ) -@pytest.mark.django_db -def test_login_user_wrong_user(api_client, student): - """ - Test login user with wrong password - """ - data = { - 'email': student.email + '1', - 'password': USER_PASSWORD - } - assert api_client.post( - reverse('users:login'), - data=data, - status=status.HTTP_404_NOT_FOUND - ) + def test_login_user_wrong_user(self, api_client, student): + """ + Test login user with wrong password + """ + data = { + 'email': student.email + '1', + 'password': USER_PASSWORD + } + assert api_client.post( + reverse('users:login'), + data=data, + status=status.HTTP_404_NOT_FOUND + ) diff --git a/factories/courses.py b/courses/factories.py similarity index 97% rename from factories/courses.py rename to courses/factories.py index 2e55318..1a78457 100644 --- a/factories/courses.py +++ b/courses/factories.py @@ -5,7 +5,7 @@ import factory.fuzzy from functools import partial -from factories.users import UserFactory +from access.factories import UserFactory from access import groups diff --git a/tests/fixtures/courses.py b/courses/tests/fixtures.py similarity index 78% rename from tests/fixtures/courses.py rename to courses/tests/fixtures.py index 1b468c3..3fa6080 100644 --- a/tests/fixtures/courses.py +++ b/courses/tests/fixtures.py @@ -1,6 +1,6 @@ import pytest -from factories.courses import CourseFactory, LessonFactory, TopicFactory +from courses.factories import CourseFactory, LessonFactory, TopicFactory @pytest.fixture diff --git a/factories/__init__.py b/factories/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/factories/finance.py b/finance/factories.py similarity index 94% rename from factories/finance.py rename to finance/factories.py index 0c2213d..dc109e0 100644 --- a/factories/finance.py +++ b/finance/factories.py @@ -8,8 +8,8 @@ from functools import partial from django.utils import timezone from yandex_money.models import Payment -from factories.courses import CourseFactory, TopicFactory, LessonFactory -from factories.users import UserFactory +from courses.factories import CourseFactory, TopicFactory, LessonFactory +from access.factories import UserFactory from finance.models import Invoice Faker = partial(factory.Faker, locale='ru_RU') diff --git a/finance/tests/conftest.py b/finance/tests/conftest.py new file mode 100644 index 0000000..ff4ee1d --- /dev/null +++ b/finance/tests/conftest.py @@ -0,0 +1,58 @@ +import os +import shutil + +import pytest + +from tests.client import BetterAPIClient + +pytest_plugins = [ + 'access.tests.fixtures', + 'finance.tests.fixtures', + 'courses.tests.fixtures' +] + + +def pytest_sessionfinish(session, exitstatus): + """ whole test run finishes. """ + print('pytest finish: cleanup') + if os.path.exists('media_qa'): + shutil.rmtree('media_qa') + + +@pytest.fixture +def api_client(): + """Anonymous client for REST API.""" + client = BetterAPIClient() + return client + + +@pytest.fixture +def admin_client(admin): + """Authorized as admin(superuser) client for REST API.""" + client = BetterAPIClient() + client.force_authenticate(user=admin) + return client + + +@pytest.fixture +def student_client(student): + """Authorized as student client for REST API.""" + client = BetterAPIClient() + client.force_authenticate(user=student) + return client + + +@pytest.fixture +def manager_client(manager): + """Authorized as manager client for REST API.""" + client = BetterAPIClient() + client.force_authenticate(user=manager) + return client + + +@pytest.fixture +def lead_manager_client(lead_manager): + """Authorized as lead manager client for REST API.""" + client = BetterAPIClient() + client.force_authenticate(user=lead_manager) + return client diff --git a/tests/fixtures/finance.py b/finance/tests/fixtures.py similarity index 93% rename from tests/fixtures/finance.py rename to finance/tests/fixtures.py index ab73d57..aaf050e 100644 --- a/tests/fixtures/finance.py +++ b/finance/tests/fixtures.py @@ -1,7 +1,7 @@ import pytest from yandex_money.models import Payment -from factories.finance import BillFactory, InvoiceFactory, PaymentFactory +from finance.factories import BillFactory, InvoiceFactory, PaymentFactory PRICE = 1000.00 METHOD_CASH = 'C' diff --git a/tests/test_finance.py b/finance/tests/test_finance_view.py similarity index 99% rename from tests/test_finance.py rename to finance/tests/test_finance_view.py index 1864191..1aa5023 100644 --- a/tests/test_finance.py +++ b/finance/tests/test_finance_view.py @@ -12,7 +12,7 @@ from yandex_money.models import Payment from finance import models from progress.models import Progress, ProgressLesson -from tests.fixtures.finance import PRICE, METHOD_CASH, STATUS_WAIT, STATUS_PAID +from finance.tests.fixtures import PRICE, METHOD_CASH, STATUS_WAIT, STATUS_PAID DUMMY_COMMENT = 'test comment' DUMMY_DESCRIPTION = 'test description'