def setUp(self):
        self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
        self.is_usercase_in_use_mock.return_value = True

        self.app = Application.new_app('domain', 'New App')
        self.module = self.app.add_module(AdvancedModule.new_module('Fish Module', None))
        self.module.case_type = 'fish'
        self.form = self.module.new_form('Form', 'en', self.get_xml('original').decode('utf-8'))
        self.other_module = self.app.add_module(AdvancedModule.new_module('Freshwater Module', lang='en'))
        self.other_module.case_type = 'freshwater'
        self.other_form = self.module.new_form('Other Form', 'en', self.get_xml('original').decode('utf-8'))
        self.case_index = CaseIndex(
            reference_id='host',
            relationship='extension',
        )
        self.subcase = AdvancedOpenCaseAction(
            case_tag='open_freshwater_0',
            case_type='freshwater',
            case_name='Wanda',
            name_update=ConditionalCaseUpdate(question_path='/data/question1'),
            open_condition=FormActionCondition(type='always'),
            case_properties={'name': ConditionalCaseUpdate(question_path='/data/question1')},
            case_indices=[self.case_index],
        )
        self.form.actions.open_cases.append(self.subcase)
        self.xform = XForm(self.get_xml('original'))
        path = 'subcase_0/'
        self.subcase_block = XFormCaseBlock(self.xform, path)
Exemple #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(
            command_label={'en': 'Advanced Search'},
            again_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>"

        suite = self.app.create_suite()
        self.assertXmlPartialEqual(self.get_xml('search_command_detail'),
                                   suite, "./detail")
Exemple #3
0
    def test_case_list_registration_form_advanced(self):
        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        register_module = app.add_module(AdvancedModule.new_module('create', None))
        register_module.unique_id = 'register_module'
        register_module.case_type = 'dugong'
        register_form = app.new_form(0, 'Register Case', lang='en')
        register_form.unique_id = 'register_case_form'
        register_form.actions.open_cases.append(AdvancedOpenCaseAction(
            case_type='dugong',
            case_tag='open_dugong',
            name_path='/data/name'
        ))

        case_module = app.add_module(AdvancedModule.new_module('update', None))
        case_module.unique_id = 'case_module'
        case_module.case_type = 'dugong'
        update_form = app.new_form(1, 'Update Case', lang='en')
        update_form.unique_id = 'update_case_form'
        update_form.actions.load_update_cases.append(LoadUpdateAction(
            case_type='dugong',
            case_tag='load_dugong',
            details_module=case_module.unique_id
        ))

        case_module.case_list_form.form_id = register_form.get_unique_id()
        case_module.case_list_form.label = {
            'en': 'Register another Dugong'
        }
        self.assertXmlEqual(self.get_xml('case-list-form-advanced'), app.create_suite())
Exemple #4
0
    def get_test_app(self):
        app = Application.new_app('domain', 'New App')
        app._id = uuid.uuid4().hex
        app.version = 1
        m0 = self._make_module(app, 0, 'parent')
        m0.get_form(0).actions.subcases.extend([
            OpenSubCaseAction(case_type='child', reference_id='parent'),
            OpenSubCaseAction(case_type='other_child', reference_id='parent')
        ])
        m1 = self._make_module(app, 1, 'child')
        m1.get_form(0).actions.subcases.append(
            OpenSubCaseAction(case_type='grand child', reference_id='parent'))
        m2 = self._make_module(app, 2, 'grand child')

        m3 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
        m3.case_type = 'other grand child'
        m3f0 = m3.new_form('other form', 'en')
        m3f0.actions.load_update_cases.append(
            LoadUpdateAction(case_type='child', case_tag='child'))
        m3f0.actions.open_cases.append(
            AdvancedOpenCaseAction(
                name_path='/data/question1',
                case_type='other grand child',
                case_indices=[CaseIndex(tag='child', reference_id='father')]))
        m3f0.actions.open_cases[0].open_condition.type = 'always'

        m4 = app.add_module(AdvancedModule.new_module('Module4', lang='en'))
        m4.case_type = 'extension'
        self._make_module(app, 5, 'other_child')

        m4f0 = m4.new_form('other form', 'en')
        m4f0.actions.load_update_cases.extend([
            LoadUpdateAction(case_type='child', case_tag='child'),
            LoadUpdateAction(case_type='other_child', case_tag='other_child'),
        ])
        m4f0.actions.open_cases.extend([
            AdvancedOpenCaseAction(name_path='/data/question1',
                                   case_type='extension',
                                   case_indices=[
                                       CaseIndex(tag='child',
                                                 relationship='extension',
                                                 reference_id='host')
                                   ]),
            AdvancedOpenCaseAction(  # 'extension' case has 2 parents
                name_path='/data/question1',
                case_type='extension',
                case_indices=[
                    CaseIndex(tag='other_child',
                              relationship='extension',
                              reference_id='host')
                ])
        ])
        m4f0.actions.open_cases[0].open_condition.type = 'always'
        m4f0.actions.open_cases[1].open_condition.type = 'always'

        m2.parent_select = ParentSelect(active=True, module_id=m1.unique_id)
        m1.parent_select = ParentSelect(active=True, module_id=m0.unique_id)

        return app
