Beispiel #1
0
    def setUp(self):
        self.factory = AppFactory(domain=DOMAIN)
        self.app_id = uuid4().hex
        self.factory.app._id = self.app_id
        module, form = self.factory.new_basic_module('basic', 'tree')
        self.factory.form_requires_case(form, 'tree')
        child_module, child_form = self.factory.new_basic_module('child', 'leaf', parent_module=module)
        self.factory.form_requires_case(child_form, 'leaf')

        child_module.search_config = CaseSearch(
            search_label=CaseSearchLabel(label={'en': 'Search'}),
            properties=[CaseSearchProperty(name=field) for field in ['name', 'shape']],
            data_registry="a_registry",
            data_registry_workflow=REGISTRY_WORKFLOW_SMART_LINK,
        )
        child_module.assign_references()

        child_module.session_endpoint_id = "child_endpoint"
        child_module.parent_select.active = True
        child_module.parent_select.module_id = module.unique_id

        generator = SuiteGenerator(self.factory.app)
        detail_section_elements = generator.add_section(DetailContributor)
        entries = EntriesContributor(generator.suite, self.factory.app, self.factory.app.modules)
        generator.suite.entries.extend(entries.get_module_contributions(child_module))
        self.request_factory = RemoteRequestFactory(generator.suite, child_module, detail_section_elements)
Beispiel #2
0
    def test_case_search_action(self, *args):
        """
        Case search action should be added to case list and a new search detail should be created
        """
        # Regular and advanced modules should get the search detail
        search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={
                    'en': 'Advanced Search'
                }
            ),
            search_again_label=CaseSearchAgainLabel(
                label={
                    'en': 'Search One More Time'
                }
            ),
            properties=[CaseSearchProperty(name='name', label={'en': 'Name'})]
        )
        advanced_module = self.app.add_module(AdvancedModule.new_module("advanced", None))
        advanced_module.search_config = search_config

        # Modules with custom xml should not get the search detail
        module_custom = self.app.add_module(Module.new_module("custom_xml", None))
        module_custom.search_config = search_config
        module_custom.case_details.short.custom_xml = "<detail id='m2_case_short'></detail>"
        advanced_module_custom = self.app.add_module(AdvancedModule.new_module("advanced with custom_xml", None))
        advanced_module_custom.search_config = search_config
        advanced_module_custom.case_details.short.custom_xml = "<detail id='m3_case_short'></detail>"

        # wrap to have assign_references called
        self.app = Application.wrap(self.app.to_json())

        suite = self.app.create_suite()
        self.assertXmlPartialEqual(self.get_xml('search_command_detail'), suite, "./detail")
Beispiel #3
0
    def setUp(self):
        self.factory = AppFactory(domain="multiple-referrals")
        self.app_id = uuid4().hex
        self.factory.app._id = self.app_id
        self.module, self.form = self.factory.new_basic_module(
            'basic', 'person')
        self.factory.form_requires_case(self.form, 'person')
        self.form.xmlns = "some-xmlns"

        self.module.case_details.short.multi_select = True
        self.module.search_config = CaseSearch(
            search_label=CaseSearchLabel(label={'en': 'Search'}),
            properties=[
                CaseSearchProperty(name=field)
                for field in ['name', 'greatest_fear']
            ],
        )
        self.module.assign_references()
Beispiel #4
0
    def test_case_search_action(self):
        app = Application.wrap(self.get_json('suite-advanced'))
        app.modules[0].search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={'en': 'Get them'},
                media_image={'en': "jr://file/commcare/image/1.png"},
                media_audio={'en': "jr://file/commcare/image/2.mp3"}
            ),
            search_again_label=CaseSearchAgainLabel(
                label={'en': 'Get them'},
                media_audio={'en': "jr://file/commcare/image/2.mp3"}
            ),
            properties=[CaseSearchProperty(name='name', label={'en': 'Name'})],
        )
        # wrap to have assign_references called
        app = Application.wrap(app.to_json())

        # test for legacy action node for older versions
        self.assertXmlPartialEqual(
            self.get_xml('case-search-with-action'),
            app.create_suite(),
            "./detail[@id='m0_case_short']/action"
        )
        self.assertXmlPartialEqual(
            self.get_xml('case-search-again-with-action'),
            app.create_suite(),
            "./detail[@id='m0_search_short']/action"
        )

        # test for localized action node for apps with CC version > 2.21
        app.build_spec.version = '2.21.0'
        self.assertXmlPartialEqual(
            self.get_xml('case-search-with-localized-action'),
            app.create_suite(),
            "./detail[@id='m0_case_short']/action"
        )
        self.assertXmlPartialEqual(
            self.get_xml('case-search-again-with-localized-action'),
            app.create_suite(),
            "./detail[@id='m0_search_short']/action"
        )
