Beispiel #1
0
    def test_end_lt_start(self):
        rp_data = {
            'title': 'Test Response Plan',
            'plan_type': 'HRP',
            'start': '2018-01-01',
            'end': '2013-01-01',
            'clusters': [
                CLUSTER_TYPES.cccm,
                CLUSTER_TYPES.nutrition,
            ],
        }

        url = reverse("response-plan-create",
                      kwargs={'workspace_id': self.workspace.id})
        response = self.client.post(url, data=rp_data, format='json')
        self.assertEquals(response.status_code,
                          status.HTTP_400_BAD_REQUEST,
                          msg=response.content)

        # Cluster system admin should also be able to create response plan
        self.admin_user = NonPartnerUserFactory()
        ClusterPRPRoleFactory(user=self.admin_user,
                              workspace=None,
                              cluster=None,
                              role=PRP_ROLE_TYPES.cluster_system_admin)
        self.client.force_authenticate(self.admin_user)

        rp_data['title'] += ' 2'
        response = self.client.post(url, data=rp_data, format='json')
        self.assertEquals(response.status_code,
                          status.HTTP_400_BAD_REQUEST,
                          msg=response.content)
Beispiel #2
0
    def test_list_api_by_user(self):
        url = reverse('workspace')
        response = self.client.get(url, format='json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(
            len(response.data),
            Workspace.objects.prefetch_related(
                'countries__gateway_types__locations').filter(
                    countries__gateway_types__locations__isnull=False).
            distinct().count())

        # Cluster system admin should also be able to query workspaces
        self.admin_user = NonPartnerUserFactory()
        ClusterPRPRoleFactory(user=self.admin_user,
                              workspace=None,
                              cluster=None,
                              role=PRP_ROLE_TYPES.cluster_system_admin)
        self.client.force_authenticate(self.admin_user)

        url = reverse('workspace')
        response = self.client.get(url, format='json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(
            len(response.data),
            Workspace.objects.prefetch_related(
                'countries__gateway_types__locations').filter(
                    countries__gateway_types__locations__isnull=False).
            distinct().count())
Beispiel #3
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.user = NonPartnerUserFactory()
        self.response_plan = ResponsePlanFactory(workspace=self.workspace)
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.prp_role = ClusterPRPRoleFactory(user=self.user,
                                              workspace=self.workspace,
                                              cluster=self.cluster,
                                              role=PRP_ROLE_TYPES.cluster_imo)

        super().setUp()
Beispiel #4
0
    def test_list_response_plan(self):
        url = reverse("response-plan",
                      kwargs={'workspace_id': self.workspace.id})
        response = self.client.get(url, format='json')

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(len(response.data),
                          self.workspace.response_plans.count())

        # Cluster system admin should also be able to query response plans
        self.admin_user = NonPartnerUserFactory()
        ClusterPRPRoleFactory(user=self.admin_user,
                              workspace=None,
                              cluster=None,
                              role=PRP_ROLE_TYPES.cluster_system_admin)
        self.client.force_authenticate(self.admin_user)

        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(len(response.data),
                          self.workspace.response_plans.count())
Beispiel #5
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.user = NonPartnerUserFactory()
        self.response_plan = ResponsePlanFactory(workspace=self.workspace)
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.prp_role = ClusterPRPRoleFactory(user=self.user,
                                              workspace=self.workspace,
                                              cluster=self.cluster,
                                              role=PRP_ROLE_TYPES.cluster_imo)
        self.loc_type = GatewayTypeFactory(country=self.country)
        self.carto_table = CartoDBTableFactory(location_type=self.loc_type,
                                               country=self.country)
        self.loc1 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.loc2 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)

        super().setUp()
