Browse Source

Update test cases

pull/1349/head
Hironsan 3 years ago
parent
commit
544682876f
6 changed files with 111 additions and 51 deletions
  1. 38
      backend/api/tests/api/test_annotation.py
  2. 13
      backend/api/tests/api/test_comment.py
  3. 52
      backend/api/tests/api/test_document.py
  4. 31
      backend/api/tests/api/test_project.py
  5. 8
      backend/api/tests/api/test_statistics.py
  6. 20
      backend/api/tests/test_models.py

38
backend/api/tests/api/test_annotation.py

@ -5,7 +5,8 @@ from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ...models import SequenceAnnotation
from ...models import (DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING,
SequenceAnnotation)
from .utils import (TestUtilsMixin, assign_user_to_role, create_default_roles,
remove_all_role_mappings)
@ -28,18 +29,29 @@ class TestAnnotationListAPI(APITestCase, TestUtilsMixin):
non_project_member = User.objects.create_user(username=cls.non_project_member_name,
password=cls.non_project_member_pass)
main_project = mommy.make('SequenceLabelingProject', users=[project_member, another_project_member])
main_project = mommy.make(
_model='SequenceLabelingProject',
users=[project_member, another_project_member],
project_type=SEQUENCE_LABELING
)
main_project_label = mommy.make('Label', project=main_project)
main_project_doc = mommy.make('Document', project=main_project)
mommy.make('SequenceAnnotation', document=main_project_doc, user=project_member)
mommy.make('SequenceAnnotation', document=main_project_doc, user=another_project_member)
sub_project = mommy.make('SequenceLabelingProject', users=[non_project_member])
sub_project = mommy.make(
_model='SequenceLabelingProject',
users=[non_project_member],
project_type=SEQUENCE_LABELING
)
sub_project_doc = mommy.make('Document', project=sub_project)
mommy.make('SequenceAnnotation', document=sub_project_doc)
cls.classification_project = mommy.make('TextClassificationProject',
users=[project_member, another_project_member])
cls.classification_project = mommy.make(
_model='TextClassificationProject',
users=[project_member, another_project_member],
project_type=DOCUMENT_CLASSIFICATION
)
cls.classification_project_label_1 = mommy.make('Label', project=cls.classification_project)
cls.classification_project_label_2 = mommy.make('Label', project=cls.classification_project)
cls.classification_project_document = mommy.make('Document', project=cls.classification_project)
@ -166,17 +178,23 @@ class TestAnnotationDetailAPI(APITestCase):
non_project_member = User.objects.create_user(username=cls.non_project_member_name,
password=cls.non_project_member_pass)
main_project = mommy.make('SequenceLabelingProject',
users=[super_user, project_member, another_project_member])
main_project = mommy.make(
_model='SequenceLabelingProject',
users=[super_user, project_member, another_project_member],
project_type=SEQUENCE_LABELING
)
main_project_doc = mommy.make('Document', project=main_project)
main_project_entity = mommy.make('SequenceAnnotation',
document=main_project_doc, user=project_member)
another_entity = mommy.make('SequenceAnnotation',
document=main_project_doc, user=another_project_member)
shared_project = mommy.make('SequenceLabelingProject',
collaborative_annotation=True,
users=[project_member, another_project_member])
shared_project = mommy.make(
_model='SequenceLabelingProject',
collaborative_annotation=True,
users=[project_member, another_project_member],
project_type=SEQUENCE_LABELING
)
shared_project_doc = mommy.make('Document', project=shared_project)
shared_entity = mommy.make('SequenceAnnotation', document=shared_project_doc, user=another_project_member)

13
backend/api/tests/api/test_comment.py