Beispiel #5
0
    def setUp(self):
        self.all_attrs = [
            'search_properties', 'search_default_properties',
            'search_claim_options'
        ]

        self.app = Application.new_app('domain', "Untitled Application")
        self.src_module = self.app.add_module(
            Module.new_module('Src Module', lang='en'))
        self.case_search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={'en': 'Search Patients Nationally'}),
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='dob', label={'en': 'Date of birth'})
            ],
            auto_launch=True,
            default_search=True,
            additional_relevant="instance('groups')/groups/group",
            search_filter=
            "name = instance('item-list:trees')/trees_list/trees[favorite='yes']/name",
            search_button_display_condition="false()",
            blacklisted_owner_ids_expression=
            "instance('commcaresession')/session/context/userid",
            default_properties=[
                DefaultCaseSearchProperty(
                    property='ɨŧsȺŧɍȺᵽ',
                    defaultValue=
                    ("instance('casedb')/case"
                     "[@case_id='instance('commcaresession')/session/data/case_id']/ɨŧsȺŧɍȺᵽ"
                     )),
                DefaultCaseSearchProperty(
                    property='name',
                    defaultValue=
                    "instance('locations')/locations/location[@id=123]/@type"),
            ],
        )
        self.src_module.search_config = self.case_search_config
        self.dest_module = self.app.add_module(
            Module.new_module('Dest Module', lang='en'))
Beispiel #6
0
 def test_additional_types__shadow_module(self, *args):
     shadow_module = self.app.add_module(ShadowModule.new_module("shadow", "en"))
     shadow_module.source_module_id = self.module.get_or_create_unique_id()
     shadow_module.search_config = CaseSearch(
         search_label=CaseSearchLabel(
             label={
                 'en': 'Search from Shadow Module'
             }
         ),
         properties=[
             CaseSearchProperty(name='name', label={'en': 'Name'}),
         ],
     )
     another_case_type = "another_case_type"
     self.module.search_config.additional_case_types = [another_case_type]
     app = Application.wrap(self.app.to_json())
     suite_xml = app.create_suite()
     suite = parse_normalize(suite_xml, to_string=False)
     ref_path = './remote-request[2]/session/datum/@nodeset'
     self.assertEqual(
         "instance('{}')/{}/case[@case_type='{}' or @case_type='{}']{}".format(
             RESULTS_INSTANCE,
             RESULTS_INSTANCE,
             self.module.case_type,
             another_case_type,
             EXCLUDE_RELATED_CASES_FILTER
         ),
         suite.xpath(ref_path)[0]
     )
     self.assertXmlPartialEqual(
         """
         <partial>
           <data key="case_type" ref="'case'"/>
           <data key="case_type" ref="'another_case_type'"/>
         </partial>
         """,
         suite_xml,
         "./remote-request[2]/session/query/data[@key='case_type']"
     )
Beispiel #7
0
    def test_multi_select_module_errors(self, *args):
        factory = AppFactory()
        module, form = factory.new_basic_module('basic', 'person')
        factory.form_requires_case(form, 'person')

        module.case_details.short.multi_select = True
        module.search_config = CaseSearch(
            search_label=CaseSearchLabel(label={'en': 'Search'}),
            properties=[CaseSearchProperty(name=field) for field in ['name', 'greatest_fear']],
            data_registry="so_many_cases",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
        )

        self.assertIn({
            'type': 'data registry multi select',
            'module': {'id': 0, 'unique_id': 'basic_module', 'name': {'en': 'basic module'}}
        }, factory.app.validate_app())

        module.search_config.data_registry_workflow = REGISTRY_WORKFLOW_SMART_LINK
        self.assertIn({
            'type': 'smart links multi select',
            'module': {'id': 0, 'unique_id': 'basic_module', 'name': {'en': 'basic module'}}
        }, factory.app.validate_app())
