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.

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