@ -5,6 +5,7 @@ from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ...models import SEQUENCE_LABELING
from .utils import (assign_user_to_role, create_default_roles,
remove_all_role_mappings)
@ -25,7 +26,11 @@ class TestCommentListAPI(APITestCase):
password=cls.another_project_member_pass)
User.objects.create_user(username=cls.non_project_member_name, password=cls.non_project_member_pass)
main_project = mommy.make('SequenceLabelingProject', users=[cls.project_member, another_project_member])
main_project = mommy.make(
_model='SequenceLabelingProject',
project_type=SEQUENCE_LABELING,
users=[cls.project_member, another_project_member]
)
main_project_doc = mommy.make('Document', project=main_project)
cls.comment = mommy.make('Comment', document=main_project_doc, text='comment 1', user=cls.project_member)
mommy.make('Comment', document=main_project_doc, text='comment 2', user=cls.project_member)
@ -41,20 +46,20 @@ class TestCommentListAPI(APITestCase):
def test_returns_comments_to_project_member(self):
self.client.login(username=self.project_member_name,
password=self.project_member_pass)
password=self.project_member_pass)
response = self.client.get(self.url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 3)
self.client.login(username=self.another_project_member_name,
password=self.another_project_member_pass)
password=self.another_project_member_pass)
response = self.client.get(self.url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 3)
def test_does_not_return_comments_to_non_project_member(self):
self.client.login(username=self.non_project_member_name,
password=self.non_project_member_pass)
password=self.non_project_member_pass)
response = self.client.get(self.url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

52
backend/api/tests/api/test_document.py

@ -5,7 +5,7 @@ from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ...models import Document
from ...models import DOCUMENT_CLASSIFICATION, Document
from .utils import (TestUtilsMixin, assign_user_to_role, create_default_roles,
remove_all_role_mappings)
@ -29,16 +29,28 @@ class TestDocumentListAPI(APITestCase, TestUtilsMixin):
password=cls.super_user_pass,
email='fizz@buzz.com')
cls.main_project = mommy.make('TextClassificationProject', users=[project_member, super_user])
cls.main_project = mommy.make(
_model='TextClassificationProject',
users=[project_member, super_user],
project_type=DOCUMENT_CLASSIFICATION
)
doc1 = mommy.make('Document', project=cls.main_project)
doc2 = mommy.make('Document', project=cls.main_project)
mommy.make('Document', project=cls.main_project)
cls.random_order_project = mommy.make('TextClassificationProject', users=[project_member, super_user],
randomize_document_order=True)
cls.random_order_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[project_member, super_user],
randomize_document_order=True
)
mommy.make('Document', 100, project=cls.random_order_project)
sub_project = mommy.make('TextClassificationProject', users=[non_project_member])
sub_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[non_project_member]
)
mommy.make('Document', project=sub_project)
cls.url = reverse(viewname='doc_list', args=[cls.main_project.id])
cls.random_order_project_url = reverse(viewname='doc_list', args=[cls.random_order_project.id])
@ -176,7 +188,11 @@ class TestDocumentDetailAPI(APITestCase):
super_user = User.objects.create_superuser(username=cls.super_user_name,
password=cls.super_user_pass,
email='fizz@buzz.com')
project = mommy.make('TextClassificationProject', users=[project_member, super_user])
project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[project_member, super_user]
)
cls.doc = mommy.make('Document', project=project)
cls.url = reverse(viewname='doc_detail', args=[project.id, cls.doc.id])
cls.data = {'text': 'example'}
@ -240,7 +256,11 @@ class TestApproveLabelsAPI(APITestCase):
password=cls.approver_pass)
project_admin = User.objects.create_user(username=cls.project_admin_name,
password=cls.project_admin_pass)
project = mommy.make('TextClassificationProject', users=[annotator, approver, project_admin])
project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[annotator, approver, project_admin]
)
cls.doc = mommy.make('Document', project=project)
cls.url = reverse(viewname='approve_labels', args=[project.id, cls.doc.id])
assign_user_to_role(project_member=annotator, project=project,
@ -294,7 +314,11 @@ class TestSearch(APITestCase):
non_project_member = User.objects.create_user(username=cls.non_project_member_name,
password=cls.non_project_member_pass)
cls.main_project = mommy.make('TextClassificationProject', users=[project_member])
cls.main_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[project_member]
)
cls.search_term = 'example'
doc1 = mommy.make('Document', text=cls.search_term, project=cls.main_project)
doc2 = mommy.make('Document', text='Lorem', project=cls.main_project)
@ -303,7 +327,11 @@ class TestSearch(APITestCase):
mommy.make('SequenceAnnotation', document=doc1, user=project_member, label=label1)
mommy.make('SequenceAnnotation', document=doc2, user=project_member, label=label2)
sub_project = mommy.make('TextClassificationProject', users=[non_project_member])
sub_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[non_project_member]
)
mommy.make('Document', text=cls.search_term, project=sub_project)
cls.url = reverse(viewname='doc_list', args=[cls.main_project.id])
cls.data = {'q': cls.search_term}
@ -368,7 +396,11 @@ class TestFilter(APITestCase):
create_default_roles()
project_member = User.objects.create_user(username=cls.project_member_name,
password=cls.project_member_pass)
cls.main_project = mommy.make('SequenceLabelingProject', users=[project_member])
cls.main_project = mommy.make(
_model='SequenceLabelingProject',
users=[project_member],
project_type='SequenceLabeling'
)
cls.label1 = mommy.make('Label', project=cls.main_project)
cls.label2 = mommy.make('Label', project=cls.main_project)
doc1 = mommy.make('Document', project=cls.main_project)

31
backend/api/tests/api/test_project.py

