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.

70 lines
2.4 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
  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. class TestProject(TestCase):
  6. def test_project_type(self):
  7. project = mixer.blend('server.Project')
  8. project.is_type_of(project.project_type)
  9. class TestLabel(TestCase):
  10. def test_shortcut_uniqueness(self):
  11. label = mixer.blend('server.Label')
  12. mixer.blend('server.Label', shortcut=label.shortcut)
  13. with self.assertRaises(IntegrityError):
  14. mixer.blend('server.Label',
  15. project=label.project,
  16. shortcut=label.shortcut)
  17. def test_text_uniqueness(self):
  18. label = mixer.blend('server.Label')
  19. mixer.blend('server.Label', text=label.text)
  20. with self.assertRaises(IntegrityError):
  21. mixer.blend('server.Label',
  22. project=label.project,
  23. text=label.text)
  24. class TestDocumentAnnotation(TestCase):
  25. def test_uniqueness(self):
  26. annotation1 = mixer.blend('server.DocumentAnnotation')
  27. with self.assertRaises(IntegrityError):
  28. mixer.blend('server.DocumentAnnotation',
  29. document=annotation1.document,
  30. user=annotation1.user,
  31. label=annotation1.label)
  32. class TestSequenceAnnotation(TestCase):
  33. def test_uniqueness(self):
  34. annotation1 = mixer.blend('server.SequenceAnnotation')
  35. with self.assertRaises(IntegrityError):
  36. mixer.blend('server.SequenceAnnotation',
  37. document=annotation1.document,
  38. user=annotation1.user,
  39. label=annotation1.label,
  40. start_offset=annotation1.start_offset,
  41. end_offset=annotation1.end_offset)
  42. def test_position_constraint(self):
  43. with self.assertRaises(ValidationError):
  44. mixer.blend('server.SequenceAnnotation',
  45. start_offset=1, end_offset=0).clean()
  46. class TestSeq2seqAnnotation(TestCase):
  47. def test_uniqueness(self):
  48. annotation1 = mixer.blend('server.Seq2seqAnnotation')
  49. with self.assertRaises(IntegrityError):
  50. mixer.blend('server.Seq2seqAnnotation',
  51. document=annotation1.document,
  52. user=annotation1.user,
  53. text=annotation1.text)