Beispiel #6
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.response_plan = ResponsePlanFactory(workspace=self.workspace)
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.loc_type = GatewayTypeFactory(country=self.country)
        self.carto_table = CartoDBTableFactory(location_type=self.loc_type,
                                               country=self.country)
        self.loc1 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.loc2 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.unicef_officer = PersonFactory()
        self.unicef_focal_point = PersonFactory()
        self.partner_focal_point = PersonFactory()
        self.objective = ClusterObjectiveFactory(cluster=self.cluster,
                                                 locations=[
                                                     self.loc1,
                                                     self.loc2,
                                                 ])
        self.activity = ClusterActivityFactory(
            cluster_objective=self.objective, locations=[self.loc1, self.loc2])
        self.partner = PartnerFactory(
            country_code=self.country.country_short_code)
        self.user = NonPartnerUserFactory()
        self.partner_user = PartnerUserFactory(partner=self.partner)
        ClusterPRPRoleFactory(user=self.user,
                              workspace=self.workspace,
                              cluster=self.cluster,
                              role=PRP_ROLE_TYPES.cluster_imo)
        IPPRPRoleFactory(user=self.partner_user,
                         workspace=self.workspace,
                         role=PRP_ROLE_TYPES.ip_authorized_officer)
        IPPRPRoleFactory(user=self.partner_user,
                         workspace=self.workspace,
                         cluster=None,
                         role=PRP_ROLE_TYPES.cluster_member)
        self.project = PartnerProjectFactory(
            partner=self.partner,
            clusters=[self.cluster],
            locations=[self.loc1, self.loc2],
        )
        self.p_activity = ClusterActivityPartnerActivityFactory(
            partner=self.partner,
            cluster_activity=self.activity,
        )
        self.project_context = PartnerActivityProjectContextFactory(
            project=self.project,
            activity=self.p_activity,
        )
        self.sample_disaggregation_value_map = {
            "height": ["tall", "medium", "short", "extrashort"],
            "age": ["1-2m", "3-4m", "5-6m", '7-10m', '11-13m', '14-16m'],
            "gender": ["male", "female", "other"],
        }

        blueprint = QuantityTypeIndicatorBlueprintFactory(
            unit=IndicatorBlueprint.NUMBER,
            calculation_formula_across_locations=IndicatorBlueprint.SUM,
            calculation_formula_across_periods=IndicatorBlueprint.SUM,
        )
        self.partneractivity_reportable = QuantityReportableToPartnerActivityProjectContextFactory(
            content_object=self.project_context, blueprint=blueprint)

        LocationWithReportableLocationGoalFactory(
            location=self.loc1,
            reportable=self.partneractivity_reportable,
        )

        LocationWithReportableLocationGoalFactory(
            location=self.loc2,
            reportable=self.partneractivity_reportable,
        )

        self.pd = ProgrammeDocumentFactory(workspace=self.workspace,
                                           partner=self.partner,
                                           sections=[
                                               SectionFactory(),
                                           ],
                                           unicef_officers=[
                                               self.unicef_officer,
                                           ],
                                           unicef_focal_point=[
                                               self.unicef_focal_point,
                                           ],
                                           partner_focal_point=[
                                               self.partner_focal_point,
                                           ])

        for idx in range(2):
            qpr_period = QPRReportingPeriodDatesFactory(
                programme_document=self.pd)
            ProgressReportFactory(
                start_date=qpr_period.start_date,
                end_date=qpr_period.end_date,
                due_date=qpr_period.due_date,
                report_number=idx + 1,
                report_type=qpr_period.report_type,
                is_final=False,
                programme_document=self.pd,
                submitted_by=self.user,
                submitting_user=self.user,
            )

        for idx in range(6):
            hr_period = HRReportingPeriodDatesFactory(
                programme_document=self.pd)
            ProgressReportFactory(
                start_date=hr_period.start_date,
                end_date=hr_period.end_date,
                due_date=hr_period.due_date,
                report_number=idx + 1,
                report_type=hr_period.report_type,
                is_final=False,
                programme_document=self.pd,
                submitted_by=self.user,
                submitting_user=self.user,
            )

        self.cp_output = PDResultLinkFactory(programme_document=self.pd, )
        self.llo = LowerLevelOutputFactory(cp_output=self.cp_output, )
        self.llo_reportable = QuantityReportableToLowerLevelOutputFactory(
            content_object=self.llo,
            blueprint=QuantityTypeIndicatorBlueprintFactory(
                unit=IndicatorBlueprint.NUMBER,
                calculation_formula_across_locations=IndicatorBlueprint.SUM,
            ))

        self.llo_reportable.disaggregations.clear()
        self.partneractivity_reportable.disaggregations.clear()

        # Create the disaggregations and values in the db for all response plans
        # including one for no response plan as well
        for disagg_name, values in self.sample_disaggregation_value_map.items(
        ):
            disagg = IPDisaggregationFactory(name=disagg_name)
            cluster_disagg = DisaggregationFactory(
                name=disagg_name, response_plan=self.response_plan)

            self.llo_reportable.disaggregations.add(disagg)
            self.partneractivity_reportable.disaggregations.add(cluster_disagg)

            for value in values:
                DisaggregationValueFactory(disaggregation=cluster_disagg,
                                           value=value)
                DisaggregationValueFactory(disaggregation=disagg, value=value)

        LocationWithReportableLocationGoalFactory(
            location=self.loc1,
            reportable=self.llo_reportable,
        )

        LocationWithReportableLocationGoalFactory(
            location=self.loc2,
            reportable=self.llo_reportable,
        )

        for _ in range(2):
            with patch("django.db.models.signals.ModelSignal.send", Mock()):
                ClusterIndicatorReportFactory(
                    reportable=self.partneractivity_reportable,
                    report_status=INDICATOR_REPORT_STATUS.submitted,
                )

        # Creating Level-3 disaggregation location data for all locations
        generate_3_num_disagg_data(self.partneractivity_reportable,
                                   indicator_type="quantity")

        for loc_data in IndicatorLocationData.objects.filter(
                indicator_report__reportable=self.partneractivity_reportable):
            QuantityIndicatorDisaggregator.post_process(loc_data)

        for pr in self.pd.progress_reports.all():
            ProgressReportIndicatorReportFactory(
                progress_report=pr,
                reportable=self.llo_reportable,
                report_status=INDICATOR_REPORT_STATUS.submitted,
                overall_status=OVERALL_STATUS.met,
            )

        # Creating Level-3 disaggregation location data for all locations
        generate_3_num_disagg_data(self.llo_reportable,
                                   indicator_type="quantity")

        for loc_data in IndicatorLocationData.objects.filter(
                indicator_report__reportable=self.llo_reportable):
            QuantityIndicatorDisaggregator.post_process(loc_data)

        super().setUp()
