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.

78 lines
3.4 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 TestProgressHelper(CRUDMixin):
  25. collaborative_annotation = False
  26. def setUp(self):
  27. self.project = prepare_project(DOCUMENT_CLASSIFICATION, collaborative_annotation=self.collaborative_annotation)
  28. self.example = make_doc(self.project.item)
  29. mommy.make("ExampleState", example=self.example, confirmed_by=self.project.admin)
  30. self.url = reverse(viewname="progress", args=[self.project.item.id])
  31. class TestProgress(TestProgressHelper):
  32. collaborative_annotation = False
  33. def test_fetch_progress(self):
  34. response = self.assert_fetch(self.project.admin, status.HTTP_200_OK)
  35. expected = {"total": 1, "remaining": 0, "complete": 1}
  36. self.assertEqual(response.data, expected)
  37. def test_cannot_affect_others_progress(self):
  38. for member in self.project.staffs:
  39. response = self.assert_fetch(member, status.HTTP_200_OK)
  40. expected = {"total": 1, "remaining": 1, "complete": 0}
  41. self.assertEqual(response.data, expected)
  42. class TestProgressOnCollaborativeAnnotation(TestProgressHelper):
  43. collaborative_annotation = True
  44. def test_fetch_progress(self):
  45. for member in self.project.members:
  46. response = self.assert_fetch(member, status.HTTP_200_OK)
  47. expected = {"total": 1, "remaining": 0, "complete": 1}
  48. self.assertEqual(response.data, expected)
  49. class TestCategoryDistribution(CRUDMixin):
  50. def setUp(self):
  51. self.project = prepare_project(DOCUMENT_CLASSIFICATION)
  52. self.example = make_doc(self.project.item)
  53. self.label = make_label(self.project.item, text="label")
  54. mommy.make("Category", example=self.example, label=self.label, user=self.project.admin)
  55. self.url = reverse(viewname="category_distribution", args=[self.project.item.id])
  56. def test_fetch_distribution(self):
  57. response = self.assert_fetch(self.project.admin, status.HTTP_200_OK)
  58. expected = {member.username: {self.label.text: 0} for member in self.project.members}
  59. expected[self.project.admin.username][self.label.text] = 1
  60. self.assertEqual(response.data, expected)