diff --git a/backend/api/tests/api/utils.py b/backend/api/tests/api/utils.py index 1242b455..afc04016 100644 --- a/backend/api/tests/api/utils.py +++ b/backend/api/tests/api/utils.py @@ -1,4 +1,3 @@ -import os from typing import List from django.conf import settings @@ -12,8 +11,6 @@ from projects.models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION, SEQUENCE_LABELING, SPEECH2TEXT, Member) from roles.models import Role -DATA_DIR = os.path.join(os.path.dirname(__file__), '../../../data_import/tests/data') - class ProjectData: @@ -55,10 +52,6 @@ def assign_user_to_role(project_member, project, role_name): return mapping -def remove_all_members(): - Member.objects.all().delete() - - def make_user(username: str = 'bob'): user_model = get_user_model() user, _ = user_model.objects.get_or_create(username=username, password='pass') @@ -136,16 +129,6 @@ def make_auto_labeling_config(project): return mommy.make('AutoLabelingConfig', project=project) -def make_annotation(task, doc, user, **kwargs): - annotation_model = { - DOCUMENT_CLASSIFICATION: 'Category', - SEQUENCE_LABELING: 'Span', - SEQ2SEQ: 'TextLabel', - SPEECH2TEXT: 'TextLabel' - }.get(task) - return mommy.make(annotation_model, example=doc, user=user, **kwargs) - - def prepare_project(task: str = 'Any', collaborative_annotation=False, **kwargs): return make_project( task=task, diff --git a/backend/data_import/tests/data/label/invalid_labels.json b/backend/label_types/tests/data/invalid_labels.json similarity index 100% rename from backend/data_import/tests/data/label/invalid_labels.json rename to backend/label_types/tests/data/invalid_labels.json diff --git a/backend/data_import/tests/data/label/valid_labels.json b/backend/label_types/tests/data/valid_labels.json similarity index 100% rename from backend/data_import/tests/data/label/valid_labels.json rename to backend/label_types/tests/data/valid_labels.json diff --git a/backend/label_types/tests/test_views.py b/backend/label_types/tests/test_views.py index 209a196c..289f519f 100644 --- a/backend/label_types/tests/test_views.py +++ b/backend/label_types/tests/test_views.py @@ -6,7 +6,9 @@ from rest_framework.reverse import reverse from rest_framework.test import APITestCase from projects.models import DOCUMENT_CLASSIFICATION -from api.tests.api.utils import (DATA_DIR, CRUDMixin, make_label, make_project, make_user, prepare_project) +from api.tests.api.utils import (CRUDMixin, make_label, make_project, make_user, prepare_project) + +DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') class TestLabelList(CRUDMixin): @@ -140,17 +142,17 @@ class TestLabelUploadAPI(APITestCase): self.assertEqual(response.status_code, expected_status) def test_allows_project_admin_to_upload_label(self): - self.assert_upload_file('label/valid_labels.json', self.project.admin, status.HTTP_201_CREATED) + self.assert_upload_file('valid_labels.json', self.project.admin, status.HTTP_201_CREATED) def test_denies_project_member_to_upload_label(self): for member in self.project.staffs: - self.assert_upload_file('label/valid_labels.json', member, status.HTTP_403_FORBIDDEN) + self.assert_upload_file('valid_labels.json', member, status.HTTP_403_FORBIDDEN) def test_denies_non_project_member_to_upload_label(self): - self.assert_upload_file('label/valid_labels.json', self.non_member, status.HTTP_403_FORBIDDEN) + self.assert_upload_file('valid_labels.json', self.non_member, status.HTTP_403_FORBIDDEN) def test_denies_unauthenticated_user_to_upload_label(self): - self.assert_upload_file('label/valid_labels.json', expected_status=status.HTTP_403_FORBIDDEN) + self.assert_upload_file('valid_labels.json', expected_status=status.HTTP_403_FORBIDDEN) def test_try_to_upload_invalid_file(self): - self.assert_upload_file('label/invalid_labels.json', self.project.admin, status.HTTP_400_BAD_REQUEST) + self.assert_upload_file('invalid_labels.json', self.project.admin, status.HTTP_400_BAD_REQUEST) diff --git a/backend/labels/tests/test_views.py b/backend/labels/tests/test_views.py index 48cec7a4..c36df40d 100644 --- a/backend/labels/tests/test_views.py +++ b/backend/labels/tests/test_views.py @@ -3,8 +3,9 @@ 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_annotation, make_doc, make_label, +from api.tests.api.utils import (CRUDMixin, make_doc, make_label, make_user, prepare_project) +from .utils import make_annotation class TestLabelList: diff --git a/backend/labels/tests/utils.py b/backend/labels/tests/utils.py new file mode 100644 index 00000000..20efaf4b --- /dev/null +++ b/backend/labels/tests/utils.py @@ -0,0 +1,13 @@ +from model_mommy import mommy + +from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT + + +def make_annotation(task, doc, user, **kwargs): + annotation_model = { + DOCUMENT_CLASSIFICATION: 'Category', + SEQUENCE_LABELING: 'Span', + SEQ2SEQ: 'TextLabel', + SPEECH2TEXT: 'TextLabel' + }.get(task) + return mommy.make(annotation_model, example=doc, user=user, **kwargs)