Beispiel #7
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.user = NonPartnerUserFactory()
        self.response_plan = ResponsePlanFactory(workspace=self.workspace)
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.prp_role = ClusterPRPRoleFactory(user=self.user,
                                              workspace=self.workspace,
                                              cluster=self.cluster,
                                              role=PRP_ROLE_TYPES.cluster_imo)
        self.loc_type = GatewayTypeFactory(country=self.country)
        self.carto_table = CartoDBTableFactory(location_type=self.loc_type,
                                               country=self.country)
        self.loc1 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.loc2 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)

        for _ in range(2):
            obj = ClusterObjectiveFactory(cluster=self.cluster,
                                          locations=[
                                              self.loc1,
                                              self.loc2,
                                          ])

            activity = ClusterActivityFactory(cluster_objective=obj,
                                              locations=[self.loc1, self.loc2])

            blueprint = QuantityTypeIndicatorBlueprintFactory()
            clusteractivity_reportable = QuantityReportableToClusterActivityFactory(
                content_object=activity, blueprint=blueprint)

            clusteractivity_reportable.disaggregations.clear()

            self.sample_disaggregation_value_map = {
                "height": ["tall", "medium", "short", "extrashort"],
                "age": ["1-2m", "3-4m", "5-6m", '7-10m', '11-13m', '14-16m'],
                "gender": ["male", "female", "other"],
            }

            # Create the disaggregations and values in the db for all response plans
            # including one for no response plan as well
            for disagg_name, values in self.sample_disaggregation_value_map.items(
            ):
                for value in values:
                    DisaggregationValueFactory(
                        disaggregation=DisaggregationFactory(
                            name=disagg_name,
                            response_plan=self.response_plan),
                        value=value)

            add_disaggregations_to_reportable(
                clusteractivity_reportable,
                disaggregation_targets=["age", "gender", "height"])

            LocationWithReportableLocationGoalFactory(
                location=self.loc1,
                reportable=clusteractivity_reportable,
            )

            LocationWithReportableLocationGoalFactory(
                location=self.loc2,
                reportable=clusteractivity_reportable,
            )

        super().setUp()
