def test_filter_workflowlevel2_create_date_range_org_admin(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)

        wkflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)

        date1 = '2019-05-01'
        date2 = '2019-05-02'
        date3 = '2019-05-03'

        factories.WorkflowLevel2(workflowlevel1=wkflvl1, create_date=date1)
        level22_uuid = uuid.uuid4()
        wkflvl22 = WorkflowLevel2.objects.create(workflowlevel1=wkflvl1,
                                                 create_date=date2,
                                                 level2_uuid=level22_uuid)
        factories.WorkflowLevel2(workflowlevel1=wkflvl1, create_date=date3)

        request = self.factory.get(
            f'{reverse("workflowlevel2-list")}?create_date_gte={date2}&create_date_lte={date2}'
        )
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'get': 'list'})
        response = view(request)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['level2_uuid'],
                         str(level22_uuid))
예제 #2
0
    def test_list_workflowlevel2_pagination(self, default_limit_mock):
        """ For default_limit 1 and pagination by default, list wfl2 endpoint should
         return 1 wfl2 for each page"""
        # set default_limit =1
        default_limit_mock.return_value = 1
        wfl1_1 = factories.WorkflowLevel1(organization=self.core_user.organization)
        wfl2_1 = factories.WorkflowLevel2(name='1. wfl2', workflowlevel1=wfl1_1)
        wfl2_2 = factories.WorkflowLevel2(name='2. wfl2', workflowlevel1=wfl1_1)

        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)

        request = self.factory.get('')
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)

        # default_limit = 1, so it should return just one wfl2
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['name'], wfl2_1.name)

        request = self.factory.get(response.data['next'])
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['name'], wfl2_2.name)
예제 #3
0
    def test_list_workflowlevel1_pagination(self, page_size_mock):
        """ For page_size 1 and pagination true, list wfl1 endpoint should
         return 1 wfl1 for each page"""
        # set page_size =1
        page_size_mock.return_value = 1
        wfl1_1 = factories.WorkflowLevel1(
            name='1. wfl', organization=self.core_user.organization)
        wfl1_2 = factories.WorkflowLevel1(
            name='2. wfl', organization=self.core_user.organization)
        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)

        request = self.factory.get('?paginate=true')
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)

        # page_size = 1, so it should return just one wfl1
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['name'], wfl1_1.name)

        m = re.search('=(.*)&', response.data['next'])
        cursor = m.group(1)

        request = self.factory.get('?cursor={}&paginate=true'.format(
            cursor))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['name'], wfl1_2.name)
    def test_create_workflowlevel2_org_admin(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)

        request = self.factory.post(reverse('workflowlevel2-list'))
        wfltype = factories.WorkflowLevelType()
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        data = {
            'name': 'Help Syrians',
            'workflowlevel1': wflvl1.pk,
            'type': wfltype.uuid,
        }
        request = self.factory.post(reverse('workflowlevel2-list'), data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Help Syrians')
        self.assertEqual(response.data['type'], wfltype.uuid)
    def test_update_workflowlevel2_org_admin(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)

        request = self.factory.post(reverse('workflowlevel2-list'))
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        wfltype = factories.WorkflowLevelType()

        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk,
            'type': wfltype.uuid
        }

        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(str(workflowlevel2.pk), )),
            data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 200)

        workflowlevel2 = WorkflowLevel2.objects.get(
            pk=response.data['level2_uuid'])
        self.assertEqual(workflowlevel2.name, data['name'])
        self.assertEqual(workflowlevel2.type, wfltype)
    def test_update_workflowlevel2_diff_org_admin(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)

        request = self.factory.post(reverse('workflowlevel2-list'))
        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)

        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk
        }

        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(str(workflowlevel2.pk), )),
            data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 403)
    def test_update_workflowlevel2_view_only(self):
        request = self.factory.post(reverse('workflowlevel2-list'))
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)

        group_wf_team = factories.CoreGroup(
            name='WF View Only',
            permissions=PERMISSIONS_VIEW_ONLY,
            organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk
        }

        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(str(workflowlevel2.pk), )),
            data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})

        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 403)
    def test_update_workflowlevel2_program_team(self):
        request = self.factory.post(reverse('workflowlevel2-list'))
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)

        group_wf_team = factories.CoreGroup(
            name='WF Team',
            permissions=PERMISSIONS_WORKFLOW_TEAM,
            organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk
        }

        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(str(workflowlevel2.pk), )),
            data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 200)

        workflowlevel2 = WorkflowLevel2.objects.get(
            pk=response.data['level2_uuid'])
        self.assertEqual(workflowlevel2.name, data['name'])
    def test_update_workflowlevel2_uuid_is_self_generated(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)

        group_wf_team = factories.CoreGroup(
            name='WF Team',
            permissions=PERMISSIONS_WORKFLOW_TEAM,
            organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk
        }
        request = self.factory.post(reverse('workflowlevel2-list'), data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'post': 'create'})
        response = view(request)
        self.assertEqual(response.status_code, 201)
        first_level2_uuid = response.data['level2_uuid']
        data = {
            'name': 'Community awareness program conducted to plant trees',
            'workflowlevel1': wflvl1.pk,
            'level2_uuid': '84a9888-4149-11e8-842f-0ed5f89f718b'
        }
        pk = first_level2_uuid
        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(pk, )), data)
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})
        response = view(request, pk=pk)
        self.assertEqual(response.status_code, 400)
    def test_filter_workflowlevel2_wkflvl1_name_org_admin(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)

        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        wkflvl1_2 = factories.WorkflowLevel1(
            name='Construction Project',
            organization=self.core_user.organization)
        wkflvl2 = factories.WorkflowLevel2(workflowlevel1=wkflvl1_1)
        factories.WorkflowLevel2(name='Develop brief survey',
                                 workflowlevel1=wkflvl1_2)

        request = self.factory.get('{}?workflowlevel1__name={}'.format(
            reverse('workflowlevel2-list'), wkflvl1_1.name))
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['name'], wkflvl2.name)
예제 #11
0
    def test_delete_workflowlevel1_program_admin_just_one(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)

        # Create a program
        data = {'name': 'Save the Pandas'}
        request = self.factory.post(reverse('workflowlevel1-list'), data)
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'post': 'create'})
        response = view(request)
        first_program_id = response.data['id']

        # Create another program
        data = {'name': 'Save the Children'}
        request = self.factory.post(reverse('workflowlevel1-list'), data)
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'post': 'create'})
        response = view(request)
        second_program_id = response.data['id']

        # Delete only the latter program
        request = self.factory.delete(reverse('workflowlevel1-list'))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=second_program_id)
        self.assertEqual(response.status_code, 204)
        self.assertRaises(
            WorkflowLevel1.DoesNotExist,
            WorkflowLevel1.objects.get, pk=second_program_id)
        WorkflowLevel1.objects.get(pk=first_program_id)
