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()
    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()
    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()
Beispiel #4
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()
    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)
Beispiel #6
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)
Beispiel #7
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)
    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)
Beispiel #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'
        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)
Beispiel #10
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)
    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)
Beispiel #12
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)
Beispiel #13
0
 def test_report_module(self):
     module = self.app.add_module(ReportModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(['view_module'], {
         'domain': self.domain.name,
         'app_id': self.app.id,
         'module_id': module.id,
     })
 def test_report_module(self, mockh):
     module = self.app.add_module(ReportModule.new_module("Module0", "en"))
     self.app.save()
     self._test_status_codes(['view_module'], {
         'domain': self.project.name,
         'app_id': self.app.id,
         'module_unique_id': module.unique_id,
     })
Beispiel #15
0
 def testImportApp_from_source(self, mock, report_mock):
     report_mock.return_value = get_sample_report_config()
     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)
Beispiel #16
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)
Beispiel #17
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)
    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='******',
        )
        MOBILE_UCR.set(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=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('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', '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)
 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, [])
Beispiel #20
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, [])
Beispiel #22
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()
Beispiel #23
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)
Beispiel #24
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=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)
Beispiel #25
0
    def test_report_module_uuid_updates(self):
        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_app_config = ReportAppConfig(report_id="123", header={"en": "CommBugz"})
        report_module.report_configs = [report_app_config]
        report_module._loaded = True

        app_source = app.export_json(dump_json=False)
        new_uuid = app_source["modules"][0]["report_configs"][0]["uuid"]
        self.assertNotEqual(report_app_config.uuid, new_uuid)
    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()
Beispiel #27
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'),
        )
Beispiel #28
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'),
        )
Beispiel #29
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")
        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]):
                    with mock_sql_backend():
                        with mock_datasource_config():
                            fixture, = report_fixture_generator(cls.user, '2.0')
        cls.fixture = ElementTree.tostring(fixture)
Beispiel #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
Beispiel #31
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)
Beispiel #32
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)
Beispiel #33
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.plain_master_app = Application.new_app(cls.domain, "Master Application")
        cls.linked_domain = 'domain-2'
        cls.plain_master_app.linked_whitelist = [cls.linked_domain]
        cls.plain_master_app.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)
Beispiel #34
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 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)
    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']",
            )
 def _add_report_module(self, app, report_app_config):
     report_module = app.add_module(ReportModule.new_module('Reports', None))
     report_module.report_configs = [report_app_config]
     app.save()
     return report_module
    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')
Beispiel #39
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)
Beispiel #40
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']",
        )
Beispiel #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']",
            )