Browse Source

Move test utilities to examples app

pull/1671/head
Hironsan 2 years ago
parent
commit
02ad76a26f
9 changed files with 31 additions and 24 deletions
  1. 16
      backend/api/tests/api/utils.py
  2. 3
      backend/auto_labeling/tests/test_views.py
  3. 3
      backend/examples/tests/test_comment.py
  4. 4
      backend/examples/tests/test_document.py
  5. 3
      backend/examples/tests/test_example_state.py
  6. 3
      backend/examples/tests/test_filters.py
  7. 17
      backend/examples/tests/utils.py
  8. 3
      backend/labels/tests/test_views.py
  9. 3
      backend/metrics/tests.py

16
backend/api/tests/api/utils.py

@ -109,22 +109,6 @@ def make_label(project, **kwargs):
return mommy.make('SpanType', project=project, **kwargs) return mommy.make('SpanType', project=project, **kwargs)
def make_doc(project):
return mommy.make('Example', text='example', project=project)
def make_image(project, filepath):
return mommy.make('Example', filename=filepath, project=project)
def make_comment(doc, user):
return mommy.make('Comment', example=doc, user=user)
def make_example_state(example, user):
return mommy.make('ExampleState', example=example, confirmed_by=user)
def make_auto_labeling_config(project): def make_auto_labeling_config(project):
return mommy.make('AutoLabelingConfig', project=project) return mommy.make('AutoLabelingConfig', project=project)

3
backend/auto_labeling/tests/test_views.py

@ -9,7 +9,8 @@ from rest_framework.reverse import reverse
from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ
from labels.models import Category, Span, TextLabel from labels.models import Category, Span, TextLabel
from api.tests.api.utils import CRUDMixin, make_doc, prepare_project
from api.tests.api.utils import CRUDMixin, prepare_project
from examples.tests.utils import make_doc
from auto_labeling.pipeline.labels import Categories, Spans, Texts from auto_labeling.pipeline.labels import Categories, Spans, Texts
data_dir = pathlib.Path(__file__).parent / 'data' data_dir = pathlib.Path(__file__).parent / 'data'

3
backend/examples/tests/test_comment.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, make_comment, make_doc, make_user, prepare_project)
from api.tests.api.utils import (CRUDMixin, make_user, prepare_project)
from .utils import make_comment, make_doc
class TestCommentListDocAPI(CRUDMixin): class TestCommentListDocAPI(CRUDMixin):

4
backend/examples/tests/test_document.py

@ -4,8 +4,8 @@ from rest_framework import status
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from projects.models import DOCUMENT_CLASSIFICATION from projects.models import DOCUMENT_CLASSIFICATION
from api.tests.api.utils import (CRUDMixin, assign_user_to_role, make_doc,
make_example_state, make_user, prepare_project)
from api.tests.api.utils import (CRUDMixin, assign_user_to_role, make_user, prepare_project)
from .utils import make_doc, make_example_state
class TestExampleListAPI(CRUDMixin): class TestExampleListAPI(CRUDMixin):

3
backend/examples/tests/test_example_state.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, make_doc, make_example_state, make_user, prepare_project)
from api.tests.api.utils import (CRUDMixin, make_user, prepare_project)
from .utils import make_doc, make_example_state
class TestExampleStateList(CRUDMixin): class TestExampleStateList(CRUDMixin):

3
backend/examples/tests/test_filters.py

@ -2,9 +2,10 @@ from unittest.mock import MagicMock
from django.test import TestCase from django.test import TestCase
from api.tests.api.utils import make_doc, make_example_state, prepare_project
from api.tests.api.utils import prepare_project
from examples.models import Example from examples.models import Example
from examples.filters import ExampleFilter from examples.filters import ExampleFilter
from .utils import make_doc, make_example_state
class TestFilterMixin(TestCase): class TestFilterMixin(TestCase):

17
backend/examples/tests/utils.py

@ -0,0 +1,17 @@
from model_mommy import mommy
def make_comment(doc, user):
return mommy.make('Comment', example=doc, user=user)
def make_doc(project):
return mommy.make('Example', text='example', project=project)
def make_image(project, filepath):
return mommy.make('Example', filename=filepath, project=project)
def make_example_state(example, user):
return mommy.make('ExampleState', example=example, confirmed_by=user)

3
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 projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ
from labels.models import Category, Span, TextLabel from labels.models import Category, Span, TextLabel
from api.tests.api.utils import (CRUDMixin, make_doc, make_label,
from api.tests.api.utils import (CRUDMixin, make_label,
make_user, prepare_project) make_user, prepare_project)
from examples.tests.utils import make_doc
from .utils import make_annotation from .utils import make_annotation

3
backend/metrics/tests.py

@ -2,7 +2,8 @@ from model_mommy import mommy
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, prepare_project, make_doc, make_label
from api.tests.api.utils import CRUDMixin, prepare_project, make_label
from examples.tests.utils import make_doc
from projects.models import DOCUMENT_CLASSIFICATION from projects.models import DOCUMENT_CLASSIFICATION

Loading…
Cancel
Save