Exemplo n.º 1
0
    def test_all_media_report_module(self):
        """
        Report Modules support media
        """
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application")

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(report_id=report._id,
                                            header={'en': 'CommBugz'},
                                            complete_graph_configs={
                                                chart.chart_id: GraphConfiguration(
                                                    series=[GraphSeries() for c in chart.y_axis_columns],
                                                )
                                                for chart in report.charts
                                            })
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        image_path = 'jr://file/commcare/case_list_image.jpg'
        audio_path = 'jr://file/commcare/case_list_audo.mp3'
        app.get_module(0).media_image.update({'en': image_path})
        app.get_module(0).media_audio.update({'en': audio_path})

        self.assertTrue(app.get_module(0).uses_media())
        self.assertEqual(len(app.all_media()), 2)
Exemplo n.º 2
0
    def test_all_media_report_module(self):
        """
        Report Modules don't support media
        """
        from corehq.apps.userreports.tests import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(report_id=report._id,
                                            header={'en': 'CommBugz'})
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        image_path = 'jr://file/commcare/case_list_image.jpg'
        audo_path = 'jr://file/commcare/case_list_audo.mp3'
        app.get_module(0).case_list_form.media_image = image_path
        app.get_module(0).case_list_form.media_audio = audo_path

        self.assertFalse(app.get_module(0).uses_media())
        self.assertEqual(len(app.all_media), 0)
Exemplo n.º 3
0
    def setUpClass(cls):
        super(AppAwareSyncTests, cls).setUpClass()
        delete_all_users()
        cls.domain_obj = create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain, 'Test App 1')
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {
            'report_id': cls.report_config1.get_id,
            'uuid': '123456'
        }
        module = cls.app1.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, 'Test App 2')
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {
            'report_id': cls.report_config2.get_id,
            'uuid': 'abcdef'
        }
        module = cls.app2.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, 'Test App 3')
        cls.app3.save()
Exemplo n.º 4
0
    def test_all_media_report_module(self):
        """
        Report Modules don't support media
        """
        from corehq.apps.userreports.tests import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(report_id=report._id,
                                            header={'en': 'CommBugz'})
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        image_path = 'jr://file/commcare/case_list_image.jpg'
        audo_path = 'jr://file/commcare/case_list_audo.mp3'
        app.get_module(0).case_list_form.media_image = image_path
        app.get_module(0).case_list_form.media_audio = audo_path

        self.assertFalse(app.get_module(0).uses_media())
        self.assertEqual(len(app.all_media), 0)
Exemplo n.º 5
0
    def test_all_media_report_module(self):
        """
        Report Modules support media
        """
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application")

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(report_id=report._id,
                                            header={'en': 'CommBugz'},
                                            complete_graph_configs={
                                                chart.chart_id: GraphConfiguration(
                                                    series=[GraphSeries() for c in chart.y_axis_columns],
                                                )
                                                for chart in report.charts
                                            })
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        image_path = 'jr://file/commcare/case_list_image.jpg'
        audio_path = 'jr://file/commcare/case_list_audo.mp3'
        app.get_module(0).media_image.update({'en': image_path})
        app.get_module(0).media_audio.update({'en': audio_path})

        self.assertTrue(app.get_module(0).uses_media())
        self.assertEqual(len(app.all_media()), 2)
Exemplo n.º 6
0
    def setUpClass(cls):
        delete_all_users()
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain, "Test App 1")
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {"report_id": cls.report_config1.get_id, "uuid": "123456"}
        module = cls.app1.add_module(ReportModule.new_module("Reports", None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, "Test App 2")
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {"report_id": cls.report_config2.get_id, "uuid": "abcdef"}
        module = cls.app2.add_module(ReportModule.new_module("Reports", None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, "Test App 3")
        cls.app3.save()
Exemplo n.º 7
0
    def setUpClass(cls):
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = CommCareUser.create(cls.domain, 'john_doe', 's3cr3t')

        cls.app1 = Application.new_app(cls.domain, 'Test App 1', application_version=APP_V2)
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.save()
        report_app_config = {
            'report_id': cls.report_config1.get_id,
            'uuid': '123456'
        }
        module = cls.app1.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, 'Test App 2', application_version=APP_V2)
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.save()
        report_app_config = {
            'report_id': cls.report_config2.get_id,
            'uuid': 'abcdef'
        }
        module = cls.app2.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, 'Test App 3', application_version=APP_V2)
        cls.app3.save()
