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.

66 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. from rest_framework import status
  2. from rest_framework.reverse import reverse
  3. from .utils import make_doc, make_example_state
  4. from api.tests.utils import CRUDMixin
  5. from projects.tests.utils import prepare_project
  6. from users.tests.utils import make_user
  7. class TestExampleStateList(CRUDMixin):
  8. @classmethod
  9. def setUpTestData(cls):
  10. cls.non_member = make_user()
  11. cls.project = prepare_project()
  12. cls.example = make_doc(cls.project.item)
  13. for member in cls.project.members:
  14. make_example_state(cls.example, member)
  15. cls.url = reverse(viewname="example_state_list", args=[cls.project.item.id, cls.example.id])
  16. def test_returns_example_state_to_project_member(self):
  17. for member in self.project.members:
  18. response = self.assert_fetch(member, status.HTTP_200_OK)
  19. self.assertEqual(response.data["count"], 1)
  20. def test_does_not_return_example_state_to_non_project_member(self):
  21. self.assert_fetch(self.non_member, status.HTTP_403_FORBIDDEN)
  22. def test_does_not_return_example_state_to_unauthenticated_user(self):
  23. self.assert_fetch(expected=status.HTTP_403_FORBIDDEN)
  24. class TestExampleStateConfirm(CRUDMixin):
  25. def setUp(self):
  26. self.project = prepare_project()
  27. self.example = make_doc(self.project.item)
  28. self.url = reverse(viewname="example_state_list", args=[self.project.item.id, self.example.id])
  29. def test_allows_member_to_confirm_example(self):
  30. for member in self.project.members:
  31. response = self.assert_fetch(member, status.HTTP_200_OK)
  32. self.assertEqual(response.data["count"], 0)
  33. self.assert_create(member, status.HTTP_201_CREATED) # confirm
  34. response = self.assert_fetch(member, status.HTTP_200_OK)
  35. self.assertEqual(response.data["count"], 1)
  36. self.assert_create(member, status.HTTP_201_CREATED) # toggle confirm
  37. response = self.assert_fetch(member, status.HTTP_200_OK)
  38. self.assertEqual(response.data["count"], 0)
  39. class TestExampleStateConfirmCollaborative(CRUDMixin):
  40. def setUp(self):
  41. self.project = prepare_project(collaborative_annotation=True)
  42. self.example = make_doc(self.project.item)
  43. self.url = reverse(viewname="example_state_list", args=[self.project.item.id, self.example.id])
  44. def test_initial_state(self):
  45. for member in self.project.members:
  46. response = self.assert_fetch(member, status.HTTP_200_OK)
  47. self.assertEqual(response.data["count"], 0)
  48. def test_can_approve_state(self):
  49. admin = self.project.admin
  50. self.assert_create(admin, status.HTTP_201_CREATED)
  51. for member in self.project.members:
  52. response = self.assert_fetch(member, status.HTTP_200_OK)
  53. self.assertEqual(response.data["count"], 1)