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