Exemplo n.º 8
0
    def setUpClass(cls):
        delete_all_users()
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain, 'Test App 1')
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {
            'report_id': cls.report_config1.get_id,
            'uuid': '123456'
        }
        module = cls.app1.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, 'Test App 2')
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {
            'report_id': cls.report_config2.get_id,
            'uuid': 'abcdef'
        }
        module = cls.app2.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, 'Test App 3')
        cls.app3.save()
Exemplo n.º 9
0
    def test_all_media_report_module(self):
        """
        Report Modules don't support media
        """
        from corehq.apps.userreports.tests import get_sample_report_config

        app = Application.new_app("domain", "Untitled Application", application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module("Reports", None))
        report_module.unique_id = "report_module"
        report = get_sample_report_config()
        report._id = "d3ff18cd83adf4550b35db8d391f6008"

        report_app_config = ReportAppConfig(report_id=report._id, header={"en": "CommBugz"})
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        image_path = "jr://file/commcare/case_list_image.jpg"
        audio_path = "jr://file/commcare/case_list_audo.mp3"
        app.get_module(0).case_list_form.set_icon("en", image_path)
        app.get_module(0).case_list_form.set_audio("en", audio_path)

        self.assertFalse(app.get_module(0).uses_media())
        self.assertEqual(len(app.all_media), 0)
Exemplo n.º 10
0
 def testImportApp_from_source(self):
     report_module = self.app.add_module(
         ReportModule.new_module('Reports', None))
     report_module.report_configs = [
         ReportAppConfig(report_id='config_id1', header={'en': 'CommBugz'}),
         ReportAppConfig(report_id='config_id2', header={'en': 'CommBugz'})
     ]
     app_source = self.app.export_json(dump_json=False)
     self._test_import_app(app_source)
Exemplo n.º 11
0
 def _make_report_app_config(self, report_slug):
     report = get_sample_report_config()
     report.domain = self.domain
     report.save()
     self.addCleanup(report.delete)
     report_app_config = ReportAppConfig(
         report_id=report._id,
         report_slug=report_slug,
     )
     report_app_config._report = report
     return report_app_config
Exemplo n.º 12
0
    def test_report_module(self):
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(
            report_id=report._id,
            header={'en': 'CommBugz'},
            uuid='ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i',
            description='report description',
        )
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu'),
            app.create_suite(),
            "./menu",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_select_detail'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.select']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_detail'),
            app.create_suite(),
            "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_entry'),
            app.create_suite(),
            "./entry",
        )
        self.assertIn(
            'reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i=CommBugz',
            app.create_app_strings('default'),
        )
Exemplo n.º 13
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'))
Exemplo n.º 14
0
    def test_linked_reports_updated(self):
        # add a report on the master app
        master_data_source = get_sample_data_source()
        master_data_source.domain = self.domain
        master_data_source.save()

        master_report = get_sample_report_config()
        master_report.config_id = master_data_source.get_id
        master_report.domain = self.domain
        master_report.save()

        master_reports_module = self.master1.add_module(
            ReportModule.new_module('Reports', None))
        master_reports_module.report_configs = [
            ReportAppConfig(report_id=master_report.get_id,
                            header={'en': 'CommBugz'}),
        ]

        # link report on master app to linked domain
        link_info = create_linked_ucr(self.domain_link, master_report.get_id)

        updated_app = update_linked_app(self.linked_app, self.master1,
                                        'a-user-id')

        # report config added with the linked report id updated in report config
        self.assertEqual(updated_app.modules[0].report_configs[0].report_id,
                         link_info.report.get_id)
Exemplo n.º 15
0
    def setUpClass(cls):
        super(BaseLinkedAppsTest, cls).setUpClass()
        cls.domain_obj = create_domain('domain')
        cls.domain = cls.domain_obj.name
        cls.master_app_with_report_modules = Application.new_app(
            cls.domain, "Master Application")
        module = cls.master_app_with_report_modules.add_module(
            ReportModule.new_module('Reports', None))
        module.report_configs = [
            ReportAppConfig(report_id='master_report_id',
                            header={'en': 'CommBugz'}),
        ]

        cls.linked_domain_obj = create_domain('domain-2')
        cls.linked_domain = cls.linked_domain_obj.name
        cls.master1 = Application.new_app(cls.domain,
                                          "First Master Application")
        cls.master1.save()

        cls.master2 = Application.new_app(cls.domain,
                                          "Second Master Application")
        cls.master2.save()

        cls.linked_app = LinkedApplication.new_app(cls.linked_domain,
                                                   "Linked Application")
        cls.linked_app.family_id = cls.master1._id
        cls.linked_app.save()

        cls.domain_link = DomainLink.link_domains(cls.linked_domain,
                                                  cls.domain)
