コード例 #1
0
    def test_update_indicator_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/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {
            'name': 'Number of beneficiaries registered',
            'workflowlevel1': wflvl1_url
        }
        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'update'})
        response = view(request, pk=indicator.pk)
        self.assertEqual(response.status_code, 200)

        indicator = Indicator.objects.get(pk=response.data['id'])
        self.assertEquals(indicator.name, data['name'])
コード例 #2
0
    def test_update_indicator_program_team(self):
        request = self.factory.post('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_TEAM))
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {
            'name': 'Number of beneficiaries registered',
            'workflowlevel1': wflvl1_url
        }
        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'update'})
        response = view(request, pk=indicator.pk)
        self.assertEqual(response.status_code, 200)

        indicator = Indicator.objects.get(pk=response.data['id'])
        self.assertEquals(indicator.name, data['name'])
コード例 #3
0
    def test_create_indicator_program_admin_json(self):
        request = self.factory.post('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        wflvl2 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl2_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl2.id},
                             request=request)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))

        data = {
            'name': 'Building resilience in Mali',
            'workflowlevel1': [wflvl1_url, wflvl2_url]
        }
        request = self.factory.post('/api/indicator/',
                                    json.dumps(data),
                                    content_type='application/json')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Building resilience in Mali')
コード例 #4
0
    def test_create_indicator_program_admin_wflvl1_another_org(self):
        request = self.factory.post('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        another_org = factories.Organization(name='Another Org')
        wflvl2 = factories.WorkflowLevel1(organization=another_org)
        wflvl2_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl2.id},
                             request=request)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))

        data = {
            'name': 'Building resilience in Mali',
            'workflowlevel1': [wflvl1_url, wflvl2_url]
        }

        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 403)
コード例 #5
0
 def test_list_indicator_superuser(self):
     request = self.factory.get('/api/indicator/')
     request.user = factories.User.build(is_superuser=True, is_staff=True)
     view = IndicatorViewSet.as_view({'get': 'list'})
     response = view(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
コード例 #6
0
    def test_filter_indicator_program_admin(self):
        wflvl1_1 = factories.WorkflowLevel1()
        wflvl1_2 = factories.WorkflowLevel1(
            name='Population Health Initiative')
        indicator1_1 = factories.Indicator(workflowlevel1=[wflvl1_1])
        factories.Indicator(name='Another Indicator',
                            workflowlevel1=[wflvl1_2])

        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1_1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1_2,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))

        request = self.factory.get('/api/indicator/?workflowlevel1__name=%s' %
                                   wflvl1_1.name)
        request.user = self.tola_user.user
        view = IndicatorViewSet.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'], indicator1_1.name)
コード例 #7
0
    def test_list_indicator_normaluser(self):
        request = self.factory.get('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1()
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Indicator(workflowlevel1=[wflvl1])
        view = IndicatorViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
コード例 #8
0
 def test_delete_indicator_normal_user(self):
     indicator = factories.Indicator()
     request = self.factory.delete('/api/indicator/')
     request.user = self.tola_user.user
     view = IndicatorViewSet.as_view({'delete': 'destroy'})
     response = view(request, pk=indicator.pk)
     self.assertEquals(response.status_code, 403)
     Indicator.objects.get(pk=indicator.pk)
コード例 #9
0
    def test_update_unexisting_indicator(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        data = {'name': 'Number of beneficiaries registered'}
        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'update'})
        response = view(request, pk=288)
        self.assertEqual(response.status_code, 404)
コード例 #10
0
    def test_list_indicator_superuser_and_org_admin(self):
        request = self.factory.get('/api/indicator/')
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        request.user = factories.User.build(is_superuser=True, is_staff=True)
        view = IndicatorViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 2)
コード例 #11
0
    def test_delete_indicator_diff_org_admin(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)
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 403)
        Indicator.objects.get(pk=indicator.pk)