Exemple #5
0
    def get_test_app(self):
        app = Application.new_app('domain', 'New App')
        app._id = uuid.uuid4().hex
        app.version = 1
        m0 = self._make_module(app, 0, 'parent')
        m0.get_form(0).actions.subcases.extend([
            OpenSubCaseAction(case_type='child', reference_id='parent'),
            OpenSubCaseAction(case_type='other_child', reference_id='parent')
        ])
        m1 = self._make_module(app, 1, 'child')
        m1.get_form(0).actions.subcases.append(OpenSubCaseAction(
            case_type='grand child',
            reference_id='parent'
        ))
        m2 = self._make_module(app, 2, 'grand child')

        m3 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
        m3.case_type = 'other grand child'
        m3f0 = m3.new_form('other form', 'en')
        m3f0.actions.load_update_cases.append(LoadUpdateAction(
            case_type='child',
            case_tag='child'))
        m3f0.actions.open_cases.append(AdvancedOpenCaseAction(
            name_path='/data/question1',
            case_type='other grand child',
            case_indices=[CaseIndex(tag='child', reference_id='father')]
        ))
        m3f0.actions.open_cases[0].open_condition.type = 'always'

        m4 = app.add_module(AdvancedModule.new_module('Module4', lang='en'))
        m4.case_type = 'extension'
        self._make_module(app, 5, 'other_child')

        m4f0 = m4.new_form('other form', 'en')
        m4f0.actions.load_update_cases.extend([
            LoadUpdateAction(case_type='child', case_tag='child'),
            LoadUpdateAction(case_type='other_child', case_tag='other_child'),
        ])
        m4f0.actions.open_cases.extend([
            AdvancedOpenCaseAction(
                name_path='/data/question1',
                case_type='extension',
                case_indices=[CaseIndex(tag='child', relationship='extension', reference_id='host')]
            ),
            AdvancedOpenCaseAction(  # 'extension' case has 2 parents
                name_path='/data/question1',
                case_type='extension',
                case_indices=[CaseIndex(tag='other_child', relationship='extension', reference_id='host')]
            )
        ])
        m4f0.actions.open_cases[0].open_condition.type = 'always'
        m4f0.actions.open_cases[1].open_condition.type = 'always'

        m2.parent_select = ParentSelect(active=True, module_id=m1.unique_id)
        m1.parent_select = ParentSelect(active=True, module_id=m0.unique_id)

        return app