Exemplo n.º 16
0
    def test_report_module(self):
        from corehq.apps.userreports.tests import get_sample_report_config

        app = Application.new_app('domain',
                                  "Untitled Application",
                                  application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module(
            'Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(report_id=report._id,
                                            header={'en': 'CommBugz'})
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu'),
            app.create_suite(),
            "./menu",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_select_detail'),
            app.create_suite(),
            "./detail[@id='reports.d3ff18cd83adf4550b35db8d391f6008.select']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail'),
            app.create_suite(),
            "./detail[@id='reports.d3ff18cd83adf4550b35db8d391f6008.summary']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_detail'),
            app.create_suite(),
            "./detail[@id='reports.d3ff18cd83adf4550b35db8d391f6008.data']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_entry'),
            app.create_suite(),
            "./entry",
        )
        self.assertIn(
            'reports.d3ff18cd83adf4550b35db8d391f6008=CommBugz',
            app.create_app_strings('default'),
        )
Exemplo n.º 17
0
    def setUpClass(cls):
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        update_toggle_cache(MOBILE_UCR.slug, cls.domain, True,
                            NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain,
                                                      cls.report_id)
        cls.report_configs_by_id = {cls.report_id: report_configuration}
        cls.app = Application.new_app(cls.domain, "Report Filter Test App",
                                      APP_V2)
        module = cls.app.add_module(
            ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                graph_configs={
                    '7451243209119342931':
                    ReportGraphConfig(series_configs={'count': {}})
                },
                filters={
                    'computed_owner_name_40cc88a0_1': MobileSelectFilter()
                },
                uuid=cls.report_config_uuid,
            ))
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {
                'color_94ec39e6': 'red',
                'count': 2,
                'computed_owner_name_40cc88a0': 'cory'
            },
            {
                'color_94ec39e6': 'black',
                'count': 1,
                'computed_owner_name_40cc88a0': 'ctsims'
            },
            {
                'color_94ec39e6': 'red',
                'count': 3,
                'computed_owner_name_40cc88a0': 'daniel'
            },
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch(
                        'corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                        lambda domain, include_remote: [cls.app]):
                    fixture, = report_fixture_generator(cls.user, '2.0')
        cls.fixture = ElementTree.tostring(fixture)
Exemplo n.º 18
0
 def test_existing_uuid(self):
     existing_uuid = 'existing_uuid'
     self.assertEqual(
         existing_uuid,
         ReportAppConfig.wrap({
             "report_id": "report_id",
             "uuid": existing_uuid,
         }).uuid)
Exemplo n.º 19
0
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        update_toggle_cache(MOBILE_UCR.slug, cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain, cls.report_id)
        cls.report_configs_by_id = {
            cls.report_id: report_configuration
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931': GraphConfiguration(
                        graph_type="bar",
                        series=[GraphSeries(
                            config={},
                            locale_specific_config={},
                            data_path="",
                            x_function="",
                            y_function="",
                        )],
                    )
                },
                filters={
                    'computed_owner_name_40cc88a0_1': MobileSelectFilter(),
                    'fav_fruit_abc123_1': MobileSelectFilter()
                },
                uuid=cls.report_config_uuid,
            )
        )
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {'color_94ec39e6': 'red', 'count': 2, 'computed_owner_name_40cc88a0': 'cory', 'fav_fruit_abc123': 'c'},
            {'color_94ec39e6': 'black', 'count': 1, 'computed_owner_name_40cc88a0': 'ctsims', 'fav_fruit_abc123': 'b'},
            {'color_94ec39e6': 'red', 'count': 3, 'computed_owner_name_40cc88a0': 'daniel', 'fav_fruit_abc123': 'b'},
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch('corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                                lambda domain, include_remote: [cls.app]):
                    with mock_sql_backend():
                        with mock_datasource_config():
                            fixture, = call_fixture_generator(report_fixture_generator, cls.user)
        cls.fixture = ElementTree.tostring(fixture)
Exemplo n.º 20
0
 def test_existing_uuid(self):
     existing_uuid = 'existing_uuid'
     self.assertEqual(
         existing_uuid,
         ReportAppConfig.wrap({
             "report_id": "report_id",
             "uuid": existing_uuid,
         }).uuid
     )
Exemplo n.º 21
0
    def test_purge_report_from_mobile_ucr(self, get_db):
        report_config = ReportConfiguration(domain='domain', config_id='foo1')
        report_config._id = "my_report_config"

        app = Application.new_app('domain', "App")
        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.report_configs = [
            ReportAppConfig(report_id=report_config._id, header={'en': 'CommBugz'}),
            ReportAppConfig(report_id='other_config_id', header={'en': 'CommBugz'})
        ]
        self.assertEqual(len(app.modules[0].report_configs), 2)

        with patch('corehq.apps.app_manager.util.get_apps_in_domain') as get_apps:
            get_apps.return_value = [app]
            # this will get called when report_config is deleted
            purge_report_from_mobile_ucr(report_config)

        self.assertEqual(len(app.modules[0].report_configs), 1)
Exemplo n.º 22
0
 def setUpClass(cls):
     super(BaseLinkedAppsTest, cls).setUpClass()
     cls.master_app_with_report_modules = Application.new_app(
         cls.domain, "Master Application")
     module = cls.master_app_with_report_modules.add_module(
         ReportModule.new_module('Reports', None))
     module.report_configs = [
         ReportAppConfig(report_id='master_report_id',
                         header={'en': 'CommBugz'}),
     ]
 def test_get_config_from_app_report_module(self):
     app = self._get_app()
     report_module = app.add_module(ReportModule.new_module(
         'Reports', None))
     report_module.report_configs = [
         ReportAppConfig(report_id='other_config_id',
                         header={'en': 'CommBugz'})
     ]
     indicators = sorted(list(_get_indicators_used_in_modules(app)))
     self.assertEqual(indicators, [])
Exemplo n.º 24
0
def edit_report_module(request, domain, app_id, module_unique_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)

    try:
        module = app.get_module_by_unique_id(module_unique_id)
    except ModuleNotFoundException:
        # temporary fallback
        module = app.get_module(module_unique_id)

    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [
            ReportAppConfig.wrap(spec) for spec in params['reports']
        ]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={
                'domain': domain,
                'app_id': app_id,
            })
        return HttpResponseBadRequest(
            _("There was a problem processing your request."))

    if app.enable_module_filtering:
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message=
            "Something went wrong while saving app {} while editing report modules"
            .format(app_id),
            details={
                'domain': domain,
                'app_id': app_id,
            })
        return HttpResponseBadRequest(
            _("There was a problem processing your request."))

    get_uuids_by_instance_id.clear(domain)
    return json_response('success')
