示例#1
0
def MAKE_REPORT_CONFIG(domain, report_id, columns=None):
    columns = columns or [
        FieldColumn(type='field',
                    aggregation="simple",
                    column_id="color_94ec39e6",
                    display="color",
                    field="color_94ec39e6").to_json(),
    ]
    return ReportConfiguration(
        _id=report_id,
        title="Entry Report",
        aggregation_columns=["color_94ec39e6"],
        config_id="516c494736e95b023cc7845b557de0f5",
        domain=domain,
        report_meta=ReportMeta(builder_report_type="chart",
                               created_by_builder=True),
        columns=columns,
        configured_charts=[
            MultibarChartSpec(type='multibar',
                              chart_id="7451243209119342931",
                              x_axis_column="color_94ec39e6",
                              y_axis_columns=[
                                  GraphDisplayColumn(column_id="count",
                                                     display="count")
                              ]).to_json()
        ],
        filters=[
            DynamicChoiceListFilterSpec(
                type='dynamic_choice_list',
                display="owner name",
                field="computed_owner_name_40cc88a0",
                slug="computed_owner_name_40cc88a0_1").to_json(),
            ChoiceListFilterSpec(type='choice_list',
                                 display="fav color",
                                 field="fav_fruit_abc123",
                                 slug="fav_fruit_abc123_1",
                                 choices=[
                                     FilterChoice(value='a', display='apple'),
                                     FilterChoice(value='b', display='banana'),
                                     FilterChoice(value='c',
                                                  display='clementine'),
                                 ]).to_json()
        ],
    )
示例#2
0
                "uuid": existing_uuid,
            }).uuid)


MAKE_REPORT_CONFIG = lambda domain, report_id: ReportConfiguration(
    _id=report_id,
    title="Entry Report",
    aggregation_columns=["color_94ec39e6"],
    config_id="516c494736e95b023cc7845b557de0f5",
    domain=domain,
    report_meta=ReportMeta(builder_report_type="chart",
                           created_by_builder=True),
    columns=[
        FieldColumn(type='field',
                    aggregation="simple",
                    column_id="color_94ec39e6",
                    display="color",
                    field="color_94ec39e6").to_json(),
    ],
    configured_charts=[
        MultibarChartSpec(type='multibar',
                          chart_id="7451243209119342931",
                          x_axis_column="color_94ec39e6",
                          y_axis_columns=[
                              GraphDisplayColumn(column_id="count",
                                                 display="count")
                          ]).to_json()
    ],
    filters=[
        DynamicChoiceListFilterSpec(type='dynamic_choice_list',
                                    display="owner name",
示例#3
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')
示例#4
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)