Browse Source

Add test cases for bounding box annotation

pull/1899/head
Hironsan 2 years ago
parent
commit
fa8758b27e
3 changed files with 46 additions and 3 deletions
  1. 4
      backend/label_types/tests/utils.py
  2. 43
      backend/labels/tests/test_views.py
  3. 2
      backend/projects/tests/utils.py

4
backend/label_types/tests/utils.py

@ -1,8 +1,10 @@
from model_mommy import mommy
from projects.models import BOUNDING_BOX
def make_label(project, **kwargs):
if project.project_type.endswith("Classification"):
if project.project_type.endswith("Classification") or project.project_type == BOUNDING_BOX:
return mommy.make("CategoryType", project=project, **kwargs)
else:
return mommy.make("SpanType", project=project, **kwargs)

43
backend/labels/tests/test_views.py

@ -1,3 +1,5 @@
import uuid
from model_mommy import mommy
from rest_framework import status
from rest_framework.reverse import reverse
@ -6,8 +8,13 @@ from .utils import make_annotation
from api.tests.utils import CRUDMixin
from examples.tests.utils import make_doc
from label_types.tests.utils import make_label
from labels.models import Category, Span, TextLabel
from projects.models import DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING
from labels.models import BoundingBox, Category, Span, TextLabel
from projects.models import (
BOUNDING_BOX,
DOCUMENT_CLASSIFICATION,
SEQ2SEQ,
SEQUENCE_LABELING,
)
from projects.tests.utils import prepare_project
from users.tests.utils import make_user
@ -63,6 +70,16 @@ class TestSpanList(TestLabelList, CRUDMixin):
make_annotation(cls.task, doc=doc, user=member, start_offset=0, end_offset=1)
class TestBBoxList(TestLabelList, CRUDMixin):
model = BoundingBox
task = BOUNDING_BOX
view_name = "bbox_list"
@classmethod
def make_annotation(cls, doc, member):
mommy.make("BoundingBox", example=doc, user=member, x=0, y=0, width=0, height=0)
class TestTextList(TestLabelList, CRUDMixin):
model = TextLabel
task = SEQ2SEQ
@ -179,6 +196,20 @@ class TestTextLabelCreation(TestDataLabeling, CRUDMixin):
return {"text": "example"}
class TestBoundingBoxCreation(TestDataLabeling, CRUDMixin):
task = BOUNDING_BOX
view_name = "bbox_list"
def create_data(self):
label = mommy.make("CategoryType", project=self.project.item)
return {"x": 0, "y": 0, "width": 0, "height": 0, "label": label.id}
def test_allows_project_member_to_annotate(self):
for member in self.project.members:
self.data["uuid"] = str(uuid.uuid4())
self.assert_create(member, status.HTTP_201_CREATED)
class TestLabelDetail:
task = SEQUENCE_LABELING
view_name = "annotation_detail"
@ -254,6 +285,14 @@ class TestTextDetail(TestLabelDetail, CRUDMixin):
return make_annotation(task=self.task, doc=doc, user=self.project.admin)
class TestBBoxDetail(TestLabelDetail, CRUDMixin):
task = BOUNDING_BOX
view_name = "bbox_detail"
def create_annotation_data(self, doc):
return mommy.make("BoundingBox", example=doc, user=self.project.admin, x=0, y=0, width=0, height=0)
class TestSharedLabelDetail:
task = DOCUMENT_CLASSIFICATION
view_name = "annotation_detail"

2
backend/projects/tests/utils.py

@ -4,6 +4,7 @@ from django.conf import settings
from model_mommy import mommy
from projects.models import (
BOUNDING_BOX,
DOCUMENT_CLASSIFICATION,
IMAGE_CLASSIFICATION,
INTENT_DETECTION_AND_SLOT_FILLING,
@ -68,6 +69,7 @@ def make_project(task: str, users: List[str], roles: List[str], collaborative_an
SPEECH2TEXT: "Speech2TextProject",
IMAGE_CLASSIFICATION: "ImageClassificationProject",
INTENT_DETECTION_AND_SLOT_FILLING: "IntentDetectionAndSlotFillingProject",
BOUNDING_BOX: "BoundingBoxProject",
}.get(task, "Project")
project = mommy.make(
_model=project_model,

Loading…
Cancel
Save