Exemplo n.º 25
0
 def setUpClass(cls):
     super(TestOverwriteApp, cls).setUpClass()
     cls.master_app = Application.new_app('domain', "Master Application")
     cls.linked_app = Application.new_app('domain-2', "Linked Application")
     module = cls.master_app.add_module(
         ReportModule.new_module('Reports', None))
     module.report_configs = [
         ReportAppConfig(report_id='id', header={'en': 'CommBugz'}),
     ]
     cls.linked_app.save()
     cls.target_json = cls.linked_app.to_json()
Exemplo n.º 26
0
def _new_report_module(request, domain, app, name, lang):
    module = app.add_module(ReportModule.new_module(name, lang))
    # by default add all reports
    module.report_configs = [
        ReportAppConfig(
            report_id=report._id,
            header={lang: report.title},
            description={lang: report.description},
        ) for report in ReportConfiguration.by_domain(domain)
    ]
    app.save()
    return back_to_main(request, domain, app_id=app.id, module_id=module.id)
Exemplo n.º 27
0
def edit_report_module(request, domain, app_id, module_unique_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)

    try:
        module = app.get_module_by_unique_id(module_unique_id)
    except ModuleNotFoundException:
        # temporary fallback
        module = app.get_module(module_unique_id)

    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    if app.enable_module_filtering:
        module['module_filter'] = request.POST.get('module_filter')

    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    if 'name_enum' in params:
        name_enum = json.loads(request.POST.get("name_enum"))
        module.name_enum = [MappingItem(i) for i in name_enum]

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while saving app {} while editing report modules".format(app_id),
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    get_uuids_by_instance_id.clear(domain)
    return json_response('success')
