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.

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