def test_delete_contact_normal_user(self): contact = factories.Contact() request = self.factory.delete('/api/contact/') request.user = self.tola_user.user view = ContactViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=contact.pk) self.assertEquals(response.status_code, 403) Contact.objects.get(pk=contact.pk)
def test_filter_contact_stakeholder_org_admin(self): group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN) self.tola_user.user.groups.add(group_org_admin) wkflvl1 = factories.WorkflowLevel1() WorkflowTeam.objects.create(workflow_user=self.tola_user, workflowlevel1=wkflvl1) contact1 = factories.Contact(name='John', organization=self.tola_user.organization, workflowlevel1=wkflvl1) factories.Contact(name='Paul', organization=self.tola_user.organization, workflowlevel1=wkflvl1) request = self.factory.get('/api/contact/?name=%s' % contact1.name) request.user = self.tola_user.user view = ContactViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['name'], contact1.name)
def test_delete_contact_diff_org_program_admin(self): another_org = factories.Organization(name='Another Org') contact = factories.Contact(organization=another_org) group_org_admin = factories.Group(name=ROLE_PROGRAM_ADMIN) self.tola_user.user.groups.add(group_org_admin) request = self.factory.delete('/api/contact/') request.user = self.tola_user.user view = ContactViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=contact.pk) self.assertEquals(response.status_code, 403) Contact.objects.get(pk=contact.pk)
def test_delete_contact_org_admin(self): contact = factories.Contact(organization=self.tola_user.organization) group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN) self.tola_user.user.groups.add(group_org_admin) request = self.factory.delete('/api/contact/') request.user = self.tola_user.user view = ContactViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=contact.pk) self.assertEquals(response.status_code, 204) self.assertRaises(Contact.DoesNotExist, Contact.objects.get, pk=contact.pk)
def test_list_contact_normaluser_one_result(self): request = self.factory.get('/api/contact/') wflvl1 = WorkflowLevel1.objects.create( name='WorkflowLevel1', organization=self.tola_user.organization) WorkflowTeam.objects.create(workflow_user=self.tola_user, workflowlevel1=wflvl1) factories.Contact(organization=self.tola_user.organization, workflowlevel1=wflvl1) request.user = self.tola_user.user view = ContactViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1)
def test_delete_contact_superuser(self): self.tola_user.user.is_superuser = True self.tola_user.user.is_staff = True self.tola_user.user.save() contact = factories.Contact() request = self.factory.delete('/api/contact/') request.user = self.tola_user.user view = ContactViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=contact.pk) self.assertEquals(response.status_code, 204) self.assertRaises(Contact.DoesNotExist, Contact.objects.get, pk=contact.pk)
def test_delete_contact_program_admin(self): contact = factories.Contact(organization=self.tola_user.organization) WorkflowTeam.objects.create( workflow_user=self.tola_user, workflowlevel1=factories.WorkflowLevel1( organization=self.tola_user.organization), role=factories.Group(name=ROLE_PROGRAM_ADMIN)) request = self.factory.delete('/api/contact/') request.user = self.tola_user.user view = ContactViewSet.as_view({'delete': 'destroy'}) response = view(request, pk=contact.pk) self.assertEquals(response.status_code, 204) self.assertRaises(Contact.DoesNotExist, Contact.objects.get, pk=contact.pk)