@ -6,6 +6,7 @@ from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ...models import DOCUMENT_CLASSIFICATION
from .utils import (assign_user_to_role, create_default_roles,
remove_all_role_mappings)
@ -33,8 +34,16 @@ class TestProjectListAPI(APITestCase):
User.objects.create_superuser(username=cls.super_user_name,
password=cls.super_user_pass,
email='fizz@buzz.com')
cls.main_project = mommy.make('TextClassificationProject', users=[main_project_member])
cls.sub_project = mommy.make('TextClassificationProject', users=[sub_project_member])
cls.main_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[main_project_member]
)
cls.sub_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[sub_project_member]
)
assign_user_to_role(project_member=main_project_member, project=cls.main_project,
role_name=settings.ROLE_ANNOTATOR)
assign_user_to_role(project_member=sub_project_member, project=cls.sub_project,
@ -118,8 +127,16 @@ class TestProjectDetailAPI(APITestCase):
password=cls.admin_user_pass,
email='fizz@buzz.com')
cls.main_project = mommy.make('TextClassificationProject', users=[cls.project_member, project_admin])
mommy.make('TextClassificationProject', users=[non_project_member])
cls.main_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[cls.project_member, project_admin]
)
mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[non_project_member]
)
cls.url = reverse(viewname='project_detail', args=[cls.main_project.id])
cls.data = {'description': 'lorem'}
assign_user_to_role(project_member=cls.project_member, project=cls.main_project,
@ -182,7 +199,11 @@ class TestTagAPI(APITestCase):
super_user = User.objects.create_superuser(username=cls.super_user_name,
password=cls.super_user_pass,
email='fizz@buzz.com')
cls.main_project = mommy.make('TextClassificationProject', users=[main_project_member, super_user])
cls.main_project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[main_project_member, super_user]
)
assign_user_to_role(project_member=main_project_member, project=cls.main_project,
role_name=settings.ROLE_ANNOTATOR)
assign_user_to_role(project_member=super_user, project=cls.main_project,

8
backend/api/tests/api/test_statistics.py

@ -4,7 +4,7 @@ from model_mommy import mommy
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ...models import Document
from ...models import DOCUMENT_CLASSIFICATION, Document
from .utils import (TestUtilsMixin, assign_user_to_role, create_default_roles,
remove_all_role_mappings)
@ -27,7 +27,11 @@ class TestStatisticsAPI(APITestCase, TestUtilsMixin):
password=cls.other_user_pass,
email='bar@buzz.com')
cls.project = mommy.make('TextClassificationProject', users=[super_user])
cls.project = mommy.make(
_model='TextClassificationProject',
project_type=DOCUMENT_CLASSIFICATION,
users=[super_user]
)
doc1 = mommy.make('Document', project=cls.project)
doc2 = mommy.make('Document', project=cls.project)
mommy.make('DocumentAnnotation', document=doc1, user=super_user)

20
backend/api/tests/test_models.py

@ -5,10 +5,6 @@ from model_mommy import mommy
from ..models import (DocumentAnnotation, Label, Seq2seqAnnotation,
SequenceAnnotation, Speech2textAnnotation)
from ..serializers import (DocumentAnnotationSerializer,
Seq2seqAnnotationSerializer,
SequenceAnnotationSerializer,
Speech2textAnnotationSerializer)
@override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage')
@ -18,10 +14,6 @@ class TestTextClassificationProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('TextClassificationProject')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
self.assertEqual(serializer, DocumentAnnotationSerializer)
def test_get_annotation_class(self):
klass = self.project.get_annotation_class()
self.assertEqual(klass, DocumentAnnotation)
@ -34,10 +26,6 @@ class TestSequenceLabelingProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('SequenceLabelingProject')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
self.assertEqual(serializer, SequenceAnnotationSerializer)
def test_get_annotation_class(self):
klass = self.project.get_annotation_class()
self.assertEqual(klass, SequenceAnnotation)
@ -50,10 +38,6 @@ class TestSeq2seqProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('Seq2seqProject')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
self.assertEqual(serializer, Seq2seqAnnotationSerializer)
def test_get_annotation_class(self):
klass = self.project.get_annotation_class()
self.assertEqual(klass, Seq2seqAnnotation)
@ -66,10 +50,6 @@ class TestSpeech2textProject(TestCase):
def setUpTestData(cls):
cls.project = mommy.make('Speech2textProject')
def test_get_annotation_serializer(self):
serializer = self.project.get_annotation_serializer()
self.assertEqual(serializer, Speech2textAnnotationSerializer)
def test_get_annotation_class(self):
klass = self.project.get_annotation_class()
self.assertEqual(klass, Speech2textAnnotation)

Loading…
Cancel
Save