Exemplo n.º 1
0
    def test_update_workflowlevel2sort_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        request = self.factory.post('/api/workflowlevel2sort/')
        wflvl1 = factories.WorkflowLevel1()
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {'workflowlevel2_id': 1, 'workflowlevel1': wflvl1_url}

        request = self.factory.post('/api/workflowlevel2sort/', data)
        request.user = self.tola_user.user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 200)

        workflowlevel2sort = WorkflowLevel2Sort.objects.get(
            pk=response.data['id'])
        self.assertEquals(workflowlevel2sort.workflowlevel2_id,
                          data['workflowlevel2_id'])
    def test_delete_workflowlevel2sort_normal_user(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)

        request = self.factory.delete('/workflowlevel2sort/')
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 204)
        self.assertRaises(
            WorkflowLevel2Sort.DoesNotExist,
            WorkflowLevel2Sort.objects.get, pk=workflowlevel2sort.pk)
    def test_delete_workflowlevel2sort_superuser(self):
        self.core_user.is_staff = True
        self.core_user.is_superuser = True
        self.core_user.save()

        workflowlevel2sort = factories.WorkflowLevel2Sort()
        request = self.factory.delete('/workflowlevel2sort/')
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 204)
        self.assertRaises(
            WorkflowLevel2Sort.DoesNotExist,
            WorkflowLevel2Sort.objects.get, pk=workflowlevel2sort.pk)
    def test_update_workflowlevel2sort_diff_org_normal_user(self):
        request = self.factory.post('/workflowlevel2sort/')
        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)

        data = {'workflowlevel2_pk': uuid.uuid4(),
                'workflowlevel1': wflvl1.pk}

        request = self.factory.post('/workflowlevel2sort/', data)
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 403)
Exemplo n.º 5
0
    def test_delete_workflowlevel2sort_diff_org_normal_user(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)

        request = self.factory.delete('/api/workflowlevel2sort/')
        request.user = self.tola_user.user
        view = WorkflowLevel2SortViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEquals(response.status_code, 403)
        WorkflowLevel2Sort.objects.get(pk=workflowlevel2sort.pk)
Exemplo n.º 6
0
    def test_list_workflowlevel2sort_normal_user(self):
        request = self.factory.get('/api/workflowlevel2sort/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1)
        request.user = self.tola_user.user
        view = WorkflowLevel2SortViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.WorkflowLevel2Sort(workflowlevel1=wflvl1)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
    def test_list_workflowlevel2sort_org_admin(self):
        """
        list view should return only objs of an org to org admins
        """
        request = self.factory.get('/workflowlevel2sort/')
        group_org_admin = factories.CoreGroup(name='Org Admin', is_org_level=True,
                                              permissions=PERMISSIONS_ORG_ADMIN,
                                              organization=self.core_user.organization)
        self.core_user.core_groups.add(group_org_admin)

        wflvl1 = factories.WorkflowLevel1(organization=self.not_default_org)
        factories.WorkflowLevel2Sort(workflowlevel1=wflvl1)
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)
    def test_delete_workflowlevel2sort_diff_org_normal_user(self):
        group_org_admin = factories.CoreGroup(name='Org Admin', is_org_level=True,
                                              permissions=PERMISSIONS_ORG_ADMIN,
                                              organization=self.core_user.organization)
        self.core_user.core_groups.add(group_org_admin)

        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)

        request = self.factory.delete('/workflowlevel2sort/')
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 403)
        WorkflowLevel2Sort.objects.get(pk=workflowlevel2sort.pk)
Exemplo n.º 9
0
    def test_update_workflowlevel2sort_diff_org_normal_user(self):
        request = self.factory.post('/api/workflowlevel2sort/')
        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {'workflowlevel2_id': 1, 'workflowlevel1': wflvl1_url}

        request = self.factory.post('/api/workflowlevel2sort/', data)
        request.user = self.tola_user.user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})
        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 403)
Exemplo n.º 10
0
    def test_update_workflowlevel2sort_normal_user(self):
        request = self.factory.post('/workflowlevel2sort/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2sort = factories.WorkflowLevel2Sort(
            workflowlevel1=wflvl1)

        data = {'workflowlevel2_pk': uuid.uuid4(),
                'workflowlevel1': wflvl1.pk}

        request = self.factory.post('/workflowlevel2sort/', data)
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})
        response = view(request, pk=workflowlevel2sort.pk)

        self.assertEqual(response.status_code, 200)

        workflowlevel2sort = WorkflowLevel2Sort.objects.get(
            pk=response.data['id'])
        self.assertEqual(workflowlevel2sort.workflowlevel2_pk,
                          data['workflowlevel2_pk'])
Exemplo n.º 11
0
    def test_update_workflowlevel2sort_superuser(self):
        self.core_user.is_staff = True
        self.core_user.is_superuser = True
        self.core_user.save()

        request = self.factory.post('/workflowlevel2sort/')
        wflvl1 = factories.WorkflowLevel1()
        workflowlevel2sort = \
            factories.WorkflowLevel2Sort(workflowlevel1=wflvl1)

        data = {'workflowlevel2_pk': uuid.uuid4(),
                'workflowlevel1': wflvl1.pk}

        request = self.factory.post('/workflowlevel2sort/', data)
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})

        response = view(request, pk=workflowlevel2sort.pk)
        self.assertEqual(response.status_code, 200)

        workflowlevel2sort = WorkflowLevel2Sort.objects.get(
            pk=response.data['id'])
        self.assertEqual(str(workflowlevel2sort.workflowlevel2_pk), str(data['workflowlevel2_pk']))