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.

63 lines
2.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import abc
  2. from django.db import IntegrityError
  3. from django.test import TestCase
  4. from model_mommy import mommy
  5. from labels.models import TextLabel
  6. from projects.models import SEQ2SEQ
  7. from projects.tests.utils import prepare_project
  8. class TestTextLabeling(abc.ABC, TestCase):
  9. collaborative = False
  10. @classmethod
  11. def setUpTestData(cls):
  12. cls.project = prepare_project(SEQ2SEQ, collaborative_annotation=cls.collaborative)
  13. cls.example = mommy.make("Example", project=cls.project.item)
  14. cls.user = cls.project.admin
  15. cls.another_user = cls.project.approver
  16. cls.text_label = TextLabel(example=cls.example, user=cls.user, text="foo")
  17. def test_can_annotate_category_to_unannotated_data(self):
  18. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  19. self.assertTrue(can_annotate)
  20. def test_uniqueness(self):
  21. a = mommy.make("TextLabel")
  22. with self.assertRaises(IntegrityError):
  23. TextLabel(example=a.example, user=a.user, text=a.text).save()
  24. class TestNonCollaborativeTextLabeling(TestTextLabeling):
  25. collaborative = False
  26. def test_cannot_annotate_same_text_to_annotated_data(self):
  27. mommy.make("TextLabel", example=self.example, user=self.user, text=self.text_label.text)
  28. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  29. self.assertFalse(can_annotate)
  30. def test_can_annotate_different_text_to_annotated_data(self):
  31. mommy.make("TextLabel", example=self.example, user=self.user)
  32. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  33. self.assertTrue(can_annotate)
  34. def test_allow_another_user_to_annotate_same_text(self):
  35. mommy.make("TextLabel", example=self.example, user=self.another_user, text=self.text_label.text)
  36. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  37. self.assertTrue(can_annotate)
  38. class TestCollaborativeTextLabeling(TestTextLabeling):
  39. collaborative = True
  40. def test_deny_another_user_to_annotate_same_text(self):
  41. mommy.make("TextLabel", example=self.example, user=self.another_user, text=self.text_label.text)
  42. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  43. self.assertFalse(can_annotate)
  44. def test_allow_another_user_to_annotate_different_text(self):
  45. mommy.make("TextLabel", example=self.example, user=self.another_user)
  46. can_annotate = TextLabel.objects.can_annotate(self.text_label, self.project.item)
  47. self.assertTrue(can_annotate)