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.

44 lines
2.0 KiB

  1. from model_mommy import mommy
  2. from rest_framework import status
  3. from rest_framework.reverse import reverse
  4. from api.tests.api.utils import CRUDMixin, prepare_project, make_doc, make_label
  5. from api.models import DOCUMENT_CLASSIFICATION
  6. class TestMemberProgress(CRUDMixin):
  7. def setUp(self):
  8. self.project = prepare_project(DOCUMENT_CLASSIFICATION)
  9. self.example = make_doc(self.project.item)
  10. self.url = reverse(viewname='member_progress', args=[self.project.item.id])
  11. def test_fetch_initial_progress(self):
  12. response = self.assert_fetch(self.project.users[0], status.HTTP_200_OK)
  13. expected_progress = [{'user': user.username, 'done': 0} for user in self.project.users]
  14. self.assertEqual(response.data, {'total': 1, 'progress': expected_progress})
  15. def test_fetch_progress(self):
  16. mommy.make('ExampleState', example=self.example, confirmed_by=self.project.users[0])
  17. response = self.assert_fetch(self.project.users[0], status.HTTP_200_OK)
  18. expected_progress = [{'user': user.username, 'done': 0} for user in self.project.users]
  19. expected_progress[0]['done'] = 1
  20. self.assertEqual(response.data, {'total': 1, 'progress': expected_progress})
  21. class TestCategoryDistribution(CRUDMixin):
  22. def setUp(self):
  23. self.project = prepare_project(DOCUMENT_CLASSIFICATION)
  24. self.example = make_doc(self.project.item)
  25. self.label = make_label(self.project.item, text='label')
  26. mommy.make('Category', example=self.example, label=self.label, user=self.project.users[0])
  27. self.url = reverse(viewname='category_distribution', args=[self.project.item.id])
  28. def test_fetch_distribution(self):
  29. response = self.assert_fetch(self.project.users[0], status.HTTP_200_OK)
  30. expected = {
  31. user.username: {self.label.text: 0} for user in self.project.users
  32. }
  33. expected[self.project.users[0].username][self.label.text] = 1
  34. self.assertEqual(response.data, expected)