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.

28 lines
1.2 KiB

  1. from django.test import TestCase
  2. from model_mommy import mommy
  3. from ..pipeline.labels import Categories
  4. from data_export.models import ExportedExample
  5. from projects.models import DOCUMENT_CLASSIFICATION
  6. from projects.tests.utils import prepare_project
  7. class TestLabels(TestCase):
  8. def setUp(self):
  9. self.project = prepare_project(task=DOCUMENT_CLASSIFICATION)
  10. self.example1 = mommy.make("ExportedExample", project=self.project.item)
  11. self.example2 = mommy.make("ExportedExample", project=self.project.item)
  12. self.category1 = mommy.make("ExportedCategory", example=self.example1, user=self.project.admin)
  13. self.examples = ExportedExample.objects.all()
  14. def test_find_by(self):
  15. categories = Categories(self.examples)
  16. result = categories.find_by(self.example1.id)
  17. self.assertEqual(len(result[Categories.column]), 1)
  18. result = categories.find_by(self.example2.id)
  19. self.assertEqual(len(result[Categories.column]), 0)
  20. def test_find_by_with_user(self):
  21. categories = Categories(self.examples, user=self.project.annotator)
  22. result = categories.find_by(self.example1.id)
  23. self.assertEqual(len(result[Categories.column]), 0)