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.

72 lines
3.4 KiB

  1. from django.test import TestCase
  2. from model_mommy import mommy
  3. from api.models import IMAGE_CLASSIFICATION, SEQUENCE_LABELING
  4. from api.tests.api.utils import prepare_project
  5. from examples.models import ExampleState
  6. class TestExampleState(TestCase):
  7. def setUp(self):
  8. self.project = prepare_project(SEQUENCE_LABELING)
  9. self.example = mommy.make('Example', project=self.project.item)
  10. self.other = mommy.make('Example', project=self.project.item)
  11. self.examples = self.project.item.examples.all()
  12. def test_initial_done(self):
  13. done = ExampleState.objects.count_done(self.examples)
  14. self.assertEqual(done, 0)
  15. def test_done_confirmed_by_user(self):
  16. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.admin)
  17. done = ExampleState.objects.count_done(self.examples)
  18. self.assertEqual(done, 1)
  19. def test_done_confirmed_by_multiple_user(self):
  20. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.admin)
  21. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.approver)
  22. done = ExampleState.objects.count_done(self.examples)
  23. self.assertEqual(done, 1)
  24. def test_done_confirmed_by_different_example(self):
  25. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.admin)
  26. mommy.make('ExampleState', example=self.other, confirmed_by=self.project.approver)
  27. done = ExampleState.objects.count_done(self.examples, self.project.admin)
  28. self.assertEqual(done, 1)
  29. def test_initial_user(self):
  30. progress = ExampleState.objects.measure_member_progress(self.examples, self.project.members)
  31. expected_progress = [{'user': member.username, 'done': 0} for member in self.project.members]
  32. self.assertEqual(progress, {'total': 2, 'progress': expected_progress})
  33. def test_user_count_after_confirmation(self):
  34. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.admin)
  35. progress = ExampleState.objects.measure_member_progress(self.examples, self.project.members)
  36. expected_progress = [{'user': member.username, 'done': 0} for member in self.project.members]
  37. expected_progress[0]['done'] = 1
  38. self.assertEqual(progress, {'total': 2, 'progress': expected_progress})
  39. def test_user_count_after_multiple_user_confirmation(self):
  40. user1 = self.project.admin
  41. user2 = self.project.approver
  42. mommy.make('ExampleState', example=self.example, confirmed_by=user1)
  43. mommy.make('ExampleState', example=self.example, confirmed_by=user2)
  44. progress = ExampleState.objects.measure_member_progress(self.examples, self.project.members)
  45. expected_progress = [{'user': member.username, 'done': 0} for member in self.project.members]
  46. expected_progress[0]['done'] = 1
  47. expected_progress[1]['done'] = 1
  48. self.assertEqual(progress, {'total': 2, 'progress': expected_progress})
  49. class TestExample(TestCase):
  50. def test_text_project_returns_text_as_data_property(self):
  51. project = prepare_project(SEQUENCE_LABELING)
  52. example = mommy.make('Example', project=project.item)
  53. self.assertEqual(example.text, example.data)
  54. def test_image_project_returns_filename_as_data_property(self):
  55. project = prepare_project(IMAGE_CLASSIFICATION)
  56. example = mommy.make('Example', project=project.item)
  57. self.assertEqual(str(example.filename), example.data)