def test_filter_workflowlevel2_wkflvl1_name_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl1_2 = factories.WorkflowLevel1(
            name='Construction Project',
            organization=self.tola_user.organization)
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wkflvl1_1)
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    workflowlevel1=wkflvl1_2)
        wkflvl2 = factories.WorkflowLevel2(workflowlevel1=wkflvl1_1)
        factories.WorkflowLevel2(name='Develop brief survey',
                                 workflowlevel1=wkflvl1_2)

        request = self.factory.get(
            '/api/workflowlevel2/?workflowlevel1__name=%s' % wkflvl1_1.name)
        request.user = self.tola_user.user
        view = WorkflowLevel2ViewSet.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'], wkflvl2.name)
예제 #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)
    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))
예제 #4
0
    def test_filter_checklist_country_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        country1 = factories.Country(country='Brazil', code='BR')
        country2 = factories.Country(country='Germany', code='DE')
        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization, country=[country1])
        wkflvl1_2 = factories.WorkflowLevel1(
            organization=self.tola_user.organization, country=[country2])
        wkflvl2_1 = factories.WorkflowLevel2(workflowlevel1=wkflvl1_1)
        wkflvl2_2 = factories.WorkflowLevel2(workflowlevel1=wkflvl1_2)
        checklist1 = factories.Checklist(name='Checklist A',
                                         workflowlevel2=wkflvl2_1)
        factories.Checklist(name='Checklist B', workflowlevel2=wkflvl2_2)

        request = self.factory.get(
            '/api/checklist'
            '/?workflowlevel2__workflowlevel1__country__country=%s' %
            country1.country)
        request.user = self.tola_user.user
        view = ChecklistViewSet.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'], checklist1.name)
예제 #5
0
    def test_filter_checklist_owner_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        another_user = factories.User(first_name='Johnn', last_name='Lennon')
        another_tola = factories.TolaUser(user=another_user)
        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl1_2 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl2_1 = factories.WorkflowLevel2(name='WorkflowLevel2 A',
                                             workflowlevel1=wkflvl1_1)
        wkflvl2_2 = factories.WorkflowLevel2(name='WorkflowLevel2 B',
                                             workflowlevel1=wkflvl1_2)
        checklist1 = factories.Checklist(name='Checklist A',
                                         owner=self.tola_user,
                                         workflowlevel2=wkflvl2_1)
        factories.Checklist(name='Checklist B',
                            owner=another_tola,
                            workflowlevel2=wkflvl2_2)

        request = self.factory.get('/api/checklist'
                                   '/?owner=%s' % self.tola_user.pk)
        request.user = self.tola_user.user
        view = ChecklistViewSet.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'], checklist1.name)
예제 #6
0
    def test_filter_checklist_wkflvl2_name_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl1_2 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl2_1 = factories.WorkflowLevel2(name='WorkflowLevel2 A',
                                             workflowlevel1=wkflvl1_1)
        wkflvl2_2 = factories.WorkflowLevel2(name='WorkflowLevel2 B',
                                             workflowlevel1=wkflvl1_2)
        checklist1 = factories.Checklist(name='Checklist A',
                                         workflowlevel2=wkflvl2_1)
        factories.Checklist(name='Checklist B', workflowlevel2=wkflvl2_2)

        request = self.factory.get('/api/checklist'
                                   '/?workflowlevel2__name=%s' %
                                   wkflvl2_1.name)
        request.user = self.tola_user.user
        view = ChecklistViewSet.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'], checklist1.name)
    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)
    def test_update_workflowlevel2_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/workflowlevel2/')
        wflvl1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

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

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

        workflowlevel2 = WorkflowLevel2.objects.get(pk=response.data['id'])
        self.assertEquals(workflowlevel2.name, data['name'])
    def test_update_workflowlevel2_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/workflowlevel2/')
        wflvl1 = factories.WorkflowLevel1()
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

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

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

        workflowlevel2 = WorkflowLevel2.objects.get(pk=response.data['id'])
        self.assertEquals(workflowlevel2.name, data['name'])
    def test_update_workflowlevel2_program_team(self):
        request = self.factory.post('/api/workflowlevel2/')
        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))
        workflowlevel2 = factories.WorkflowLevel2(workflowlevel1=wflvl1)
        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': wflvl1.id},
                             request=request)

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

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

        workflowlevel2 = WorkflowLevel2.objects.get(pk=response.data['id'])
        self.assertEquals(workflowlevel2.name, data['name'])
    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)
