def test_search_config_relevant(self, *args): config = CaseSearch() self.assertEqual(config.get_relevant(), "count(instance('casedb')/casedb/case[@case_id=instance('commcaresession')/session/data/search_case_id]) = 0") # noqa: E501 config.additional_relevant = "double(now()) mod 2 = 0" self.assertEqual(config.get_relevant(), "(count(instance('casedb')/casedb/case[@case_id=instance('commcaresession')/session/data/search_case_id]) = 0) and (double(now()) mod 2 = 0)") # noqa: E501
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)
def test_search_config_relevant_multi_select(self, *args): config = CaseSearch() self.assertEqual(config.get_relevant(multi_select=True), "$case_id != ''") config.additional_relevant = "double(now()) mod 2 = 0" self.assertEqual(config.get_relevant(multi_select=True), "($case_id != '') and (double(now()) mod 2 = 0)")
def setUp(self): factory = AppFactory(DOMAIN, "App with DR and child modules", build_version='2.53.0') m0, f0 = factory.new_basic_module("case list", "case") factory.form_requires_case(f0) m1, f1 = factory.new_basic_module("child case list", "case", parent_module=m0) m1.parent_select = ParentSelect(active=True, relationship="other", module_id=m0.get_or_create_unique_id()) f2 = factory.new_form(m1) factory.form_requires_case(f1) factory.form_requires_case(f2) m1.search_config = CaseSearch( properties=[CaseSearchProperty(name='name', label={'en': 'Name'})], data_registry="myregistry", data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE, ) # link from f1 to f2 (both in the child module) f1.post_form_workflow = WORKFLOW_FORM f1.form_links = [FormLink(form_id=f2.get_unique_id())] factory.app._id = "123" # wrap to have assign_references called self.app = Application.wrap(factory.app.to_json())
def test_workflow_registry_module_previous_screen_after_case_list_form(self): factory = AppFactory(DOMAIN, "App with DR", build_version='2.53.0') m0, f0 = factory.new_basic_module("new case", "case") factory.form_opens_case(f0, "case") m1, f1 = factory.new_basic_module("update case", "case") factory.form_requires_case(f1, "case") m1.case_details.long.columns.append( DetailColumn.wrap(dict( header={"en": "name"}, model="case", format="plain", field="whatever", )) ) m1.search_config = CaseSearch( properties=[ CaseSearchProperty(name='name', label={'en': 'Name'}), ], data_registry="myregistry", data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE, ) m1.case_list_form.form_id = f0.get_unique_id() m1.case_list_form.label = {'en': 'New Case'} f1.post_form_workflow = WORKFLOW_PREVIOUS app = Application.wrap(factory.app.to_json()) app._id = "123" suite = app.create_suite() self.assertXmlPartialEqual( """ <partial> <create> <command value="'m1'"/> <query id="results" value="http://localhost:8000/a/test_domain/phone/registry_case/123/"> <data key="case_type" ref="'case'"/> <data key="x_commcare_data_registry" ref="'myregistry'"/> <data key="case_id" ref="instance('commcaresession')/session/data/case_id"/> </query> <datum id="case_id" value="instance('commcaresession')/session/data/case_id"/> <query id="registry" value="http://localhost:8000/a/test_domain/phone/registry_case/123/"> <data key="x_commcare_data_registry" ref="'myregistry'"/> <data key="case_type" ref="'case'"/> <data key="case_id" ref="instance('commcaresession')/session/data/case_id"/> </query> </create> </partial> """, suite, "./entry[2]/stack/create" )
def test_blacklisted_owner_ids(self, *args): self.module.search_config = CaseSearch( properties=[ CaseSearchProperty(name='name', label={'en': 'Name'}), ], blacklisted_owner_ids_expression="instance('commcaresession')/session/context/userid", ) # 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_config_blacklisted_owners'), suite, "./remote-request[1]")
def setUp(self): self.app = Application.new_app(DOMAIN, "Untitled Application") self.app._id = '123' self.app.build_spec = BuildSpec(version='2.53.0', build_number=1) self.module = self.app.add_module(Module.new_module("Followup", None)) self.form = self.app.new_form(0, "Untitled Form", None, attachment=get_simple_form("xmlns1.0")) self.form.requires = 'case' self.module.case_type = 'case' self.module.case_details.long.columns.append( DetailColumn.wrap(dict( header={"en": "name"}, model="case", format="plain", field="whatever", )) ) self.module.search_config = CaseSearch( properties=[ CaseSearchProperty(name='name', label={'en': 'Name'}), CaseSearchProperty(name='favorite_color', label={'en': 'Favorite Color'}, itemset=Itemset( instance_id='item-list:colors', instance_uri='jr://fixture/item-list:colors', nodeset="instance('item-list:colors')/colors_list/colors", label='name', sort='name', value='value'), ) ], data_registry="myregistry", data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE, additional_registry_cases=["'another case ID'"], ) self.reg_module = self.app.add_module(Module.new_module("Registration", None)) self.reg_form = self.app.new_form(1, "Untitled Form", None, attachment=get_simple_form("xmlns1.0")) self.reg_module.case_type = 'case' self.reg_form.actions.open_case = OpenCaseAction( name_update=ConditionalCaseUpdate(question_path="/data/question1") ) self.reg_form.actions.open_case.condition.type = 'always' self.reg_form.post_form_workflow = WORKFLOW_FORM self.reg_form.form_links = [ FormLink(form_id=self.form.get_unique_id()) ] # 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] self.form = self.module.forms[0]
def test_only_default_properties(self, *args): self.module.search_config = CaseSearch( 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()) suite = self.app.create_suite() self.assertXmlPartialEqual(self.get_xml('search_config_default_only'), suite, "./remote-request[1]")
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']" )
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())
def setUp(self): super().setUp() self.app = Application.new_app(DOMAIN, "Application with Shadow") self.app._id = '456' self.app.build_spec = BuildSpec(version='2.53.0', build_number=1) self.module = self.app.add_module(Module.new_module("Followup", None)) self.form = self.app.new_form(0, "Untitled Form", None, attachment=get_simple_form("xmlns1.0")) self.form.requires = 'case' self.module.case_type = 'case' self.module.case_details.long.columns.append( DetailColumn.wrap(dict( header={"en": "name"}, model="case", format="plain", field="whatever", )) ) self.module.search_config = CaseSearch( properties=[ CaseSearchProperty(name='name', label={'en': 'Name'}), CaseSearchProperty(name='favorite_color', label={'en': 'Favorite Color'}, itemset=Itemset( instance_id='item-list:colors', instance_uri='jr://fixture/item-list:colors', nodeset="instance('item-list:colors')/colors_list/colors", label='name', sort='name', value='value'), ) ], data_registry="myregistry", data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE, additional_registry_cases=["'another case ID'"], ) self.shadow_module = self.app.add_module(ShadowModule.new_module("Shadow", "en")) self.shadow_module.source_module_id = self.module.unique_id self.shadow_module.case_details.long.columns.append( DetailColumn.wrap(dict( header={"en": "name"}, model="case", format="plain", field="whatever", )) ) self.shadow_module.search_config = CaseSearch( properties=[ CaseSearchProperty(name='name', label={'en': 'Name'}), CaseSearchProperty(name='favorite_color', label={'en': 'Texture'}, itemset=Itemset( instance_id='item-list:textures', instance_uri='jr://fixture/item-list:textures', nodeset="instance('item-list:textures')/textures_list/textures", label='name', sort='name', value='value'), ) ], data_registry="myregistry", data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE, ) # 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] self.shadow_module = self.app.modules[1]