Beispiel #8
0
    def test_modules_case_search_app_strings(self):
        factory = AppFactory(build_version='2.40.0')
        factory.app.langs = ['en', 'es']
        factory.app.build_profiles = OrderedDict({
            'en':
            BuildProfile(langs=['en'], name='en-profile'),
            'es':
            BuildProfile(langs=['es'], name='es-profile'),
        })
        module, form = factory.new_basic_module('my_module', 'cases')
        module.search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={
                    'en': 'Get them',
                    'es': 'Conseguirlos'
                },
                media_image={
                    'en': "jr://file/commcare/image/1.png",
                    'es': "jr://file/commcare/image/1_es.png"
                },
                media_audio={'en': "jr://file/commcare/image/2.mp3"}),
            search_again_label=CaseSearchAgainLabel(
                label={'en': 'Get them all'}),
            properties=[CaseSearchProperty(name="name", label={'en': 'Name'})])
        # wrap to have assign_references called
        app = Application.wrap(factory.app.to_json())

        with flag_disabled('USH_CASE_CLAIM_UPDATES'):
            # default language
            self.assertEqual(app.default_language, 'en')
            en_app_strings = self._generate_app_strings(app,
                                                        'default',
                                                        build_profile_id='en')
            self.assertEqual(en_app_strings['case_search.m0'],
                             'Search All Cases')
            self.assertEqual(en_app_strings['case_search.m0.again'],
                             'Search Again')
            self.assertFalse('case_search.m0.icon' in en_app_strings)
            self.assertFalse('case_search.m0.audio' in en_app_strings)

            # non-default language
            es_app_strings = self._generate_app_strings(app,
                                                        'es',
                                                        build_profile_id='es')
            self.assertEqual(es_app_strings['case_search.m0'],
                             'Search All Cases')
            self.assertEqual(es_app_strings['case_search.m0.again'],
                             'Search Again')

        with flag_enabled('USH_CASE_CLAIM_UPDATES'):
            # default language
            en_app_strings = self._generate_app_strings(app,
                                                        'default',
                                                        build_profile_id='en')
            self.assertEqual(en_app_strings['case_search.m0'], 'Get them')
            self.assertEqual(en_app_strings['case_search.m0.icon'],
                             'jr://file/commcare/image/1.png')
            self.assertEqual(en_app_strings['case_search.m0.audio'],
                             'jr://file/commcare/image/2.mp3')
            self.assertEqual(en_app_strings['case_search.m0.again'],
                             'Get them all')

            # non-default language
            es_app_strings = self._generate_app_strings(app,
                                                        'es',
                                                        build_profile_id='es')
            self.assertEqual(es_app_strings['case_search.m0'], 'Conseguirlos')
            self.assertEqual(es_app_strings['case_search.m0.icon'],
                             'jr://file/commcare/image/1_es.png')
            self.assertEqual(es_app_strings['case_search.m0.again'],
                             'Get them all')
Beispiel #9
0
    def setUp(self):
        self.app = Application.new_app(DOMAIN, "Untitled Application")
        self.app._id = '123'
        self.app.build_spec = BuildSpec(version='2.35.0', build_number=1)
        self.module = self.app.add_module(Module.new_module("Untitled Module", None))
        self.form = self.app.new_form(0, "Untitled Form", None)
        self.form.requires = 'case'
        self.module.case_type = 'case'

        # chosen xpath just used to reference more instances - not considered valid to use in apps
        self.module.case_details.short.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "report_name"},
                model="case",
                format="calculate",
                field="whatever",
                calc_xpath="instance('reports')/report[1]/name",
            ))
        )
        self.module.case_details.short.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "moon"},
                model="case",
                format="calculate",
                field="whatever",
                calc_xpath="instance('item-list:moons')/moons_list/moons[favorite='yes']/name",
            ))
        )
        self.module.case_details.short.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "Parent's Whatever"},
                model="case",
                format="plain",
                field="parent/whatever",
            ))
        )
        self.module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "ledger_name"},
                model="case",
                format="calculate",
                field="whatever",
                calc_xpath="instance('ledgerdb')/ledgers/name/name",
            ))
        )
        self.module.search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={
                    'en': 'Search Patients Nationally'
                }
            ),
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='dob', label={'en': 'Date of birth'})
            ],
            additional_relevant="instance('groups')/groups/group",
            search_filter="name = instance('item-list:trees')/trees_list/trees[favorite='yes']/name",
            default_properties=[
                DefaultCaseSearchProperty(
                    property='ɨŧsȺŧɍȺᵽ',
                    defaultValue=(
                        "instance('casedb')/case"
                        "[@case_id='instance('commcaresession')/session/data/case_id']"
                        "/ɨŧsȺŧɍȺᵽ")
                ),
                DefaultCaseSearchProperty(
                    property='name',
                    defaultValue="instance('locations')/locations/location[@id=123]/@type",
                ),
            ],
        )

        # wrap to have assign_references called
        self.app = Application.wrap(self.app.to_json())
        # reset to newly wrapped module
        self.module = self.app.modules[0]