Exemplo n.º 28
0
    def setUpClass(cls):
        super(BaseLinkedAppsTest, cls).setUpClass()
        cls.master_app_with_report_modules = Application.new_app('domain', "Master Application")
        module = cls.master_app_with_report_modules.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [
            ReportAppConfig(report_id='id', header={'en': 'CommBugz'}),
        ]

        cls.plain_master_app = Application.new_app('domain', "Master Application")
        cls.plain_master_app.linked_whitelist = ['domain-2']
        cls.plain_master_app.save()

        cls.linked_app = LinkedApplication.new_app('domain-2', "Linked Application")
        cls.linked_app.save()
Exemplo n.º 29
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']
    module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    app.save()
    return json_response('success')
Exemplo n.º 30
0
    def _create_report_and_datasource(self):
        master_data_source = get_sample_data_source()
        master_data_source.domain = self.domain
        master_data_source.save()

        master_report = get_sample_report_config()
        master_report.config_id = master_data_source.get_id
        master_report.domain = self.domain
        master_report.save()

        master_reports_module = self.master1.add_module(
            ReportModule.new_module('Reports', None))
        master_reports_module.report_configs = [
            ReportAppConfig(report_id=master_report.get_id,
                            header={'en': 'CommBugz'}),
        ]
        return master_report, master_data_source
Exemplo n.º 31
0
    def test_get_report_fixture_for_user(self):
        from corehq.apps.userreports.reports.data_source import ConfigurableReportDataSource
        from corehq.apps.userreports.tests.utils import mock_datasource_config
        from corehq.apps.app_manager.models import ReportAppConfig

        app_report_config = ReportAppConfig.wrap({
            'report_id': self.report_config1.get_id,
            'uuid': 'abcdef'
        })
        with mock.patch.object(ConfigurableReportDataSource, 'get_data') as get_data_mock, \
            mock.patch('custom.icds.messaging.indicators.get_report_configs') as get_report_configs:
            get_report_configs.return_value = {'test_id': app_report_config}
            get_data_mock.return_value = [{'owner': 'bob', 'count': 3, 'is_starred': True}]

            with mock_datasource_config():
                fixture = _get_report_fixture_for_user(self.domain, 'test_id', self.user).decode('utf8')
                self.assertIn(self.report_config1.get_id, fixture)
Exemplo n.º 32
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}))
Exemplo n.º 33
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']
    module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    if (feature_previews.MODULE_FILTER.enabled(domain) and
            app.enable_module_filtering):
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])
    app.save()
    return json_response('success')
Exemplo n.º 34
0
    def test_report_fixtures_provider(self):
        report_id = 'deadbeef'
        provider = ReportFixturesProvider()
        report_app_config = ReportAppConfig(
            uuid='c0ffee',
            report_id=report_id,
            filters={'computed_owner_name_40cc88a0_1': StaticChoiceListFilter()}
        )
        user = Mock()

        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:

            report_factory_patch.from_spec.return_value = self.get_data_source_mock()
            report = provider.report_config_to_fixture(report_app_config, user)
            self.assertEqual(
                etree.tostring(report, pretty_print=True),
                self.get_xml('expected_report')
            )
Exemplo n.º 35
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    if (feature_previews.MODULE_FILTER.enabled(domain) and
            app.enable_module_filtering):
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while saving app {} while editing report modules".format(app_id),
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    return json_response('success')
Exemplo n.º 36
0
    def setUpClass(cls):
        super(BaseLinkedAppsTest, cls).setUpClass()
        cls.domain = 'domain'
        cls.master_app_with_report_modules = Application.new_app(
            cls.domain, "Master Application")
        module = cls.master_app_with_report_modules.add_module(
            ReportModule.new_module('Reports', None))
        module.report_configs = [
            ReportAppConfig(report_id='master_report_id',
                            header={'en': 'CommBugz'}),
        ]

        cls.master1 = Application.new_app(cls.domain, "Master Application")
        cls.linked_domain = 'domain-2'
        cls.master1.linked_whitelist = [cls.linked_domain]
        cls.master1.save()

        cls.linked_app = LinkedApplication.new_app(cls.linked_domain,
                                                   "Linked Application")
        cls.linked_app.save()

        cls.domain_link = DomainLink.link_domains(cls.linked_domain,
                                                  cls.domain)
    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'))