예제 #12
0
    def test_expand_data_from_buildly_permission_denied(
            self, mock_perform_request, mock_app):
        # mock app
        mock_app.return_value = Mock(App)

        # create expand data
        wfl2 = factories.WorkflowLevel2()

        self.response_data['workflowlevel2_uuid'] = wfl2.level2_uuid

        # mock response
        headers = {'Content-Type': ['application/json']}
        pyswagger_response = Mock(PySwaggerResponse)
        pyswagger_response.status = 200
        pyswagger_response.data = self.response_data
        pyswagger_response.header = headers
        mock_perform_request.return_value = pyswagger_response

        # make api request
        path = '/old/{}/{}/'.format(self.lm.endpoint_name, 'products')

        # first without permissions
        expected_message = 'You do not have permission to perform this action.'

        response = self.client.get(path, {'aggregate': 'true'})

        self.assertEqual(response.status_code, 403)
        self.assertEqual(
            json.loads(response.content)['detail'], expected_message)
    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_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_superuser(self):
        self.core_user.is_staff = True
        self.core_user.is_superuser = True
        self.core_user.save()

        request = self.factory.post(reverse('workflowlevel2-list'))
        wflvl1 = factories.WorkflowLevel1()
        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, 200)

        workflowlevel2 = WorkflowLevel2.objects.get(
            pk=response.data['level2_uuid'])
        self.assertEqual(workflowlevel2.name, data['name'])
    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)
예제 #17
0
    def test_delete_budget_value_from_wfl2(self):
        """
        When budget deleted, then related wfl2s total_estimated_budget
        should be updated
        """

        wflvl1 = factories.WorkflowLevel1(name='WorkflowLevel1',
                                          organization=self.organization)
        wflvl2 = factories.WorkflowLevel2(name='WorkflowLevel2',
                                          workflowlevel1=wflvl1,
                                          total_estimated_budget=0,
                                          actual_cost=0)
        factories.Budget(proposed_value=100,
                         actual_value=10,
                         workflowlevel2=wflvl2)

        budget_2 = factories.Budget(proposed_value=80,
                                    actual_value=20,
                                    workflowlevel2=wflvl2)

        wflvl2 = WorkflowLevel2.objects.get(pk=wflvl2.pk)
        self.assertEqual(wflvl2.total_estimated_budget, 180.00)
        self.assertEqual(wflvl2.actual_cost, 30.00)

        budget_2.delete()
        wflvl2 = WorkflowLevel2.objects.get(pk=wflvl2.pk)
        self.assertEqual(wflvl2.total_estimated_budget, 100.00)
        self.assertEqual(wflvl2.actual_cost, 10.00)
예제 #18
0
    def test_expand_data_from_buildly_superuser(self, mock_perform_request,
                                                mock_app):
        # mock app
        mock_app.return_value = Mock(App)

        # create expand data
        wfl2 = factories.WorkflowLevel2()
        self.response_data['workflowlevel2_uuid'] = wfl2.level2_uuid

        # mock response
        headers = {'Content-Type': ['application/json']}
        pyswagger_response = Mock(PySwaggerResponse)
        pyswagger_response.status = 200
        pyswagger_response.data = self.response_data
        pyswagger_response.header = headers
        mock_perform_request.return_value = pyswagger_response

        self.core_user.is_superuser = True

        # make api request
        path = '/old/{}/{}/'.format(self.lm.endpoint_name, 'products')
        response = self.client.get(path, {'aggregate': 'true'})

        # validate result
        expected_data = {
            'id': 1,
            'workflowlevel2_uuid': model_to_dict(wfl2),
            'name': 'test',
            'contact_uuid': 1
        }
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.content.decode('utf-8'),
            json.dumps(expected_data, cls=utils.GatewayJSONEncoder))
예제 #19
0
    def setUp(self):
        wflvl1 = factories.WorkflowLevel1()
        wflvl2 = factories.WorkflowLevel2(name='WorkflowLevel2',
                                          workflowlevel1=wflvl1)
        factories.Budget.create_batch(2, workflowlevel2=wflvl2)

        factory = APIRequestFactory()
        self.request = factory.get('/api/budget/')
 def test_delete_workflowlevel2_normal_user(self):
     workflowlevel2 = factories.WorkflowLevel2()
     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_workflowlevel2_normal_user(self):
     workflowlevel2 = factories.WorkflowLevel2()
     request = self.factory.delete('/api/workflowlevel2/')
     request.user = self.tola_user.user
     view = WorkflowLevel2ViewSet.as_view({'delete': 'destroy'})
     response = view(request, pk=workflowlevel2.pk)
     self.assertEquals(response.status_code, 403)
     WorkflowLevel2.objects.get(pk=workflowlevel2.pk)