Beispiel #8
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.response_plan = ResponsePlanFactory(workspace=self.workspace)
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.loc_type = GatewayTypeFactory(country=self.country)
        self.carto_table = CartoDBTableFactory(location_type=self.loc_type,
                                               country=self.country)
        self.user = NonPartnerUserFactory()
        self.prp_role = ClusterPRPRoleFactory(user=self.user,
                                              workspace=self.workspace,
                                              cluster=self.cluster,
                                              role=PRP_ROLE_TYPES.cluster_imo)
        self.loc1 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.loc2 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)

        self.objective = ClusterObjectiveFactory(cluster=self.cluster,
                                                 locations=[
                                                     self.loc1,
                                                     self.loc2,
                                                 ])

        self.activity = ClusterActivityFactory(
            cluster_objective=self.objective, locations=[self.loc1, self.loc2])

        self.partner = PartnerFactory(
            country_code=self.country.country_short_code)

        self.project = PartnerProjectFactory(
            partner=self.partner,
            clusters=[self.cluster],
            locations=[self.loc1, self.loc2],
        )

        self.p_activity = ClusterActivityPartnerActivityFactory(
            partner=self.partner,
            cluster_activity=self.activity,
        )
        self.project_context = PartnerActivityProjectContextFactory(
            project=self.project,
            activity=self.p_activity,
        )

        self.sample_disaggregation_value_map = {
            "height": ["tall", "medium", "short", "extrashort"],
            "age": ["1-2m", "3-4m", "5-6m", '7-10m', '11-13m', '14-16m'],
            "gender": ["male", "female", "other"],
        }

        # Create the disaggregations and values in the db for all response plans
        # including one for no response plan as well
        for disagg_name, values in self.sample_disaggregation_value_map.items(
        ):
            for value in values:
                DisaggregationValueFactory(
                    disaggregation=DisaggregationFactory(
                        name=disagg_name, response_plan=self.response_plan),
                    value=value)

        super().setUp()
Beispiel #9
0
    def setUp(self):
        self.country = CountryFactory()
        self.workspace = WorkspaceFactory(countries=[
            self.country,
        ])
        self.response_plan = ResponsePlanFactory(
            workspace=self.workspace,
            start=beginning_of_this_year,
            end=end_of_this_year,
        )
        self.cluster = ClusterFactory(type='cccm',
                                      response_plan=self.response_plan)
        self.loc_type = GatewayTypeFactory(country=self.country)
        self.carto_table = CartoDBTableFactory(location_type=self.loc_type,
                                               country=self.country)
        self.loc1 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.loc2 = LocationFactory(gateway=self.loc_type,
                                    carto_db_table=self.carto_table)
        self.unicef_officer = PersonFactory()
        self.unicef_focal_point = PersonFactory()
        self.partner_focal_point = PersonFactory()
        self.objective = ClusterObjectiveFactory(cluster=self.cluster,
                                                 locations=[
                                                     self.loc1,
                                                     self.loc2,
                                                 ])
        self.activity = ClusterActivityFactory(
            cluster_objective=self.objective, locations=[self.loc1, self.loc2])
        self.partner = PartnerFactory(
            country_code=self.country.country_short_code,
            clusters=[
                self.cluster,
            ])
        self.user = NonPartnerUserFactory()
        self.partner_user = PartnerUserFactory(partner=self.partner)
        ClusterPRPRoleFactory(user=self.user,
                              workspace=self.workspace,
                              cluster=self.cluster,
                              role=PRP_ROLE_TYPES.cluster_imo)
        IPPRPRoleFactory(user=self.partner_user,
                         workspace=self.workspace,
                         role=PRP_ROLE_TYPES.ip_authorized_officer)
        IPPRPRoleFactory(user=self.partner_user,
                         workspace=self.workspace,
                         cluster=None,
                         role=PRP_ROLE_TYPES.cluster_member)
        self.project = PartnerProjectFactory(
            partner=self.partner,
            clusters=[self.cluster],
            locations=[self.loc1, self.loc2],
            start_date=datetime.date(today.year, 3, 1),
            end_date=datetime.date(today.year, 10, 25),
        )

        super().setUp()

        self.data = {
            "cluster":
            self.cluster.id,
            "partner":
            self.partner.id,
            "projects": [{
                "project_id":
                self.project.id,
                "start_date":
                self.project.start_date.strftime(settings.PRINT_DATA_FORMAT),
                "end_date":
                self.project.end_date.strftime(settings.PRINT_DATA_FORMAT),
                "status":
                "Ong"
            }],
        }