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.admin, status.HTTP_200_OK)
  13. expected_progress = [{'user': member.username, 'done': 0} for member in self.project.members]
  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.admin)
  17. response = self.assert_fetch(self.project.admin, status.HTTP_200_OK)
  18. expected_progress = [{'user': member.username, 'done': 0} for member in self.project.members]
  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.admin)
  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.admin, status.HTTP_200_OK)
  30. expected = {
  31. member.username: {self.label.text: 0} for member in self.project.members
  32. }
  33. expected[self.project.admin.username][self.label.text] = 1
  34. self.assertEqual(response.data, expected)