Browse Source

Add test cases for segmentation APIs

pull/1899/head
Hironsan 2 years ago
parent
commit
754021105e
3 changed files with 38 additions and 3 deletions
  1. 35
      backend/labels/tests/test_views.py
  2. 4
      backend/labels/urls.py
  3. 2
      backend/projects/tests/utils.py

35
backend/labels/tests/test_views.py

@ -8,10 +8,11 @@ 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 BoundingBox, Category, Span, TextLabel
from labels.models import BoundingBox, Category, Segmentation, Span, TextLabel
from projects.models import (
BOUNDING_BOX,
DOCUMENT_CLASSIFICATION,
SEGMENTATION,
SEQ2SEQ,
SEQUENCE_LABELING,
)
@ -80,6 +81,16 @@ class TestBBoxList(TestLabelList, CRUDMixin):
mommy.make("BoundingBox", example=doc, user=member, x=0, y=0, width=0, height=0)
class TestSegmentationList(TestLabelList, CRUDMixin):
model = Segmentation
task = SEGMENTATION
view_name = "segmentation_list"
@classmethod
def make_annotation(cls, doc, member):
mommy.make("Segmentation", example=doc, user=member, points=[0, 1])
class TestTextList(TestLabelList, CRUDMixin):
model = TextLabel
task = SEQ2SEQ
@ -210,6 +221,20 @@ class TestBoundingBoxCreation(TestDataLabeling, CRUDMixin):
self.assert_create(member, status.HTTP_201_CREATED)
class TestSegmentationCreation(TestDataLabeling, CRUDMixin):
task = SEGMENTATION
view_name = "segmentation_list"
def create_data(self):
label = mommy.make("CategoryType", project=self.project.item)
return {"points": [1, 2], "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"
@ -293,6 +318,14 @@ class TestBBoxDetail(TestLabelDetail, CRUDMixin):
return mommy.make("BoundingBox", example=doc, user=self.project.admin, x=0, y=0, width=0, height=0)
class TestSegmentationDetail(TestLabelDetail, CRUDMixin):
task = SEGMENTATION
view_name = "segmentation_detail"
def create_annotation_data(self, doc):
return mommy.make("Segmentation", example=doc, user=self.project.admin, points=[1, 2])
class TestSharedLabelDetail:
task = DOCUMENT_CLASSIFICATION
view_name = "annotation_detail"

4
backend/labels/urls.py

@ -42,10 +42,10 @@ urlpatterns = [
view=BoundingBoxDetailAPI.as_view(),
name="bbox_detail",
),
path(route="examples/<int:example_id>/segments", view=SegmentationListAPI.as_view(), name="segment_list"),
path(route="examples/<int:example_id>/segments", view=SegmentationListAPI.as_view(), name="segmentation_list"),
path(
route="examples/<int:example_id>/segments/<int:annotation_id>",
view=SegmentationDetailAPI.as_view(),
name="segment_detail",
name="segmentation_detail",
),
]

2
backend/projects/tests/utils.py

@ -8,6 +8,7 @@ from projects.models import (
DOCUMENT_CLASSIFICATION,
IMAGE_CLASSIFICATION,
INTENT_DETECTION_AND_SLOT_FILLING,
SEGMENTATION,
SEQ2SEQ,
SEQUENCE_LABELING,
SPEECH2TEXT,
@ -70,6 +71,7 @@ def make_project(task: str, users: List[str], roles: List[str], collaborative_an
IMAGE_CLASSIFICATION: "ImageClassificationProject",
INTENT_DETECTION_AND_SLOT_FILLING: "IntentDetectionAndSlotFillingProject",
BOUNDING_BOX: "BoundingBoxProject",
SEGMENTATION: "SegmentationProject",
}.get(task, "Project")
project = mommy.make(
_model=project_model,

Loading…
Cancel
Save