コード例 #12
0
    def test_delete_indicator_view_only(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1,
                                    role=factories.Group(name=ROLE_VIEW_ONLY))
        indicator = factories.Indicator(workflowlevel1=[wflvl1])

        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 403)
        Indicator.objects.get(pk=indicator.pk)
コード例 #13
0
    def test_delete_indicator_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Indicator.DoesNotExist,
                          Indicator.objects.get,
                          pk=indicator.pk)
コード例 #14
0
    def test_delete_indicator_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        wflvl1 = factories.WorkflowLevel1()
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Indicator.DoesNotExist,
                          Indicator.objects.get,
                          pk=indicator.pk)
コード例 #15
0
    def test_delete_indicator_diff_org(self):
        another_org = factories.Organization(name='Another Org')
        wflvl1 = factories.WorkflowLevel1(organization=another_org)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))
        indicator = factories.Indicator(workflowlevel1=[wflvl1])

        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 403)
        Indicator.objects.get(pk=indicator.pk)
コード例 #16
0
    def test_delete_indicator_program_admin(self):
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))
        indicator = factories.Indicator(workflowlevel1=[wflvl1])

        request = self.factory.delete('/api/indicator/')
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=indicator.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Indicator.DoesNotExist,
                          Indicator.objects.get,
                          pk=indicator.pk)
コード例 #17
0
    def test_list_indicator_program_team(self):
        request = self.factory.get('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_TEAM))
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Indicator(workflowlevel1=[wflvl1])
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
コード例 #18
0
    def test_filter_indicator_superuser(self):
        wflvl1_1 = factories.WorkflowLevel1()
        wflvl1_2 = factories.WorkflowLevel1(
            name='Population Health Initiative')
        indicator1_1 = factories.Indicator(workflowlevel1=[wflvl1_1])
        factories.Indicator(name='Another Indicator',
                            workflowlevel1=[wflvl1_2])

        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        request = self.factory.get('/api/indicator/?workflowlevel1__name=%s' %
                                   wflvl1_1.name)
        request.user = self.tola_user.user
        view = IndicatorViewSet.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'], indicator1_1.name)
コード例 #19
0
    def test_create_level_view_only(self):
        request = self.factory.post('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1,
                                    role=factories.Group(name=ROLE_VIEW_ONLY))

        data = {
            'name': 'Building resilience in Mali',
            'workflowlevel1': [wflvl1_url]
        }

        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 403)
コード例 #20
0
    def test_list_indicator_org_admin(self):
        request = self.factory.get('/api/indicator/')
        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_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl1_2 = factories.WorkflowLevel1(organization=another_org)
        wflvl1_3 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)

        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Indicator(workflowlevel1=[wflvl1_1])
        factories.Indicator(workflowlevel1=[wflvl1_2, wflvl1_3])
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 2)
コード例 #21
0
    def test_create_indicator_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

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

        data = {
            'name': 'Building resilience in Mali',
            'workflowlevel1': [wflvl1_url]
        }

        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Building resilience in Mali')
コード例 #22
0
    def test_create_indicator_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/indicator/')
        wflvl1 = factories.WorkflowLevel1()
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {
            'name': 'Building resilience in Mali',
            'workflowlevel1': [wflvl1_url]
        }

        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Building resilience in Mali')
コード例 #23
0
    def test_update_indicator_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        request = self.factory.post('/api/indicator/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        indicator = factories.Indicator(workflowlevel1=[wflvl1])
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {
            'name': 'Number of beneficiaries registered',
            'workflowlevel1': wflvl1_url
        }
        request = self.factory.post('/api/indicator/', data)
        request.user = self.tola_user.user
        view = IndicatorViewSet.as_view({'post': 'update'})
        response = view(request, pk=indicator.pk)
        self.assertEqual(response.status_code, 200)

        indicator = Indicator.objects.get(pk=response.data['id'])
        self.assertEquals(indicator.name, data['name'])