Browse Source

Move test utilities to roles app

pull/1671/head
Hironsan 2 years ago
parent
commit
521436d500
5 changed files with 14 additions and 8 deletions
  1. 7
      backend/api/tests/api/utils.py
  2. 3
      backend/projects/tests/test_project.py
  3. 0
      backend/roles/tests/__init__.py
  4. 3
      backend/roles/tests/test_views.py
  5. 9
      backend/roles/tests/utils.py

7
backend/api/tests/api/utils.py

@ -10,6 +10,7 @@ from projects.models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION,
INTENT_DETECTION_AND_SLOT_FILLING, SEQ2SEQ, INTENT_DETECTION_AND_SLOT_FILLING, SEQ2SEQ,
SEQUENCE_LABELING, SPEECH2TEXT, Member) SEQUENCE_LABELING, SPEECH2TEXT, Member)
from roles.models import Role from roles.models import Role
from roles.tests.utils import create_default_roles
class ProjectData: class ProjectData:
@ -35,12 +36,6 @@ class ProjectData:
return [self.approver, self.annotator] return [self.approver, self.annotator]
def create_default_roles():
Role.objects.get_or_create(name=settings.ROLE_PROJECT_ADMIN)
Role.objects.get_or_create(name=settings.ROLE_ANNOTATOR)
Role.objects.get_or_create(name=settings.ROLE_ANNOTATION_APPROVER)
def assign_user_to_role(project_member, project, role_name): def assign_user_to_role(project_member, project, role_name):
role, _ = Role.objects.get_or_create(name=role_name) role, _ = Role.objects.get_or_create(name=role_name)
if Member.objects.filter(user=project_member, project=project).exists(): if Member.objects.filter(user=project_member, project=project).exists():

3
backend/projects/tests/test_project.py

@ -1,7 +1,8 @@
from rest_framework import status from rest_framework import status
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from api.tests.api.utils import CRUDMixin, create_default_roles, make_user, prepare_project
from api.tests.api.utils import CRUDMixin, make_user, prepare_project
from roles.tests.utils import create_default_roles
class TestProjectList(CRUDMixin): class TestProjectList(CRUDMixin):

0
backend/roles/tests/__init__.py

backend/roles/tests.py → backend/roles/tests/test_views.py

@ -1,7 +1,8 @@
from rest_framework import status from rest_framework import status
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from api.tests.api.utils import (CRUDMixin, create_default_roles, make_user)
from api.tests.api.utils import (CRUDMixin, make_user)
from .utils import create_default_roles
class TestRoleAPI(CRUDMixin): class TestRoleAPI(CRUDMixin):

9
backend/roles/tests/utils.py

@ -0,0 +1,9 @@
from django.conf import settings
from roles.models import Role
def create_default_roles():
Role.objects.get_or_create(name=settings.ROLE_PROJECT_ADMIN)
Role.objects.get_or_create(name=settings.ROLE_ANNOTATOR)
Role.objects.get_or_create(name=settings.ROLE_ANNOTATION_APPROVER)
Loading…
Cancel
Save