class CollaboratorApiTestC ase SubMatterDataApiTest CaseMixin APITestC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class CollaboratorApiTestCase(SubMatterDataApiTestCaseMixin, APITestCase):
model = Collaborator
object_factory = CollaboratorFactory
permission_level = Collaborator.OWNER
def post_parameters(self, organization):
return {
'sub_matter': SubMatterFactory(matter__organization=organization).pk,
'organization': OrganizationFactory().pk,
'level': Collaborator.COLLABORATOR
}
def patch_parameters(self):
return {
'level': Collaborator.ADMIN
}
def test_submatter_filter(self):
# override this test to account for implicitly created collaborations
self.login(self.user)
active_organization = self.get_primary(self.user)
sub_matter1 = SubMatterFactory(matter__organization=active_organization)
sub_matter2 = SubMatterFactory(matter__organization=active_organization)
self.create_object(sub_matter=sub_matter1)
self.create_object(sub_matter=sub_matter2)
res = self.client.get(reverse(self._reverse_list))
self.assertEqual(len(res.data), 2 + 2) # 2 collaborations were created implicitly
res = self.client.get(reverse(self._reverse_list), {'sub_matter': sub_matter1.pk})
self.assertEqual(len(res.data), 1 + 1)
res = self.client.get(reverse(self._reverse_list), {'sub_matter': sub_matter2.pk})
self.assertEqual(len(res.data), 1 + 1)
def test_collaborator_can_get_list(self):
# override this test to account for implicitly created collaborations
self.login(self.user)
sub_matter = SubMatterFactory() # one collaboration created implicitly here
active_organization = self.get_primary(self.user)
self.create_collaboration(sub_matter, active_organization, Collaborator.VIEW) # this collaboration is required
# for self.user to be allowed to
# perform the action
self.create_batch(3, sub_matter=sub_matter)
res = self.client.get(reverse(self._reverse_list))
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 3 + 2)