Exemple #6
0
    def get_test_app(self):
        app = Application.new_app('domain', 'New App')
        app.version = 1
        m0 = self._make_module(app, 0, 'parent')
        m0.get_form(0).actions.subcases.append(
            OpenSubCaseAction(case_type='child', reference_id='parent'))
        m1 = self._make_module(app, 1, 'child')
        m1.get_form(0).actions.subcases.append(
            OpenSubCaseAction(case_type='grand child', reference_id='parent'))
        m2 = self._make_module(app, 2, 'grand child')

        m3 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
        m3.case_type = 'other grand child'
        m3f0 = m3.new_form('other form', 'en')
        m3f0.actions.load_update_cases.append(
            LoadUpdateAction(case_type='child', case_tag='child'))
        m3f0.actions.open_cases.append(
            AdvancedOpenCaseAction(name_path='/data/question1',
                                   case_type='other grand child',
                                   case_indices=[CaseIndex(tag='child')]))
        m3f0.actions.open_cases[0].open_condition.type = 'always'

        m2.parent_select = ParentSelect(active=True, module_id=m1.unique_id)
        m1.parent_select = ParentSelect(active=True, module_id=m0.unique_id)

        expected_hierarchy = {
            'parent': {
                'child': {
                    'grand child': {},
                    'other grand child': {}
                }
            }
        }
        return app, expected_hierarchy
    def test_child_module_adjusted_datums_advanced_module(self):
        """
        Testing that the session variable name for the case_id is correct since
        it will have been adjusted in the suite.xml to match the variable name
        in the root module.
        """
        module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        module.case_type = 'test_case_type'
        form = module.new_form("Untitled Form", "en", self.get_xml('original_form', override_path=('data',)))

        form.actions.load_update_cases.append(LoadUpdateAction(
            case_type=module.case_type,
            case_tag='load_1',
            case_properties={'question1': '/data/question1'}
        ))

        root_module = self.app.add_module(Module.new_module('root module', None))
        root_module.unique_id = 'm_root'
        root_module.case_type = module.case_type

        root_module_form = root_module.new_form('root module form', None)
        root_module_form.requires = 'case'
        root_module_form.actions.update_case = UpdateCaseAction(update={'question1': '/data/question1'})
        root_module_form.actions.update_case.condition.type = 'always'

        # make module a child module of root_module
        module.root_module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml('child_module_adjusted_case_id_advanced'), form.render_xform())
    def test_child_module_adjusted_datums_advanced_module(self):
        """
        Testing that the session variable name for the case_id is correct since
        it will have been adjusted in the suite.xml to match the variable name
        in the root module.
        """
        module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        module.case_type = 'test_case_type'
        form = module.new_form("Untitled Form", "en", self.get_xml('original_form', override_path=('data',)))

        form.actions.load_update_cases.append(LoadUpdateAction(
            case_type=module.case_type,
            case_tag='load_1',
            case_properties={'question1': '/data/question1'}
        ))

        root_module = self.app.add_module(Module.new_module('root module', None))
        root_module.unique_id = 'm_root'
        root_module.case_type = module.case_type

        root_module_form = root_module.new_form('root module form', None)
        root_module_form.requires = 'case'
        root_module_form.actions.update_case = UpdateCaseAction(update={'question1': '/data/question1'})
        root_module_form.actions.update_case.condition.type = 'always'

        # make module a child module of root_module
        module.root_module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml('child_module_adjusted_case_id_advanced'), form.render_xform())
    def test_child_module_adjusted_datums_advanced_module(self):
        """
        Testing that the session variable name for the case_id is correct since
        it will have been adjusted in the suite.xml to match the variable name
        in the root module.
        """
        module = self.app.add_module(AdvancedModule.new_module("New Module", lang="en"))
        module.case_type = "test_case_type"
        form = module.new_form("Untitled Form", "en", self.get_xml("original"))

        form.actions.load_update_cases.append(
            LoadUpdateAction(
                case_type=module.case_type, case_tag="load_1", case_properties={"question1": "/data/question1"}
            )
        )

        root_module = self.app.add_module(Module.new_module("root module", None))
        root_module.unique_id = "m_root"
        root_module.case_type = module.case_type

        root_module_form = root_module.new_form("root module form", None)
        root_module_form.requires = "case"
        root_module_form.actions.update_case = UpdateCaseAction(update={"question1": "/data/question1"})
        root_module_form.actions.update_case.condition.type = "always"

        # make module a child module of root_module
        module.root_module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml("child_module_adjusted_case_id_advanced"), form.render_xform())