예제 #12
0
def org_admin(org):
    group_org_admin = factories.CoreGroup(name='Org Admin',
                                          organization=org,
                                          is_org_level=True,
                                          permissions=PERMISSIONS_ORG_ADMIN)
    coreuser = factories.CoreUser.create(
        organization=group_org_admin.organization)
    coreuser.core_groups.add(group_org_admin)
    return coreuser
    def test_update_unexisting_workflowlevel2sort(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)

        data = {'workflowlevel2_pk': 1}

        request = self.factory.post('/workflowlevel2sort/', data)
        request.user = self.core_user
        view = WorkflowLevel2SortViewSet.as_view({'post': 'update'})
        response = view(request, pk=288)
        self.assertEqual(response.status_code, 404)
예제 #14
0
    def test_update_unexisting_workflowlevel1(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)

        data = {'salary': '10'}
        request = self.factory.put(
            reverse('workflowlevel1-detail', args=(288,)), data
        )
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'put': 'update'})
        response = view(request, pk=288)
        self.assertEqual(response.status_code, 404)
예제 #15
0
    def test_list_workflowlevel1_normal_user_same_org(self):
        wflvl1 = factories.WorkflowLevel1(organization=self.core_user.organization)
        group_wf_team = factories.CoreGroup(name='WF View Only',
                                             permissions=PERMISSIONS_VIEW_ONLY,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        request = self.factory.get(reverse('workflowlevel1-list'))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
예제 #16
0
    def test_delete_workflowlevel1_different_org_admin(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)

        org_other = factories.Organization(name='Other Org')
        wflvl1 = factories.WorkflowLevel1(organization=org_other)
        request = self.factory.delete(reverse('workflowlevel1-list'))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=wflvl1.pk)
        self.assertEqual(response.status_code, 403)
        WorkflowLevel1.objects.get(pk=wflvl1.pk)
