예제 #1
0
    def test_list_level_normaluser(self):
        request = self.factory.get('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Level(organization=self.tola_user.organization)
        view = LevelViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
예제 #2
0
 def test_list_level_superuser(self):
     request = self.factory.get('/api/level/')
     request.user = factories.User.build(is_superuser=True, is_staff=True)
     view = LevelViewSet.as_view({'get': 'list'})
     response = view(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
예제 #3
0
 def test_delete_level_normal_user(self):
     level = factories.Level()
     request = self.factory.delete('/api/level/')
     request.user = self.tola_user.user
     view = LevelViewSet.as_view({'delete': 'destroy'})
     response = view(request, pk=level.pk)
     self.assertEquals(response.status_code, 403)
     Level.objects.get(pk=level.pk)
예제 #4
0
    def test_update_unexisting_level(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        data = {'name': 'Intermediate Results'}
        request = self.factory.post('/api/level/', data)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'update'})
        response = view(request, pk=288)
        self.assertEqual(response.status_code, 404)
예제 #5
0
    def test_delete_level_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        level = factories.Level(organization=self.tola_user.organization)
        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Level.DoesNotExist, Level.objects.get, pk=level.pk)
예제 #6
0
    def test_update_level_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')
        level = factories.Level(organization=another_org)
        data = {'name': 'Goal'}
        request = self.factory.post('/api/level/', data)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'update'})
        response = view(request, pk=level.pk)
        self.assertEqual(response.status_code, 403)
예제 #7
0
    def test_delete_level_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')
        level = factories.Level(organization=another_org)
        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 403)
        Level.objects.get(pk=level.pk)
예제 #8
0
    def test_delete_level_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        level = factories.Level()
        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Level.DoesNotExist, Level.objects.get, pk=level.pk)
예제 #9
0
    def test_list_level_org_admin(self):
        request = self.factory.get('/api/level/')
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Level(organization=self.tola_user.organization)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
예제 #10
0
    def test_update_level_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        level = factories.Level(organization=self.tola_user.organization)
        data = {'name': 'Goal'}
        request = self.factory.post('/api/level/', data)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'update'})
        response = view(request, pk=level.pk)
        self.assertEqual(response.status_code, 200)

        level = Level.objects.get(pk=response.data['id'])
        self.assertEquals(level.name, data['name'])
예제 #11
0
    def test_update_level_view_only(self):
        wflvl1 = factories.WorkflowLevel1()
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1,
                                    role=factories.Group(name=ROLE_VIEW_ONLY))
        level = factories.Level(organization=self.tola_user.organization,
                                workflowlevel1=wflvl1)

        data = {'name': 'Goal'}
        request = self.factory.post('/api/level/', data)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'update'})
        response = view(request, pk=level.pk)
        self.assertEqual(response.status_code, 403)
예제 #12
0
    def test_delete_level_view_only(self):
        wflvl1 = factories.WorkflowLevel1()
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wflvl1,
                                    role=factories.Group(name=ROLE_VIEW_ONLY))
        level = factories.Level(organization=self.tola_user.organization,
                                workflowlevel1=wflvl1)

        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 403)
        Level.objects.get(pk=level.pk)
예제 #13
0
    def test_delete_level_program_admin(self):
        wflvl1 = factories.WorkflowLevel1()
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))
        level = factories.Level(organization=self.tola_user.organization,
                                workflowlevel1=wflvl1)

        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 204)
        self.assertRaises(Level.DoesNotExist, Level.objects.get, pk=level.pk)
예제 #14
0
    def test_update_level_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        level = factories.Level()
        data = {'name': 'Goal'}
        request = self.factory.post('/api/level/', data)
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'update'})
        response = view(request, pk=level.pk)
        self.assertEqual(response.status_code, 200)

        level = Level.objects.get(pk=response.data['id'])
        self.assertEquals(level.name, data['name'])
예제 #15
0
    def test_list_level_program_team(self):
        request = self.factory.get('/api/level/')
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            role=factories.Group(name=ROLE_PROGRAM_TEAM))
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Level(organization=self.tola_user.organization)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
예제 #16
0
    def test_delete_level_diff_org(self):
        wflvl1 = factories.WorkflowLevel1()
        another_org = factories.Organization(name='Another Org')
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_ADMIN))
        level = factories.Level(organization=another_org,
                                workflowlevel1=wflvl1)

        request = self.factory.delete('/api/level/')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'delete': 'destroy'})
        response = view(request, pk=level.pk)
        self.assertEquals(response.status_code, 403)
        Level.objects.get(pk=level.pk)
예제 #17
0
    def test_filter_level_normaluser(self):
        country1 = factories.Country(country='Brazil', code='BR')
        country2 = factories.Country()
        level1 = factories.Level(name='Level 1',
                                 country=country1,
                                 organization=self.tola_user.organization)
        factories.Level(name='Level 2',
                        country=country2,
                        organization=self.tola_user.organization)

        request = self.factory.get('/api/level/?country__country=%s' %
                                   country1.country)
        request.user = self.tola_user.user
        view = LevelViewSet.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'], level1.name)
예제 #18
0
    def test_filter_level_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        another_org = factories.Organization(name='Another Org')
        level1 = factories.Level(name='Level 1',
                                 organization=self.tola_user.organization)
        factories.Level(name='Level 2', organization=another_org)

        request = self.factory.get('/api/level/?organization__id=%s' %
                                   self.tola_user.organization.pk)
        request.user = self.tola_user.user
        view = LevelViewSet.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'], level1.name)
예제 #19
0
    def test_update_level_program_team(self):
        wflvl1 = factories.WorkflowLevel1()
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=wflvl1,
            role=factories.Group(name=ROLE_PROGRAM_TEAM))
        level = factories.Level(organization=self.tola_user.organization,
                                workflowlevel1=wflvl1)

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

        level = Level.objects.get(pk=response.data['id'])
        self.assertEquals(level.name, data['name'])
예제 #20
0
    def test_create_level_view_only(self):
        request = self.factory.post('/api/level/')
        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': 'Goal', 'workflowlevel1': wflvl1_url}

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

        self.assertEqual(response.status_code, 403)
예제 #21
0
    def test_create_level_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/level/')
        wflvl1 = factories.WorkflowLevel1()
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {'name': 'Goal', 'workflowlevel1': wflvl1_url}

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

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Goal')
예제 #22
0
    def test_create_level_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/level/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

        data = {'name': 'Goal', 'workflowlevel1': wflvl1_url}

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

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Goal')
예제 #23
0
    def test_create_level_program_admin_json(self):
        request = self.factory.post('/api/level/')
        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_PROGRAM_ADMIN))

        data = {'name': 'Goal', 'workflowlevel1': wflvl1_url}

        request = self.factory.post('/api/level/',
                                    json.dumps(data),
                                    content_type='application/json')
        request.user = self.tola_user.user
        view = LevelViewSet.as_view({'post': 'create'})
        response = view(request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Goal')