Exemplo n.º 38
0
 def test_different_uuids(self):
     report_app_config_1 = ReportAppConfig(report_id='report_id')
     report_app_config_2 = ReportAppConfig(report_id='report_id')
     self.assertNotEqual(report_app_config_1.uuid, report_app_config_2.uuid)
Exemplo n.º 39
0
    def test_report_module(self):
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(
            report_id=report._id,
            header={'en': 'CommBugz'},
            uuid='ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i',
            xpath_description='"report description"',
            use_xpath_description=True
        )
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu'),
            app.create_suite(),
            "./menu",
        )

        app.multimedia_map = {
            "jr://file/commcare/image/module0_en.png": HQMediaMapItem(
                multimedia_id='bb4472b4b3c702f81c0b208357eb22f8',
                media_type='CommCareImage',
                unique_id='fe06454697634053cdb75fd9705ac7e6',
            ),
        }
        report_module.media_image = {
            'en': 'jr://file/commcare/image/module0_en.png',
        }
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu_multimedia'),
            app.create_suite(),
            "./menu",
        )

        self.assertXmlPartialEqual(
            self.get_xml('reports_module_select_detail'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.select']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail_use_xpath_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_detail'),
            app.create_suite(),
            "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_entry'),
            app.create_suite(),
            "./entry",
        )
        self.assertIn(
            'reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i=CommBugz',
            app.create_app_strings('default'),
        )

        report_app_config.use_xpath_description = False
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail_use_localized_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )
Exemplo n.º 40
0
 def test_new_uuid(self):
     report_app_config = ReportAppConfig(report_id='report_id')
     self.assertTrue(report_app_config.uuid)
     self.assertIsInstance(report_app_config.uuid, basestring)
Exemplo n.º 41
0
    def test_report_module(self):
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application")

        report_module = app.add_module(ReportModule.new_module('Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(
            report_id=report._id,
            header={'en': 'CommBugz'},
            uuid='ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i',
            xpath_description='"report description"',
            use_xpath_description=True
        )
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu'),
            app.create_suite(),
            "./menu",
        )

        app.multimedia_map = {
            "jr://file/commcare/image/module0_en.png": HQMediaMapItem(
                multimedia_id='bb4472b4b3c702f81c0b208357eb22f8',
                media_type='CommCareImage',
                unique_id='fe06454697634053cdb75fd9705ac7e6',
            ),
        }
        report_module.media_image = {
            'en': 'jr://file/commcare/image/module0_en.png',
        }
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu_multimedia'),
            app.create_suite(),
            "./menu",
        )

        self.assertXmlPartialEqual(
            self.get_xml('reports_module_select_detail'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.select']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail_use_xpath_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_detail'),
            app.create_suite(),
            "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_entry'),
            app.create_suite(),
            "./entry",
        )
        self.assertIn(
            'reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i=CommBugz',
            app.create_app_strings('default'),
        )

        report_app_config.use_xpath_description = False
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_summary_detail_use_localized_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )

        # Tuple mapping translation formats to the expected output of each
        translation_formats = [
            ({
                u'एक': {
                    'en': 'one',
                    'es': 'uno',
                },
                '2': {
                    'en': 'two',
                    'es': 'dos\'',
                    'hin': u'दो',
                },
            }, 'reports_module_data_detail-translated'),
            ({
                u'एक': 'one',
                '2': 'two',
            }, 'reports_module_data_detail-translated-simple'),
            ({
                u'एक': {
                    'en': 'one',
                    'es': 'uno',
                },
                '2': 'two',
            }, 'reports_module_data_detail-translated-mixed'),
        ]
        for translation_format, expected_output in translation_formats:
            report_app_config._report.columns[0]['transform'] = {
                'type': 'translation',
                'translations': translation_format,
            }
            report_app_config._report = ReportConfiguration.wrap(report_app_config._report._doc)
            self.assertXmlPartialEqual(
                self.get_xml(expected_output),
                app.create_suite(),
                "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
            )
