Browse Source

fix TestExampleStateConfirmCollaborative

pull/1473/head
youichiro 3 years ago
parent
commit
28052f6e38
1 changed files with 41 additions and 9 deletions
  1. 50
      backend/api/tests/api/test_example_state.py

50
backend/api/tests/api/test_example_state.py

@ -1,8 +1,9 @@
from django.conf import settings
from rest_framework import status
from rest_framework.reverse import reverse
from .utils import (CRUDMixin, make_doc, make_example_state, make_user,
prepare_project)
prepare_project, assign_user_to_role)
class TestExampleStateList(CRUDMixin):
@ -54,14 +55,45 @@ class TestExampleStateConfirmCollaborative(CRUDMixin):
self.example = make_doc(self.project.item)
self.url = reverse(viewname='example_state_list', args=[self.project.item.id, self.example.id])
def test_can_share_example_state(self):
member1 = self.project.users[0]
member2 = self.project.users[1]
response = self.assert_fetch(member1, status.HTTP_200_OK)
def test_cannot_share_example_state_in_other_role(self):
admin = self.project.users[0]
approver = self.project.users[1]
response = self.assert_fetch(admin, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
self.assert_create(member1, status.HTTP_201_CREATED) # confirm
response = self.assert_fetch(member1, status.HTTP_200_OK)
response = self.assert_fetch(approver, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
self.assert_create(admin, status.HTTP_201_CREATED) # confirm by admin
response = self.assert_fetch(admin, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 1)
response = self.assert_fetch(approver, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
self.assert_create(approver, status.HTTP_201_CREATED) # confirm by approver
response = self.assert_fetch(admin, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 1)
response = self.assert_fetch(approver, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 1)
self.assert_create(member2, status.HTTP_201_CREATED) # toggle confirm
response = self.assert_fetch(member1, status.HTTP_200_OK)
def test_can_share_example_state_in_same_role(self):
annotator1 = make_user()
assign_user_to_role(annotator1, self.project.item, settings.ROLE_ANNOTATOR)
annotator2 = make_user()
assign_user_to_role(annotator2, self.project.item, settings.ROLE_ANNOTATOR)
response = self.assert_fetch(annotator1, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
response = self.assert_fetch(annotator2, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
self.assert_create(annotator1, status.HTTP_201_CREATED) # confirm by annotator1
response = self.assert_fetch(annotator1, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 1)
response = self.assert_fetch(annotator2, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 1)
self.assert_create(annotator2, status.HTTP_201_CREATED) # toggle confirm by annotator2
response = self.assert_fetch(annotator1, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
response = self.assert_fetch(annotator2, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 0)
Loading…
Cancel
Save