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.

43 lines
2.0 KiB

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