예제 #17
0
    def test_update_workflowlevel1_program_team(self):
        wflvl1 = factories.WorkflowLevel1()
        group_wf_team = factories.CoreGroup(name='WF Team',
                                             permissions=PERMISSIONS_WORKFLOW_TEAM,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        request = self.factory.put(reverse('workflowlevel1-detail', args=(wflvl1.pk,)), {'name': 'Save the Lennons'})
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'put': 'update'})
        response = view(request, pk=wflvl1.pk)
        # WFL1 admin doesn't have permissions to update this WFL1 itself
        self.assertEqual(response.status_code, 403)
예제 #18
0
    def test_update_unexisting_workflowlevel2(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)

        data = {'name': 'Community awareness program conducted to plant trees'}

        request = self.factory.put(
            reverse('workflowlevel2-detail', args=(228,)), data
        )
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'put': 'update'})
        response = view(request, pk=288)
        self.assertEqual(response.status_code, 404)
예제 #19
0
 def test_create_workflowlevel1_uuid_is_self_generated(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)
     data = {
         'name': 'Save the Children',
         'level1_uuid': '75e4c912-4149-11e8-842f-0ed5f89f718b'
     }
     request = self.factory.post(reverse('workflowlevel1-list'), data)
     request.user = self.core_user
     view = WorkflowLevel1ViewSet.as_view({'post': 'create'})
     response = view(request)
     self.assertEqual(response.status_code, 201)
     self.assertNotEqual(response.data['level1_uuid'], '75e4c912-4149-11e8-842f-0ed5f89f718b')
예제 #20
0
    def test_filter_workflowlevel1_org_admin(self):
        wflvl1 = factories.WorkflowLevel1(organization=self.core_user.organization)
        factories.WorkflowLevel1(name='Population Health Initiative', organization=self.core_user.organization)
        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)

        request = self.factory.get('{}?name={}'.format(reverse('workflowlevel1-list'), wflvl1.name))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.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'], wflvl1.name)
예제 #21
0
    def test_update_workflowlevel1_different_org_admin(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)

        wflvl1 = factories.WorkflowLevel1(
            organization=factories.Organization(name='Other Org'))
        data = {'name': 'Save the Lennons'}
        request = self.factory.put(
            reverse('workflowlevel1-detail', args=(wflvl1.pk,)), data
        )
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'put': 'update'})
        response = view(request, pk=wflvl1.pk)
        self.assertEqual(response.status_code, 403)
예제 #22
0
    def test_list_workflowlevel1_program_admin(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        wflvl2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)

        group_wfl1_admin = factories.CoreGroup(name='Workflow Admin', permissions=PERMISSIONS_WORKFLOW_ADMIN)
        wflvl1.core_groups.add(group_wfl1_admin)
        self.core_user.core_groups.add(group_wfl1_admin)

        request = self.factory.get(reverse('workflowlevel1-list'))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.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'], wflvl1.name)
