Esempio n. 1
0
    def test_v2_report_fixtures_provider_iterative_total_row(self):
        report_id = 'deadbeef'
        provider = ReportFixturesProviderV2()
        report_app_config = ReportAppConfig(
            uuid='c0ffee',
            report_id=report_id,
            filters={
                'computed_owner_name_40cc88a0_1': StaticChoiceListFilter()
            })
        user = Mock(user_id='mock-user-id')

        with mock_report_configuration_get({report_id: MAKE_REPORT_CONFIG('test_domain', report_id)}), \
             patch(
                 'corehq.apps.app_manager.fixtures.mobile_ucr.ConfigurableReportDataSource') as report_datasource, \
            patch('corehq.apps.app_manager.fixtures.mobile_ucr._format_last_sync_time') as last_sync_time_patch:
            mock = self.get_data_source_mock()
            mock.has_total_row = True
            mock.total_column_ids = ['baz']
            mock.final_column_ids = ['foo', 'bar', 'baz']
            report_datasource.from_spec.return_value = mock
            last_sync_time_patch.return_value = datetime(
                2017, 9, 11, 6, 35, 20).isoformat()
            fixtures = provider.report_config_to_fixture(
                report_app_config, user)
            report = E.restore()
            report.extend(fixtures)
            self.assertXMLEqual(
                etree.tostring(report, pretty_print=True).decode('utf-8'),
                self.get_xml('expected_v2_report_total').decode('utf-8'))
Esempio n. 2
0
 def test_report_fixtures_data_cache(self):
     data_source = self.get_data_source_mock()
     cache = ReportDataCache()
     self._test_report_fixtures_provider(ReportFixturesProviderV1(cache),
                                         'expected_v1_report', data_source)
     self._test_report_fixtures_provider(ReportFixturesProviderV2(cache),
                                         'expected_v2_report', data_source)
     data_source.get_data.assert_called_once()
Esempio n. 3
0
def _get_cached_v2_report_fixture_for_user(domain, report_slug, ota_user,
                                           ls_app_version):
    """
    :param domain: the domain
    :param report_slug: the slug/alias of the report
    :param ota_user: the OTARestoreCommCareUser for which to get the report fixture
    :param ls_app_version: the version of app user is on
    """
    report_config = _get_v2_report_configs(domain, ls_app_version)[report_slug]
    xml = ReportFixturesProviderV2().report_config_to_fixture(
        report_config, ota_user)[1]
    return etree.tostring(xml)
Esempio n. 4
0
 def _test_get_oldest_sync_time(self, utcnow, synced_ids, purged_ids,
                                expected):
     sync_log = Mock()
     sync_log.last_ucr_sync_times = [
         Mock(report_uuid='a', datetime=datetime(2018, 9, 11, 6, 35, 20)),
         Mock(report_uuid='b', datetime=datetime(2017, 9, 11, 6, 35, 20))
     ]
     restore_state = Mock()
     restore_state.last_sync_log = sync_log
     restore_state.overwrite_cache = False
     synced_fixtures = [Mock(uuid=_id) for _id in synced_ids]
     with patch('corehq.apps.app_manager.fixtures.mobile_ucr._utcnow'
                ) as utcnow_patch:
         utcnow_patch.return_value = utcnow
         oldest_sync_time = ReportFixturesProviderV2._get_oldest_sync_time(
             restore_state, synced_fixtures, purged_ids)
     self.assertEqual(oldest_sync_time, expected)
Esempio n. 5
0
    def test_v2_report_fixtures_provider_caching(self):
        report_id = 'deadbeef'
        provider = ReportFixturesProviderV2()
        report_app_config = ReportAppConfig(
            uuid='c0ffee',
            report_id=report_id,
            filters={
                'computed_owner_name_40cc88a0_1': StaticChoiceListFilter()
            },
            sync_delay=1.0,
        )
        restore_user = Mock(user_id='mock-user-id')
        restore_state = Mock(
            overwrite_cache=False,
            restore_user=restore_user,
            last_sync_log=Mock(last_ucr_sync_times=()),
        )

        with mock_report_configuration_get({report_id: MAKE_REPORT_CONFIG('test_domain', report_id)}), \
                patch('corehq.apps.app_manager.fixtures.mobile_ucr.ConfigurableReportDataSource') as report_datasource, \
                patch('corehq.apps.app_manager.fixtures.mobile_ucr._utcnow') as utcnow_patch:

            report_datasource.from_spec.return_value = self.get_data_source_mock(
            )
            utcnow_patch.return_value = datetime(2017, 9, 11, 6, 35, 20)
            configs = provider._relevant_report_configs(
                restore_state, [report_app_config])
            self.assertEqual(configs, ([report_app_config], set()))

            restore_state = Mock(
                overwrite_cache=False,
                restore_user=restore_user,
                last_sync_log=Mock(last_ucr_sync_times=(
                    UCRSyncLog(report_uuid=report_app_config.uuid,
                               datetime=datetime.utcnow()), )),
            )

            configs = provider._relevant_report_configs(
                restore_state, [report_app_config])
            self.assertEqual(configs, ([], set()))

            configs = provider._relevant_report_configs(restore_state, [])
            self.assertEqual(configs, ([], {report_app_config.uuid}))
    def test_v2_report_fixtures_provider(self):
        report_id = 'deadbeef'
        provider = ReportFixturesProviderV2()
        report_app_config = ReportAppConfig(
            uuid='c0ffee',
            report_id=report_id,
            filters={
                'computed_owner_name_40cc88a0_1': StaticChoiceListFilter()
            })
        user = Mock(user_id='mock-user-id')

        with mock_report_configuration_get({report_id: MAKE_REPORT_CONFIG('test_domain', report_id)}), \
                patch('corehq.apps.app_manager.fixtures.mobile_ucr.ReportFactory') as report_factory_patch, \
                patch('corehq.apps.app_manager.fixtures.mobile_ucr._utcnow') as utcnow_patch:

            report_factory_patch.from_spec.return_value = self.get_data_source_mock(
            )
            utcnow_patch.return_value = datetime(2017, 9, 11, 6, 35, 20)
            fixtures = provider.report_config_to_v2_fixture(
                report_app_config, user)
            report = E.restore()
            report.extend(fixtures)
            self.assertXMLEqual(etree.tostring(report, pretty_print=True),
                                self.get_xml('expected_v2_report'))
Esempio n. 7
0
 def test_v2_report_fixtures_provider(self):
     self._test_report_fixtures_provider(ReportFixturesProviderV2(),
                                         'expected_v2_report')