Exemple #10
0
    def setUp(self):
        self.app = Application.new_app('domain', 'New App')
        self.app.version = 3
        self.parent_module = self.app.add_module(
            Module.new_module('New Module', lang='en'))
        self.parent_form = self.app.new_form(0, 'New Form', lang='en')
        self.parent_module.case_type = 'parent_test_case_type'
        self.parent_form.source = self.get_xml('original_form',
                                               override_path=('data', ))
        self.parent_form.actions.open_case = OpenCaseAction(
            name_path="/data/question1", external_id=None)
        self.parent_form.actions.open_case.condition.type = 'always'

        self.module = self.app.add_module(
            AdvancedModule.new_module('New Module', lang='en'))
        form = AdvancedForm(name={"en": "Untitled Form"})
        self.module.forms.append(form)
        self.form = self.module.get_form(-1)
        self.module.case_type = 'test_case_type'
        self.form.source = self.get_xml('subcase_original')

        child_module_1 = self.app.add_module(
            Module.new_module('New Module', lang='en'))
        child_module_1.case_type = 'child1'
        child_module_2 = self.app.add_module(
            Module.new_module('New Module', lang='en'))
        child_module_2.case_type = 'child2'
        self.is_usercase_in_use_patch = patch(
            'corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
Exemple #11
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3
        cls.first_build.has_submissions = True

        cls.advanced_app = Application.new_app('domain', "Untitled Application")
        module = cls.advanced_app.add_module(AdvancedModule.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", cls.get_xml('repeat_group_form'))
        form.xmlns = 'repeat-xmlns'
        form.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
            )
        ]

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
    def get_test_app(self):
        app = Application.new_app("domain", "New App", APP_V2)
        app.version = 1
        m0 = self._make_module(app, 0, "parent")
        m0.get_form(0).actions.subcases.append(OpenSubCaseAction(case_type="child", reference_id="parent"))
        m1 = self._make_module(app, 1, "child")
        m1.get_form(0).actions.subcases.append(OpenSubCaseAction(case_type="grand child", reference_id="parent"))
        m2 = self._make_module(app, 2, "grand child")

        m3 = app.add_module(AdvancedModule.new_module("Module3", lang="en"))
        m3.case_type = "other grand child"
        m3f0 = m3.new_form("other form", "en")
        m3f0.actions.load_update_cases.append(LoadUpdateAction(case_type="child", case_tag="child"))
        m3f0.actions.open_cases.append(
            AdvancedOpenCaseAction(
                name_path="/data/question1", case_type="other grand child", case_indices=[CaseIndex(tag="child")]
            )
        )
        m3f0.actions.open_cases[0].open_condition.type = "always"

        m2.parent_select = ParentSelect(active=True, module_id=m1.unique_id)
        m1.parent_select = ParentSelect(active=True, module_id=m0.unique_id)

        expected_hierarchy = {"parent": {"child": {"grand child": {}, "other grand child": {}}}}
        return app, expected_hierarchy
Exemple #13
0
 def setUp(self):
     self.app = Application.new_app('domain',
                                    "Untitled Application",
                                    application_version=APP_V2)
     self.module = self.app.add_module(
         AdvancedModule.new_module('Untitled Module', None))
     self.form = self.module.new_form("Untitled Form", None)
 def test_advanced_module(self, mock):
     module = self.app.add_module(AdvancedModule.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,
     })
Exemple #15
0
 def test_advanced_module(self):
     module = self.app.add_module(AdvancedModule.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 setUp(self):
     self.app = Application.new_app('domain', 'New App', APP_V2)
     self.app.version = 3
     self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
     form = AdvancedForm(name={"en": "Untitled Form"})
     self.module.forms.append(form)
     self.form = self.module.get_form(-1)
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original')
    def setUp(self):
        self.app = Application.new_app('domain', 'New App')
        self.app.version = 3
        self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        self.module.case_type = 'test_case_type'
        self.form = self.module.new_form("Untitled Form", "en", self.get_xml('original_form', override_path=('data',)))

        self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
Exemple #18
0
    def setUp(self):
        self.app = Application.new_app('domain', 'New App')
        self.app.version = 3
        self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        self.module.case_type = 'test_case_type'
        self.form = self.module.new_form("Untitled Form", "en", self.get_xml('original'))

        self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
Exemple #19
0
 def setUp(self):
     self.app = Application.new_app('domain', 'New App', APP_V2)
     self.app.version = 3
     self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
     form = AdvancedForm(name={"en": "Untitled Form"})
     self.module.forms.append(form)
     self.form = self.module.get_form(-1)
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original')
    def setUp(self):
        self.app = Application.new_app("domain", "New App", APP_V2)
        self.app.version = 3
        self.module = self.app.add_module(AdvancedModule.new_module("New Module", lang="en"))
        self.module.case_type = "test_case_type"
        self.form = self.module.new_form("Untitled Form", "en", self.get_xml("original"))

        self.is_usercase_in_use_patch = patch("corehq.apps.app_manager.models.is_usercase_in_use")
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.advanced_app = Application.new_app('domain',
                                               "Untitled Application")
        module = cls.advanced_app.add_module(
            AdvancedModule.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form",
                               cls.get_xml('repeat_group_form'))
        form.xmlns = 'repeat-xmlns'
        form.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
            )
        ]

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property_2')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                    ],
                    inferred=True),
            ])
        cls.inferred_schema.save()