예제 #23
0
    def test_delete_workflowlevel2_diff_org(self):
        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        group_wf_admin = factories.CoreGroup(name='WF Admin',
                                             permissions=PERMISSIONS_WORKFLOW_ADMIN,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_admin)
        wflvl1.core_groups.add(group_wf_admin)

        request = self.factory.delete(reverse('workflowlevel2-list'))
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 403)
        WorkflowLevel2.objects.get(pk=str(workflowlevel2.pk))
예제 #24
0
    def test_delete_workflowlevel1_program_admin(self):
        wfl1 = factories.WorkflowLevel1(name='Save the Children')

        group_wf_admin = factories.CoreGroup(name='WF Admin',
                                             permissions=PERMISSIONS_WORKFLOW_ADMIN,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_admin)
        wfl1.core_groups.add(group_wf_admin)

        # Only org admin can delete the workflow level 1
        request = self.factory.delete(reverse('workflowlevel1-list'))
        request.user = self.core_user
        view = WorkflowLevel1ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=wfl1.pk)
        self.assertEqual(response.status_code, 403)
        self.assertIsNotNone(WorkflowLevel1.objects.filter(pk=wfl1.pk).first())
예제 #25
0
    def test_delete_workflowlevel2_program_admin(self):
        wflvl1 = factories.WorkflowLevel1(organization=self.core_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        group_wf_admin = factories.CoreGroup(name='WF Admin',
                                             permissions=PERMISSIONS_WORKFLOW_ADMIN,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_admin)
        wflvl1.core_groups.add(group_wf_admin)

        request = self.factory.delete(reverse('workflowlevel2-list'))
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 204)
        self.assertRaises(
            WorkflowLevel2.DoesNotExist,
            WorkflowLevel2.objects.get, pk=str(workflowlevel2.pk))
예제 #26
0
    def test_delete_workflowlevel2_view_only(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.core_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)

        group_wf_team = factories.CoreGroup(name='WF View Only',
                                             permissions=PERMISSIONS_VIEW_ONLY,
                                             organization=self.core_user.organization)
        self.core_user.core_groups.add(group_wf_team)
        wflvl1.core_groups.add(group_wf_team)

        request = self.factory.delete(reverse('workflowlevel2-list'))
        request.user = self.core_user
        view = WorkflowLevel2ViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=str(workflowlevel2.pk))
        self.assertEqual(response.status_code, 403)
        WorkflowLevel2.objects.get(pk=str(workflowlevel2.pk))
    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)
    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_list_workflowlevel2sort_view_only(self):
     """
     list view should return only objs associated with programs that
     program view only users have access to
     """
     request = self.factory.get('/workflowlevel2sort/')
     wflvl1 = factories.WorkflowLevel1(organization=self.core_user.organization)
     group_wf_team = factories.CoreGroup(name='WF View Only',
                                         permissions=PERMISSIONS_VIEW_ONLY,
                                         organization=self.core_user.organization)
     self.core_user.core_groups.add(group_wf_team)
     wflvl1.core_groups.add(group_wf_team)
     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)
예제 #30
0
    def _create_groups(self):
        self._su_group = CoreGroup.objects.filter(is_global=True,
                                                  permissions=15).first()
        if not self._su_group:
            logger.info("Creating global CoreGroup")
            self._su_group = factories.CoreGroup(name='Global Admin',
                                                 is_global=True,
                                                 permissions=15)

        # TODO: remove this after full Group -> CoreGroup refactoring
        self._groups.append(factories.Group(name=ROLE_VIEW_ONLY, ))

        self._groups.append(factories.Group(name=ROLE_ORGANIZATION_ADMIN, ))

        self._groups.append(factories.Group(name=ROLE_WORKFLOW_ADMIN, ))

        self._groups.append(factories.Group(name=ROLE_WORKFLOW_TEAM, ))