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.

68 lines
2.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. from django.test import TestCase
  2. from django.core.exceptions import ValidationError
  3. from django.db.utils import IntegrityError
  4. from mixer.backend.django import mixer
  5. from ..models import Label, DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
  6. class TestProject(TestCase):
  7. def test_project_type(self):
  8. project = mixer.blend('server.Project')
  9. project.is_type_of(project.project_type)
  10. def test_get_progress(self):
  11. project = mixer.blend('server.Project')
  12. res = project.get_progress(None)
  13. self.assertEqual(res['total'], 0)
  14. self.assertEqual(res['remaining'], 0)
  15. class TestLabel(TestCase):
  16. def test_shortcut_uniqueness(self):
  17. label = mixer.blend('server.Label')
  18. mixer.blend('server.Label', shortcut=label.shortcut)
  19. with self.assertRaises(IntegrityError):
  20. Label(project=label.project, shortcut=label.shortcut).save()
  21. def test_text_uniqueness(self):
  22. label = mixer.blend('server.Label')
  23. mixer.blend('server.Label', text=label.text)
  24. with self.assertRaises(IntegrityError):
  25. Label(project=label.project, text=label.text).save()
  26. class TestDocumentAnnotation(TestCase):
  27. def test_uniqueness(self):
  28. a = mixer.blend('server.DocumentAnnotation')
  29. with self.assertRaises(IntegrityError):
  30. DocumentAnnotation(document=a.document, user=a.user, label=a.label).save()
  31. class TestSequenceAnnotation(TestCase):
  32. def test_uniqueness(self):
  33. a = mixer.blend('server.SequenceAnnotation')
  34. with self.assertRaises(IntegrityError):
  35. SequenceAnnotation(document=a.document,
  36. user=a.user,
  37. label=a.label,
  38. start_offset=a.start_offset,
  39. end_offset=a.end_offset).save()
  40. def test_position_constraint(self):
  41. with self.assertRaises(ValidationError):
  42. mixer.blend('server.SequenceAnnotation',
  43. start_offset=1, end_offset=0).clean()
  44. class TestSeq2seqAnnotation(TestCase):
  45. def test_uniqueness(self):
  46. a = mixer.blend('server.Seq2seqAnnotation')
  47. with self.assertRaises(IntegrityError):
  48. Seq2seqAnnotation(document=a.document,
  49. user=a.user,
  50. text=a.text).save()