From 06d1d307a76c6ed0d18134c97af6b1f1841e75ec Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 4 Feb 2022 16:23:20 +0900 Subject: [PATCH] Move test utilities to users app --- backend/api/tests/api/utils.py | 8 +------- backend/examples/tests/test_comment.py | 3 ++- backend/examples/tests/test_document.py | 3 ++- backend/examples/tests/test_example_state.py | 3 ++- backend/label_types/tests/test_views.py | 3 ++- backend/labels/tests/test_views.py | 3 ++- backend/projects/tests/test_member.py | 3 ++- backend/projects/tests/test_project.py | 3 ++- backend/projects/tests/test_tag.py | 3 ++- backend/projects/tests/utils.py | 0 backend/roles/tests/test_views.py | 3 ++- backend/users/tests/__init__.py | 0 backend/users/{tests.py => tests/test_views.py} | 2 +- backend/users/tests/utils.py | 7 +++++++ 14 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 backend/projects/tests/utils.py create mode 100644 backend/users/tests/__init__.py rename backend/users/{tests.py => tests/test_views.py} (97%) create mode 100644 backend/users/tests/utils.py diff --git a/backend/api/tests/api/utils.py b/backend/api/tests/api/utils.py index 48d9cf44..4ac451ad 100644 --- a/backend/api/tests/api/utils.py +++ b/backend/api/tests/api/utils.py @@ -1,7 +1,6 @@ from typing import List from django.conf import settings -from django.contrib.auth import get_user_model from model_mommy import mommy from rest_framework import status from rest_framework.test import APITestCase @@ -11,6 +10,7 @@ from projects.models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION, SEQUENCE_LABELING, SPEECH2TEXT, Member) from roles.models import Role from roles.tests.utils import create_default_roles +from users.tests.utils import make_user class ProjectData: @@ -47,12 +47,6 @@ def assign_user_to_role(project_member, project, role_name): return mapping -def make_user(username: str = 'bob'): - user_model = get_user_model() - user, _ = user_model.objects.get_or_create(username=username, password='pass') - return user - - def make_project( task: str, users: List[str], diff --git a/backend/examples/tests/test_comment.py b/backend/examples/tests/test_comment.py index 093102f1..c6d6b491 100644 --- a/backend/examples/tests/test_comment.py +++ b/backend/examples/tests/test_comment.py @@ -1,7 +1,8 @@ from rest_framework import status from rest_framework.reverse import reverse -from api.tests.api.utils import (CRUDMixin, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, prepare_project) +from users.tests.utils import make_user from .utils import make_comment, make_doc diff --git a/backend/examples/tests/test_document.py b/backend/examples/tests/test_document.py index 737dd4e5..798dfff8 100644 --- a/backend/examples/tests/test_document.py +++ b/backend/examples/tests/test_document.py @@ -4,7 +4,8 @@ from rest_framework import status from rest_framework.reverse import reverse from projects.models import DOCUMENT_CLASSIFICATION -from api.tests.api.utils import (CRUDMixin, assign_user_to_role, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, assign_user_to_role, prepare_project) +from users.tests.utils import make_user from .utils import make_doc, make_example_state diff --git a/backend/examples/tests/test_example_state.py b/backend/examples/tests/test_example_state.py index a2d93afe..d2b2a723 100644 --- a/backend/examples/tests/test_example_state.py +++ b/backend/examples/tests/test_example_state.py @@ -1,7 +1,8 @@ from rest_framework import status from rest_framework.reverse import reverse -from api.tests.api.utils import (CRUDMixin, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, prepare_project) +from users.tests.utils import make_user from .utils import make_doc, make_example_state diff --git a/backend/label_types/tests/test_views.py b/backend/label_types/tests/test_views.py index bb05f737..a934a07f 100644 --- a/backend/label_types/tests/test_views.py +++ b/backend/label_types/tests/test_views.py @@ -6,7 +6,8 @@ from rest_framework.reverse import reverse from rest_framework.test import APITestCase from projects.models import DOCUMENT_CLASSIFICATION -from api.tests.api.utils import (CRUDMixin, make_project, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, make_project, prepare_project) +from users.tests.utils import make_user from .utils import make_label DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') diff --git a/backend/labels/tests/test_views.py b/backend/labels/tests/test_views.py index 28d0b9ba..b12ffce7 100644 --- a/backend/labels/tests/test_views.py +++ b/backend/labels/tests/test_views.py @@ -3,9 +3,10 @@ from rest_framework.reverse import reverse from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ from labels.models import Category, Span, TextLabel -from api.tests.api.utils import (CRUDMixin, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, prepare_project) from examples.tests.utils import make_doc from label_types.tests.utils import make_label +from users.tests.utils import make_user from .utils import make_annotation diff --git a/backend/projects/tests/test_member.py b/backend/projects/tests/test_member.py index 73596067..974d04d1 100644 --- a/backend/projects/tests/test_member.py +++ b/backend/projects/tests/test_member.py @@ -7,7 +7,8 @@ from model_mommy import mommy from roles.models import Role from projects.models import Member -from api.tests.api.utils import (CRUDMixin, prepare_project, make_user) +from api.tests.api.utils import (CRUDMixin, prepare_project) +from users.tests.utils import make_user class TestMemberListAPI(CRUDMixin): diff --git a/backend/projects/tests/test_project.py b/backend/projects/tests/test_project.py index e20e377a..71d4fb26 100644 --- a/backend/projects/tests/test_project.py +++ b/backend/projects/tests/test_project.py @@ -1,8 +1,9 @@ from rest_framework import status from rest_framework.reverse import reverse -from api.tests.api.utils import CRUDMixin, make_user, prepare_project +from api.tests.api.utils import CRUDMixin, prepare_project from roles.tests.utils import create_default_roles +from users.tests.utils import make_user class TestProjectList(CRUDMixin): diff --git a/backend/projects/tests/test_tag.py b/backend/projects/tests/test_tag.py index b748fee5..d8c7c2ec 100644 --- a/backend/projects/tests/test_tag.py +++ b/backend/projects/tests/test_tag.py @@ -1,7 +1,8 @@ from rest_framework import status from rest_framework.reverse import reverse -from api.tests.api.utils import CRUDMixin, make_tag, make_user, prepare_project +from api.tests.api.utils import CRUDMixin, make_tag, prepare_project +from users.tests.utils import make_user class TestTagList(CRUDMixin): diff --git a/backend/projects/tests/utils.py b/backend/projects/tests/utils.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/roles/tests/test_views.py b/backend/roles/tests/test_views.py index a64ea06e..979f7a14 100644 --- a/backend/roles/tests/test_views.py +++ b/backend/roles/tests/test_views.py @@ -1,7 +1,8 @@ from rest_framework import status from rest_framework.reverse import reverse -from api.tests.api.utils import (CRUDMixin, make_user) +from api.tests.api.utils import (CRUDMixin) +from users.tests.utils import make_user from .utils import create_default_roles diff --git a/backend/users/tests/__init__.py b/backend/users/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/users/tests.py b/backend/users/tests/test_views.py similarity index 97% rename from backend/users/tests.py rename to backend/users/tests/test_views.py index 44bd626d..db6cbd10 100644 --- a/backend/users/tests.py +++ b/backend/users/tests/test_views.py @@ -2,7 +2,7 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase -from api.tests.api.utils import make_user +from .utils import make_user class TestUserAPI(APITestCase): diff --git a/backend/users/tests/utils.py b/backend/users/tests/utils.py new file mode 100644 index 00000000..653a51b1 --- /dev/null +++ b/backend/users/tests/utils.py @@ -0,0 +1,7 @@ +from django.contrib.auth import get_user_model + + +def make_user(username: str = 'bob'): + user_model = get_user_model() + user, _ = user_model.objects.get_or_create(username=username, password='pass') + return user