예제 #22
0
 def test_save_address(self):
     factories.WorkflowLevel2(
         address={
             'street': 'Oderberger Straße',
             'house_number': '16A',
             'postal_code': '10435',
             'city': 'Berlin',
             'country': 'Germany',
         })
예제 #23
0
    def setUp(self):
        factories.Organization(id=1)
        wflvl1 = factories.WorkflowLevel1()
        wflvl2 = factories.WorkflowLevel2(name='WorkflowLevel2',
                                          workflowlevel1=wflvl1)
        factories.CodedField.create_batch(2, workflowlevel2=[wflvl2])

        factory = APIRequestFactory()
        self.request = factory.get('/api/codedfield/')
    def test_contains_expected_fields(self):
        wfl2 = factories.WorkflowLevel2()

        serializer = WorkflowLevel2NameSerializer(instance=wfl2)

        data = serializer.data

        keys = ['level2_uuid', 'name']

        self.assertEqual(set(data.keys()), set(keys))
예제 #25
0
    def test_save_address_fail(self):
        wflvl2 = factories.WorkflowLevel2()
        wflvl2.address = {
            'street': None,
        }
        self.assertRaises(ValidationError, wflvl2.save)

        wflvl2.address = {
            'house_number': 'a' * 21,
        }
        self.assertRaises(ValidationError, wflvl2.save)
예제 #26
0
    def setUp(self):
        self.old_stdout = sys.stdout
        self.old_stderr = sys.stderr
        sys.stdout = DevNull()
        sys.stderr = DevNull()
        logging.disable(logging.ERROR)

        self.org = factories.Organization()
        self.tola_user = factories.TolaUser()
        self.wfl1 = factories.WorkflowLevel1(organization=self.org)
        self.wfl2 = factories.WorkflowLevel2(workflowlevel1=self.wfl1)
    def test_filter_workflowlevel2_status_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)
        wfl_status1 = factories.WorkflowLevelStatus(name="Started Test Status",
                                                    short_name="started")
        wfl_status2 = factories.WorkflowLevelStatus(
            name="Finished Test Status", short_name="finished")
        wkflvl2_1 = factories.WorkflowLevel2(name='Started brief survey',
                                             workflowlevel1=wkflvl1,
                                             status=wfl_status1)
        wkflvl2_2 = factories.WorkflowLevel2(name='Finished brief survey',
                                             workflowlevel1=wkflvl1,
                                             status=wfl_status2)

        # filter by status.uuid
        request = self.factory.get(
            f"{reverse('workflowlevel2-list')}?status__uuid={str(wfl_status1.pk)}"
        )
        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_1.name)

        # filter by status.short_name
        request = self.factory.get(
            f"{reverse('workflowlevel2-list')}?status__short_name=finished")
        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_2.name)
    def test_filter_workflowlevel2_wkflvl1_country_superuser(self):
        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        country1 = factories.Country(country='Brazil', code='BR')
        country2 = factories.Country(country='Germany', code='DE')
        wkflvl1_1 = factories.WorkflowLevel1(country=[country1])
        wkflvl1_2 = factories.WorkflowLevel1(country=[country2])
        wkflvl2 = factories.WorkflowLevel2(workflowlevel1=wkflvl1_1)
        factories.WorkflowLevel2(name='Develop brief survey',
                                 workflowlevel1=wkflvl1_2)

        request = self.factory.get(
            '/api/workflowlevel2/?workflowlevel1__country__country=%s' %
            country1.country)
        request.user = self.tola_user.user
        view = WorkflowLevel2ViewSet.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'], wkflvl2.name)
예제 #29
0
    def test_list_budget_normaluser_one_result(self):
        tola_user = factories.TolaUser()
        wflvl1 = factories.WorkflowLevel1(name='WorkflowLevel1',
                                          organization=tola_user.organization)
        wflvl2 = factories.WorkflowLevel2(name='WorkflowLevel2',
                                          workflowlevel1=wflvl1)
        factories.Budget(workflowlevel2=wflvl2)

        self.request.user = tola_user.user
        view = BudgetViewSet.as_view({'get': 'list'})
        response = view(self.request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
    def test_delete_workflowlevel2_superuser(self):
        self.core_user.is_staff = True
        self.core_user.is_superuser = True
        self.core_user.save()

        workflowlevel2 = factories.WorkflowLevel2()
        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))