Exemplo n.º 42
0
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_mobile_id = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        create_domain(cls.domain)
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        MOBILE_UCR.set(cls.domain, True, NAMESPACE_DOMAIN)
        ADD_ROW_INDEX_TO_MOBILE_UCRS.set(cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain, cls.report_id)

        # also make a report with a hidden column
        cls.hidden_column_report_id = 'bd2a43018ad9463682165c1bc16347ac'
        cls.hidden_column_mobile_id = '45152061d8dc4d2a8d987a0568abe1ae'
        report_configuration_with_hidden_column = MAKE_REPORT_CONFIG(
            cls.domain,
            cls.hidden_column_report_id,
            columns=[
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="color_94ec39e6",
                    display="color",
                    field="color_94ec39e6"
                ).to_json(),
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="hidden_color_94ec39e6",
                    display="color",
                    field="color_94ec39e6",
                    visible=False,
                ).to_json(),
            ]
        )
        cls.report_configs_by_id = {
            cls.report_id: report_configuration,
            cls.hidden_column_report_id: report_configuration_with_hidden_column
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        report_module = cls.app.add_module(ReportModule.new_module("Report Module", 'en'))
        report_module.report_context_tile = True
        report_module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931': GraphConfiguration(
                        graph_type="bar",
                        series=[GraphSeries(
                            config={},
                            locale_specific_config={},
                            data_path="",
                            x_function="",
                            y_function="",
                        )],
                    )
                },
                filters=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('computed_owner_name_40cc88a0_1', MobileSelectFilter()),
                ]),
                uuid=cls.report_config_mobile_id,
            )
        )
        report_module.report_configs.append(
            ReportAppConfig(
                report_id=cls.hidden_column_report_id,
                header={},
                description="",
                complete_graph_configs={},
                filters={},
                uuid=cls.hidden_column_mobile_id,
            )
        )

        case_module = cls.app.add_module(Module.new_module("Case Module", 'en'))
        case_module.case_type = "fish"
        case_module.report_context_tile = True
        case_form = case_module.new_form("Update Fish", None)
        case_form.requires = "case"
        case_form.xmlns = "http://openrosa.org/formdesigner/2423EFB5-2E8C-4B8F-9DA0-23FFFD4391AF"

        survey_module = cls.app.add_module(Module.new_module("Survey Module", 'en'))
        survey_module.report_context_tile = True
        survey_form = survey_module.new_form("Survey", None)
        survey_form.xmlns = "http://openrosa.org/formdesigner/2423EFB5-2E8C-4B8F-9DA0-23FFFD4391AE"

        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {'color_94ec39e6': 'red', 'count': 2, 'computed_owner_name_40cc88a0': 'cory', 'fav_fruit_abc123': 'c'},
            {'color_94ec39e6': 'black', 'count': 1, 'computed_owner_name_40cc88a0': 'ctsims', 'fav_fruit_abc123': 'b'},
            {'color_94ec39e6': 'red', 'count': 3, 'computed_owner_name_40cc88a0': 'daniel', 'fav_fruit_abc123': 'b'},
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch('corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                                lambda domain, include_remote: [cls.app]):
                    with mock_datasource_config():
                        fixtures = call_fixture_generator(report_fixture_generator, cls.user)
                        fixture = [f for f in fixtures if f.attrib.get('id') == ReportFixturesProviderV1.id][0]
        cls.fixture = ElementTree.tostring(fixture, encoding='utf-8')
Exemplo n.º 43
0
    def test_report_module(self):
        from corehq.apps.userreports.tests.utils import get_sample_report_config

        app = Application.new_app('domain', "Untitled Application")

        report_module = app.add_module(ReportModule.new_module(
            'Reports', None))
        report_module.unique_id = 'report_module'
        report = get_sample_report_config()
        report._id = 'd3ff18cd83adf4550b35db8d391f6008'

        report_app_config = ReportAppConfig(
            report_id=report._id,
            header={'en': 'CommBugz'},
            uuid='ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i',
            xpath_description='"report description"',
            use_xpath_description=True)
        report_app_config._report = report
        report_module.report_configs = [report_app_config]
        report_module._loaded = True
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu'),
            app.create_suite(),
            "./menu",
        )

        app.multimedia_map = {
            "jr://file/commcare/image/module0_en.png":
            HQMediaMapItem(
                multimedia_id='bb4472b4b3c702f81c0b208357eb22f8',
                media_type='CommCareImage',
                unique_id='fe06454697634053cdb75fd9705ac7e6',
            ),
        }
        report_module.media_image = {
            'en': 'jr://file/commcare/image/module0_en.png',
        }
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_menu_multimedia'),
            app.create_suite(),
            "./menu",
        )

        self.assertXmlPartialEqual(
            self.get_xml('reports_module_select_detail'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.select']",
        )
        self.assertXmlPartialEqual(
            self.get_xml(
                'reports_module_summary_detail_use_xpath_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_detail'),
            app.create_suite(),
            "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
        )
        self.assertXmlPartialEqual(
            self.get_xml('reports_module_data_entry'),
            app.create_suite(),
            "./entry",
        )
        self.assertIn(
            'reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i=CommBugz',
            app.create_app_strings('default'),
        )

        report_app_config.use_xpath_description = False
        self.assertXmlPartialEqual(
            self.get_xml(
                'reports_module_summary_detail_use_localized_description'),
            app.create_suite(),
            "./detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.summary']",
        )

        # Tuple mapping translation formats to the expected output of each
        translation_formats = [
            ({
                u'एक': {
                    'en': 'one',
                    'es': 'uno',
                },
                '2': {
                    'en': 'two',
                    'es': 'dos\'',
                    'hin': u'दो',
                },
            }, 'reports_module_data_detail-translated'),
            ({
                u'एक': 'one',
                '2': 'two',
            }, 'reports_module_data_detail-translated-simple'),
            ({
                u'एक': {
                    'en': 'one',
                    'es': 'uno',
                },
                '2': 'two',
            }, 'reports_module_data_detail-translated-mixed'),
        ]
        for translation_format, expected_output in translation_formats:
            report_app_config._report.columns[0]['transform'] = {
                'type': 'translation',
                'translations': translation_format,
            }
            report_app_config._report = ReportConfiguration.wrap(
                report_app_config._report._doc)
            self.assertXmlPartialEqual(
                self.get_xml(expected_output),
                app.create_suite(),
                "./detail/detail[@id='reports.ip1bjs8xtaejnhfrbzj2r6v1fi6hia4i.data']",
            )
Exemplo n.º 44
0
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_mobile_id = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        create_domain(cls.domain)
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        MOBILE_UCR.set(cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain,
                                                      cls.report_id)

        # also make a report with a hidden column
        cls.hidden_column_report_id = 'bd2a43018ad9463682165c1bc16347ac'
        cls.hidden_column_mobile_id = '45152061d8dc4d2a8d987a0568abe1ae'
        report_configuration_with_hidden_column = MAKE_REPORT_CONFIG(
            cls.domain,
            cls.hidden_column_report_id,
            columns=[
                FieldColumn(type='field',
                            aggregation="simple",
                            column_id="color_94ec39e6",
                            display="color",
                            field="color_94ec39e6").to_json(),
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="hidden_color_94ec39e6",
                    display="color",
                    field="color_94ec39e6",
                    visible=False,
                ).to_json(),
            ])
        cls.report_configs_by_id = {
            cls.report_id: report_configuration,
            cls.hidden_column_report_id:
            report_configuration_with_hidden_column
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(
            ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931':
                    GraphConfiguration(
                        graph_type="bar",
                        series=[
                            GraphSeries(
                                config={},
                                locale_specific_config={},
                                data_path="",
                                x_function="",
                                y_function="",
                            )
                        ],
                    )
                },
                filters=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('computed_owner_name_40cc88a0_1', MobileSelectFilter()),
                ]),
                uuid=cls.report_config_mobile_id,
            ))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.hidden_column_report_id,
                header={},
                description="",
                complete_graph_configs={},
                filters={},
                uuid=cls.hidden_column_mobile_id,
            ))
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {
                'color_94ec39e6': 'red',
                'count': 2,
                'computed_owner_name_40cc88a0': 'cory',
                'fav_fruit_abc123': 'c'
            },
            {
                'color_94ec39e6': 'black',
                'count': 1,
                'computed_owner_name_40cc88a0': 'ctsims',
                'fav_fruit_abc123': 'b'
            },
            {
                'color_94ec39e6': 'red',
                'count': 3,
                'computed_owner_name_40cc88a0': 'daniel',
                'fav_fruit_abc123': 'b'
            },
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch(
                        'corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                        lambda domain, include_remote: [cls.app]):
                    with mock_datasource_config():
                        fixture, = call_fixture_generator(
                            report_fixture_generator, cls.user)
        cls.fixture = ElementTree.tostring(fixture)