Beispiel #1
0
    def test_report_runner(self):
        d = datetime(2015, 9, 1)
        with mock.patch('custom.ilsgateway.tanzania.warehouse.updater.default_start_date', return_value=d), \
                mock.patch('custom.ilsgateway.tasks.default_start_date', return_value=d), \
                mock.patch('custom.ilsgateway.tasks.get_start_date', return_value=d):
            report_run(TEST_DOMAIN)
            self.assertEqual(OrganizationSummary.objects.filter(date__lte=datetime(2015, 9, 3)).count(), 7)

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 1
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 1
            )

            self._move_location(self.facility1, self.district2.get_id)

            pr = PendingReportingDataRecalculation.objects.filter(sql_location=self.facility1.sql_location).first()
            self.assertEqual(pr.type, 'parent_change')
            self.assertDictEqual(
                pr.data,
                {'previous_parent': self.district1.get_id, 'current_parent': self.district2.get_id}
            )

            report_run(TEST_DOMAIN)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 0
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.region1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 0
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 2
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.region2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 2
            )
    def handle(self, domain, *args, **options):
        if len(args) == 1:
            ilsgateway_id = args[0]
        else:
            ilsgateway_id = 1166  # defaults to bondenzi: http://ilsgateway.com/tz/facility/1166/

        # monkey patch the default start date to cover less data
        updater.default_start_date = lambda: datetime(2015, 1, 1)
        config = ILSGatewayConfig.for_domain(domain)
        assert config.enabled, 'ilsgateway sync must be configured for this domain'
        locations = _get_locations_from_ilsgateway_id(domain, ilsgateway_id)
        _clear_data(domain)
        report_run(domain, locations, strict=False)
    def test_report_runner2(self):
        d = datetime(2015, 9, 1)
        with mock.patch('custom.ilsgateway.tanzania.warehouse.updater.default_start_date', return_value=d), \
                mock.patch('custom.ilsgateway.tasks.default_start_date', return_value=d),\
                mock.patch('custom.ilsgateway.tasks.get_start_date', return_value=d):
            report_run(TEST_DOMAIN)
            self.assertEqual(
                OrganizationSummary.objects.filter(
                    date__lte=datetime(2015, 9, 3)).count(), 7)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.DELIVERY_FACILITY,
                ).first().total, 1)

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility2.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY).first().
                total, 1)

            self._change_group(self.facility1, 'C')
            pr = PendingReportingDataRecalculation.objects.filter(
                sql_location=self.facility1.sql_location).first()
            self.assertEqual(pr.type, 'group_change')
            self.assertDictEqual(pr.data, {
                'previous_group': 'A',
                'current_group': 'C'
            })

            report_run(TEST_DOMAIN)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.DELIVERY_FACILITY,
                ).first().total, 0)

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY,
                ).first().total, 1)

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility2.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY).first().
                total, 1)
    def test_report_runner2(self):
        d = datetime(2015, 9, 1)
        with mock.patch('custom.ilsgateway.tanzania.warehouse.updater.default_start_date', return_value=d), \
                mock.patch('custom.ilsgateway.tasks.default_start_date', return_value=d),\
                mock.patch('custom.ilsgateway.tasks.get_start_date', return_value=d):
            report_run(TEST_DOMAIN)
            self.assertEqual(OrganizationSummary.objects.filter(date__lte=datetime(2015, 9, 3)).count(), 7)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.DELIVERY_FACILITY,
                ).first().total, 1
            )

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility2.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY
                ).first().total, 1
            )

            self._change_group(self.facility1, 'C')
            pr = PendingReportingDataRecalculation.objects.filter(sql_location=self.facility1.sql_location).first()
            self.assertEqual(pr.type, 'group_change')
            self.assertDictEqual(pr.data, {'previous_group': 'A', 'current_group': 'C'})

            report_run(TEST_DOMAIN)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.DELIVERY_FACILITY,
                ).first().total, 0
            )

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility1.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY,
                ).first().total, 1
            )

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.facility2.get_id,
                    title=SupplyPointStatusTypes.R_AND_R_FACILITY
                ).first().total, 1
            )
    def test_report_runner(self):
        with mock.patch('custom.ilsgateway.tanzania.warehouse.updater.default_start_date',
                        return_value=datetime(2015, 9, 1)):
            report_run(TEST_DOMAIN)
            self.assertEqual(OrganizationSummary.objects.filter(date__lte=datetime(2015, 9, 3)).count(), 7)

            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 1
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 1
            )

            self._move_location(self.facility1, self.district2.get_id)
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 0
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.region1.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 0
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.district2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 2
            )
            self.assertEqual(
                GroupSummary.objects.filter(
                    org_summary__location_id=self.region2.get_id,
                    title=SupplyPointStatusTypes.SOH_FACILITY
                ).first().total, 2
            )