Exemple #22
0
    def setUp(self):
        self.app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)
        update_toggle_cache(MODULE_FILTER.slug, self.app.domain, True, NAMESPACE_DOMAIN)
        self.module_0 = self.app.add_module(Module.new_module('parent', None))
        self.module_0.unique_id = 'm1'
        self.module_1 = self.app.add_module(AdvancedModule.new_module("Untitled Module", None))
        self.module_1.unique_id = 'm2'

        for m_id in range(2):
            self.app.new_form(m_id, "Form", None)
Exemple #23
0
def _new_advanced_module(request, domain, app, name, lang):
    module = app.add_module(AdvancedModule.new_module(name, lang))
    module_id = module.id
    app.new_form(module_id, _("Untitled Form"), lang)

    app.save()
    response = back_to_main(request, domain, app_id=app.id, module_id=module_id)
    response.set_cookie('suppress_build_errors', 'yes')
    messages.info(request, _('Caution: Advanced modules are a labs feature'))
    return response
Exemple #24
0
def _new_advanced_module(request, domain, app, name, lang):
    module = app.add_module(AdvancedModule.new_module(name, lang))
    module_id = module.id
    app.new_form(module_id, _("Untitled Form"), lang)

    app.save()
    response = back_to_main(request, domain, app_id=app.id, module_id=module_id)
    response.set_cookie('suppress_build_errors', 'yes')
    messages.info(request, _('Caution: Advanced modules are a labs feature'))
    return response
 def setUp(self):
     self.app = Application.new_app('domain', 'New App', APP_V2)
     self.app.version = 3
     self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
     form = AdvancedForm(name={"en": "Untitled Form"})
     self.module.forms.append(form)
     self.form = self.module.get_form(-1)
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original')
     self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
     self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
    def test_advanced_form_get_action_type(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        form = app.new_form(0, "Untitled Form", None)
        form.xmlns = 'http://id_m1-f0'
        form.actions.load_update_cases.append(LoadUpdateAction(case_type="clinic", case_tag='load_0'))

        modules, errors = get_app_summary_formdata('domain', app)
        self.assertEqual(modules[0]['forms'][0]['action_type'], 'load (load_0)')
Exemple #27
0
    def test_advanced_form_get_action_type(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        form = app.new_form(0, "Untitled Form", None)
        form.xmlns = 'http://id_m1-f0'
        form.actions.load_update_cases.append(LoadUpdateAction(case_type="clinic", case_tag='load_0'))

        modules, errors = get_app_summary_formdata('domain', app)
        self.assertEqual(modules[0]['forms'][0]['action_type'], 'load (load_0)')
    def test_case_search_action(self):
        """
        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(
            command_label={'en': 'Advanced Search'},
            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>"

        suite = self.app.create_suite()
        self.assertXmlPartialEqual(self.get_xml('search_command_detail'), suite, "./detail")
Exemple #29
0
    def test_copy_form(self):
        app = Application.new_app('domain', "Untitled Application")
        module = app.add_module(AdvancedModule.new_module('module', None))
        original_form = app.new_form(module.id, "Untitled Form", None)
        original_form.source = '<source>'

        app._copy_form(module, original_form, module, rename=True)

        form_count = 0
        for f in app.get_forms():
            form_count += 1
            if f.unique_id != original_form.unique_id:
                self.assertEqual(f.name['en'], 'Copy of {}'.format(original_form.name['en']))
        self.assertEqual(form_count, 2, 'Copy form has copied multiple times!')
Exemple #30
0
    def test_save_xform_with_shadow_form_does_not_change_xmlns(self):
        source = self.get_source()
        module = self.app.add_module(AdvancedModule.new_module('a module', None))
        form = self.app.new_form(self.module.id, "a form", None)
        save_xform(self.app, form, source.encode('utf-8'))
        Application.get_xmlns_map.get_cache(self.app).clear()

        shadow = module.new_shadow_form("shadow form", "en")
        shadow.shadow_parent_form_id = form.unique_id
        self.assertEqual(shadow.shadow_parent_form, form)

        save_xform(self.app, form, source.encode('utf-8'))
        self.assertEqual(form.source, source)
        self.assertEqual(form.xmlns, DEFAULT_XMLNS)
Exemple #31
0
    def test_copy_form(self):
        app = Application.new_app('domain', "Untitled Application")
        module = app.add_module(AdvancedModule.new_module('module', None))
        original_form = app.new_form(module.id, "Untitled Form", None)
        original_form.source = '<source>'

        app._copy_form(module, original_form, module, rename=True)

        form_count = 0
        for f in app.get_forms():
            form_count += 1
            if f.unique_id != original_form.unique_id:
                self.assertEqual(f.name['en'], 'Copy of {}'.format(original_form.name['en']))
        self.assertEqual(form_count, 2, 'Copy form has copied multiple times!')
Exemple #32
0
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {
            'lang': None,
            'default_label': "Default label message"
        }
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0, "Followup Form", None, attachment=attachment)

        modules, _ = util.get_form_data('domain', app)
        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['name']['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['questions'][0]['label'], " Default label message ")
Exemple #33
0
 def test_case_references_advanced(self):
     app = Application.new_app('domain', 'New App')
     app._id = uuid.uuid4().hex
     app.version = 1
     m0 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
     m0.case_type = 'household_advanced'
     m0f1 = m0.new_form('save to case', 'en', attachment=self.get_xml('standard_questions').decode('utf-8'))
     m0f1.case_references = CaseReferences.wrap({
         'save': {
             "/data/question1": {
                 "case_type": "household_advanced",
                 "properties": [
                     "save_to_case_p1",
                     "save_to_case_p2"
                 ],
             }
         }
     })
     self._assert_properties(app.get_case_metadata(), {'name', 'save_to_case_p1', 'save_to_case_p2'})
Exemple #34
0
 def test_case_references_advanced(self):
     app = Application.new_app('domain', 'New App')
     app._id = uuid.uuid4().hex
     app.version = 1
     m0 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
     m0.case_type = 'household_advanced'
     m0f1 = m0.new_form('save to case', 'en', attachment=self.get_xml('standard_questions'))
     m0f1.case_references = CaseReferences.wrap({
         'save': {
             "/data/question1": {
                 "case_type": "household_advanced",
                 "properties": [
                     "save_to_case_p1",
                     "save_to_case_p2"
                 ],
             }
         }
     })
     self._assert_properties(app.get_case_metadata(), {'save_to_case_p1', 'save_to_case_p2'})
Exemple #35
0
    def test_tiered_select_with_advanced_module_as_parent(self):
        app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        child_module = app.add_module(Module.new_module("Untitled Module", None))
        child_module.case_type = 'child'
        child_module.parent_select.active = True

        # make child module point to advanced module as parent
        child_module.parent_select.module_id = parent_module.unique_id

        child_form = app.new_form(1, "Untitled Form", None)
        child_form.xmlns = 'http://id_m1-f0'
        child_form.requires = 'case'

        self.assertXmlPartialEqual(self.get_xml('advanced_module_parent'), app.create_suite(), "./entry[1]")
Exemple #36
0
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {
            'lang': None,
            'default_label': "Default label message"
        }
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0, "Followup Form", None, attachment=attachment)

        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(app.modules[0].forms[0].name['en'], "Followup Form")

        first_question = app.modules[0].forms[0].get_questions([], include_triggers=True, include_groups=True)[0]
        self.assertEqual(first_question['label'], " Default label message ")
    def test_tiered_select_with_advanced_module_as_parent(self):
        app = Application.new_app("domain", "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module("parent", None))
        parent_module.case_type = "parent"
        parent_module.unique_id = "id_parent_module"

        child_module = app.add_module(Module.new_module("Untitled Module", None))
        child_module.case_type = "child"
        child_module.parent_select.active = True

        # make child module point to advanced module as parent
        child_module.parent_select.module_id = parent_module.unique_id

        child_form = app.new_form(1, "Untitled Form", None)
        child_form.xmlns = "http://id_m1-f0"
        child_form.requires = "case"

        self.assertXmlPartialEqual(self.get_xml("advanced_module_parent"), app.create_suite(), "./entry[1]")
Exemple #38
0
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {
            'lang': None,
            'default_label': "Default label message"
        }
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0, "Followup Form", None, attachment=attachment)

        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(app.modules[0].forms[0].name['en'], "Followup Form")

        first_question = app.modules[0].forms[0].get_questions([], include_triggers=True, include_groups=True)[0]
        self.assertEqual(first_question['label'], " Default label message ")
    def test_tiered_select_with_advanced_module_as_parent(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        child_module = app.add_module(Module.new_module("Untitled Module", None))
        child_module.case_type = 'child'
        child_module.parent_select.active = True

        # make child module point to advanced module as parent
        child_module.parent_select.module_id = parent_module.unique_id

        child_form = app.new_form(1, "Untitled Form", None)
        child_form.xmlns = 'http://id_m1-f0'
        child_form.requires = 'case'

        self.assertXmlPartialEqual(self.get_xml('advanced_module_parent'), app.create_suite(), "./entry[1]")
Exemple #40
0
 def test_case_properties_advanced(self):
     app = Application.new_app('domain', 'New App')
     app._id = uuid.uuid4().hex
     app.version = 1
     m0 = app.add_module(AdvancedModule.new_module('Module0', lang='en'))
     m0.case_type = 'child'
     m0f0 = m0.new_form(
         'other form',
         'en',
         attachment=self.get_xml('standard_questions').decode('utf-8'))
     m0f0.actions.load_update_cases.append(
         LoadUpdateAction(
             case_type='parent',
             case_tag='parent',
             case_properties={
                 'case_name':
                 ConditionalCaseUpdate(question_path='/data/question1'),
                 'other':
                 ConditionalCaseUpdate(question_path='/data/question2')
             }))
     m0f0.actions.open_cases.append(
         AdvancedOpenCaseAction(
             name_update=ConditionalCaseUpdate(
                 question_path='/data/question1'),
             case_type='child',
             case_indices=[CaseIndex(tag='parent', reference_id='father')],
             case_properties={
                 'child_other':
                 ConditionalCaseUpdate(question_path='/data/question2')
             }))
     m0f0.actions.open_cases[0].open_condition.type = 'always'
     meta = app.get_case_metadata()
     self.assertEqual(2, len(meta.case_types))
     child_type = meta.get_type('child')
     parent_type = meta.get_type('parent')
     self.assertFalse(child_type.has_errors)
     self.assertFalse(parent_type.has_errors)
     self.assertEqual({'name', 'child_other'},
                      {p.name
                       for p in child_type.properties})
     self.assertEqual({'case_name', 'other'},
                      {p.name
                       for p in parent_type.properties})
    def test_default_followup_form(self):
        app = Application.new_app('domain', "Untitled Application")

        parent_module = app.add_module(
            AdvancedModule.new_module('parent', None))
        parent_module.case_type = 'parent'
        parent_module.unique_id = 'id_parent_module'

        context = {'lang': None, 'default_label': "Default label message"}
        attachment = get_default_followup_form_xml(context=context)
        followup = app.new_form(0,
                                "Followup Form",
                                None,
                                attachment=attachment)

        modules, _ = util.get_form_data('domain', app)
        self.assertEqual(followup.name['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['name']['en'], "Followup Form")
        self.assertEqual(modules[0]['forms'][0]['questions'][0]['label'],
                         " Default label message ")
    def setUp(self):
        self.app = Application.new_app('domain', 'New App', APP_V2)
        self.app.version = 3
        self.parent_module = self.app.add_module(Module.new_module('New Module', lang='en'))
        self.parent_form = self.app.new_form(0, 'New Form', lang='en')
        self.parent_module.case_type = 'parent_test_case_type'
        self.parent_form.source = self.get_xml('original')
        self.parent_form.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
        self.parent_form.actions.open_case.condition.type = 'always'

        self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        form = AdvancedForm(name={"en": "Untitled Form"})
        self.module.forms.append(form)
        self.form = self.module.get_form(-1)
        self.module.case_type = 'test_case_type'
        self.form.source = self.get_xml('subcase_original')

        child_module_1 = self.app.add_module(Module.new_module('New Module', lang='en'))
        child_module_1.case_type ='child1'
        child_module_2 = self.app.add_module(Module.new_module('New Module', lang='en'))
        child_module_2.case_type ='child2'
    def get_test_app(self):
        app = Application.new_app('domain', 'New App', APP_V2)
        app.version = 1
        m0 = self._make_module(app, 0, 'parent')
        m0.get_form(0).actions.subcases.append(OpenSubCaseAction(
            case_type='child',
            reference_id='parent'
        ))
        m1 = self._make_module(app, 1, 'child')
        m1.get_form(0).actions.subcases.append(OpenSubCaseAction(
            case_type='grand child',
            reference_id='parent'
        ))
        m2 = self._make_module(app, 2, 'grand child')

        m3 = app.add_module(AdvancedModule.new_module('Module3', lang='en'))
        m3.case_type = 'other grand child'
        m3f0 = m3.new_form('other form', 'en')
        m3f0.actions.load_update_cases.append(LoadUpdateAction(
            case_type='child',
            case_tag='child'))
        m3f0.actions.open_cases.append(AdvancedOpenCaseAction(
            name_path='/data/question1',
            case_type='other grand child',
            parent_tag='child'
        ))
        m3f0.actions.open_cases[0].open_condition.type = 'always'

        m2.parent_select = ParentSelect(active=True, module_id=m1.unique_id)
        m1.parent_select = ParentSelect(active=True, module_id=m0.unique_id)

        expected_hierarchy = {
            'parent': {
                'child': {
                    'grand child': {},
                    'other grand child': {}
                }
            }
        }
        return app, expected_hierarchy
    def setUp(self):
        self.app = Application.new_app("domain", "New App", APP_V2)
        self.app.version = 3
        self.parent_module = self.app.add_module(Module.new_module("New Module", lang="en"))
        self.parent_form = self.app.new_form(0, "New Form", lang="en")
        self.parent_module.case_type = "parent_test_case_type"
        self.parent_form.source = self.get_xml("original")
        self.parent_form.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
        self.parent_form.actions.open_case.condition.type = "always"

        self.module = self.app.add_module(AdvancedModule.new_module("New Module", lang="en"))
        form = AdvancedForm(name={"en": "Untitled Form"})
        self.module.forms.append(form)
        self.form = self.module.get_form(-1)
        self.module.case_type = "test_case_type"
        self.form.source = self.get_xml("subcase_original")

        child_module_1 = self.app.add_module(Module.new_module("New Module", lang="en"))
        child_module_1.case_type = "child1"
        child_module_2 = self.app.add_module(Module.new_module("New Module", lang="en"))
        child_module_2.case_type = "child2"
        self.is_usercase_in_use_patch = patch("corehq.apps.app_manager.models.is_usercase_in_use")
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
    def setUp(self):
        self.app = Application.new_app('domain', 'New App')
        self.app.version = 3
        self.parent_module = self.app.add_module(Module.new_module('New Module', lang='en'))
        self.parent_form = self.app.new_form(0, 'New Form', lang='en')
        self.parent_module.case_type = 'parent_test_case_type'
        self.parent_form.source = self.get_xml('original_form', override_path=('data',)).decode('utf-8')
        self.parent_form.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
        self.parent_form.actions.open_case.condition.type = 'always'

        self.module = self.app.add_module(AdvancedModule.new_module('New Module', lang='en'))
        form = AdvancedForm(name={"en": "Untitled Form"})
        self.module.forms.append(form)
        self.form = self.module.get_form(-1)
        self.module.case_type = 'test_case_type'
        self.form.source = self.get_xml('subcase_original').decode('utf-8')

        child_module_1 = self.app.add_module(Module.new_module('New Module', lang='en'))
        child_module_1.case_type ='child1'
        child_module_2 = self.app.add_module(Module.new_module('New Module', lang='en'))
        child_module_2.case_type ='child2'
        self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
Exemple #46
0
    def setUp(self):
        self.is_usercase_in_use_patch = patch('corehq.apps.app_manager.models.is_usercase_in_use')
        self.is_usercase_in_use_mock = self.is_usercase_in_use_patch.start()
        self.is_usercase_in_use_mock.return_value = True

        self.app = Application.new_app('domain', 'New App')
        self.module = self.app.add_module(AdvancedModule.new_module('Fish Module', None))
        self.module.case_type = 'fish'
        self.form = self.module.new_form('New Form', None)
        self.case_index = CaseIndex(
            reference_id='host',
            relationship='extension',
        )
        self.subcase = AdvancedOpenCaseAction(
            case_type='freshwater',
            case_name='Wanda',
            open_condition=FormActionCondition(type='always'),
            case_properties={'name': '/data/question1'},
            case_indices=[self.case_index],
        )
        self.form.actions.open_cases.append(self.subcase)
        self.xform = XForm(self.get_xml('original'))
        path = 'subcase_0/'
        self.subcase_block = CaseBlock(self.xform, path)
Exemple #47
0
 def setUp(self):
     self.app = Application.new_app('domain', "Untitled Application")
     self.module = self.app.add_module(AdvancedModule.new_module('Untitled Module', None))
     self.form = self.module.new_form("Untitled Form", None)