You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.4 KiB

  1. import unittest
  2. from model_mommy import mommy
  3. from api.models import INTENT_DETECTION_AND_SLOT_FILLING
  4. from api.tests.api.utils import prepare_project
  5. from ..pipeline.repositories import IntentDetectionSlotFillingRepository
  6. class TestCSVWriter(unittest.TestCase):
  7. def setUp(self):
  8. self.project = prepare_project(INTENT_DETECTION_AND_SLOT_FILLING)
  9. def test_list(self):
  10. example = mommy.make('Example', project=self.project.item, text='example')
  11. category = mommy.make('Category', example=example, user=self.project.users[0])
  12. span = mommy.make('Span', example=example, user=self.project.users[0], start_offset=0, end_offset=1)
  13. repository = IntentDetectionSlotFillingRepository(self.project.item)
  14. expected = [
  15. {
  16. 'data': example.text,
  17. 'label': {
  18. 'cats': [category.label.text],
  19. 'entities': [(span.start_offset, span.end_offset, span.label.text)]
  20. }
  21. }
  22. ]
  23. records = list(repository.list())
  24. self.assertEqual(len(records), len(expected))
  25. for record, expect in zip(records, expected):
  26. self.assertEqual(record.data, expect['data'])
  27. self.assertEqual(record.label['cats'], expect['label']['cats'])
  28. self.assertEqual(record.label['entities'], expect['label']['entities'])