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.7 KiB

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