Пример #1
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())
Пример #2
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('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)
Пример #3
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")
Пример #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
Пример #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
Пример #6
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()
Пример #7
0
def get_visit_scheduler_module_and_form_for_test():
    form = AdvancedForm(schedule=FormSchedule(
        unique_id='form-unique-id-1',
        schedule_form_id='form1',
        enabled=True,
        visits=[
            ScheduleVisit(
                due=1, starts=-1, expires=1, repeats=False, increment=None),
            ScheduleVisit(
                due=7, starts=-2, expires=3, repeats=False, increment=None),
            ScheduleVisit(due=None,
                          starts=None,
                          expires=None,
                          repeats=True,
                          increment=14),
        ],
    ))

    module = AdvancedModule(
        schedule_phases=[
            SchedulePhase(anchor='edd', forms=[]),
            SchedulePhase(anchor='add',
                          forms=[SchedulePhaseForm(form_id=form.unique_id)]),
        ],
        forms=[form],
    )

    return module, form
Пример #8
0
    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
Пример #9
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())
Пример #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 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())
Пример #14
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)
Пример #15
0
 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,
     })
Пример #16
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"))
        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 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()
Пример #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'))
     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')
Пример #21
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()
Пример #22
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.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()
Пример #23
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)
Пример #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
Пример #25
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()
Пример #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")
Пример #29
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)')
Пример #30
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!')
Пример #31
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)
Пример #32
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!')
Пример #33
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 ")
Пример #34
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 ")
Пример #35
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})
Пример #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 ")
Пример #37
0
    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]")
Пример #38
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'})
    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]")
Пример #40
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]")
Пример #41
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'})
Пример #42
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 ")
    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'
Пример #44
0
    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()
Пример #46
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',)).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()
Пример #47
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)
Пример #48
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)
    def handle(self, domain, app_id, module_id, *args, **options):
        app = get_current_app(domain, app_id)
        module = app.get_module_by_unique_id(module_id)

        assert module.doc_type == 'Module', "Only support modules"
        assert module.display_style == 'list', "Doesn't support grid case lists"
        assert module.referral_list.show is False, "Doesn't support referral lists"
        assert module.ref_details.short.columns == [], "Doesn't support ref details"
        assert module.ref_details.long.columns == [], "Doesn't support ref details"
        assert module.task_list.show is False, "Doesn't support task lists"

        latest_build = get_latest_build_version(domain, app_id)
        if latest_build != app.version:
            app.validate_app()
            copy = app.make_build(
                comment="Build before moving {} to an advanced module".format(module.name),
            )
            copy.save(increment_version=False)

        module.module_type = 'advanced'
        module.doc_type = 'AdvancedModule'

        forms = []
        for form in module.forms:
            # https://github.com/dimagi/commcare-hq/blob/271ab9346745e7a8a4d647db66dc959fbb9f8159/corehq/apps/app_manager/models.py#L3182
            assert isinstance(form, Form)
            new_form = AdvancedForm(
                name=form.name,
                form_filter=form.form_filter,
                media_image=form.media_image,
                media_audio=form.media_audio,
                comment=form.comment,
            )
            new_form._parent = module
            form._parent = module

            new_form.source = form.source

            actions = form.active_actions()
            open = actions.get('open_case', None)
            update = actions.get('update_case', None)
            close = actions.get('close_case', None)
            preload = actions.get('case_preload', None)
            subcases = actions.get('subcases', None)
            case_type = module.case_type

            base_action = None
            if open:
                base_action = AdvancedOpenCaseAction(
                    case_type=case_type,
                    case_tag='open_{0}_0'.format(case_type),
                    name_path=open.name_path,
                    open_condition=open.condition,
                    case_properties=update.update if update else {},
                )
                new_form.actions.open_cases.append(base_action)
            elif update or preload or close:
                base_action = LoadUpdateAction(
                    case_type=case_type,
                    case_tag='load_{0}_0'.format(case_type),
                    case_properties=update.update if update else {},
                    preload=preload.preload if preload else {},
                )

                if module.parent_select.active:
                    select_chain = get_select_chain(app, module, include_self=False)
                    for n, link in enumerate(reversed(list(enumerate(select_chain)))):
                        i, module = link
                        new_form.actions.load_update_cases.append(LoadUpdateAction(
                            case_type=module.case_type,
                            case_tag='_'.join(['parent'] * (i + 1)),
                            details_module=module.unique_id,
                            case_index=CaseIndex(tag='_'.join(['parent'] * (i + 2)) if n > 0 else ''),
                        ))

                    base_action.case_indices = [CaseIndex(tag='parent')]

                if close:
                    base_action.close_condition = close.condition
                new_form.actions.load_update_cases.append(base_action)

            if subcases:
                for i, subcase in enumerate(subcases):
                    open_subcase_action = AdvancedOpenCaseAction(
                        case_type=subcase.case_type,
                        case_tag='open_{0}_{1}'.format(subcase.case_type, i + 1),
                        name_path=subcase.case_name,
                        open_condition=subcase.condition,
                        case_properties=subcase.case_properties,
                        repeat_context=subcase.repeat_context,
                        case_indices=[CaseIndex(
                            tag=base_action.case_tag if base_action else '',
                            reference_id=subcase.reference_id,
                        )],
                    )
                    new_form.actions.open_cases.append(open_subcase_action)

            new_form.unique_id = form.unique_id
            forms.append(new_form.to_json())

        new_module = module.to_json()
        new_module['forms'] = forms
        del new_module['display_style']
        del new_module['referral_list']
        del new_module['ref_details']
        del new_module['task_list']
        del new_module['parent_select']  # This is handled in forms for advanced modules

        new_module = AdvancedModule.wrap(new_module)
        modules = app.modules
        mod_index = [i for i, mod in enumerate(modules) if mod.unique_id == module_id][0]
        modules[mod_index] = new_module
        app.modules = modules
        app.save()

        # update xml
        app = get_current_app(domain, app_id)
        module = app.get_module_by_unique_id(module_id)
        for form in module.forms:
            real_form = app.get_form(form.unique_id)
            if form.xmlns in (DUE_LIST_XMLNS, IMMUNIZATION_XMLNS):
                new_form_source = form.source.replace(
                    "instance('commcaresession')/session/data/case_id",
                    "instance('commcaresession')/session/data/case_id_load_tasks_0")
                real_form.source = new_form_source
            elif form.xmlns == ELIGIBLE_COUPLE_XMLNS:
                new_form_source = form.source.replace(
                    "instance('commcaresession')/session/data/case_id",
                    "instance('commcaresession')/session/data/case_id_load_person_0")
                real_form.source = new_form_source
        app.save()
        copy = app.make_build(
            comment="{} moved to an advanced module".format(module.name),
        )
        copy.save(increment_version=False)
Пример #50
0
    def handle(self, domain, app_id, module_id, *args, **options):
        app = get_current_app(domain, app_id)
        module = app.get_module_by_unique_id(module_id)

        assert module.doc_type == 'Module', "Only support modules"
        assert module.display_style == 'list', "Doesn't support grid case lists"
        assert module.referral_list.show is False, "Doesn't support referral lists"
        assert module.ref_details.short.columns == [], "Doesn't support ref details"
        assert module.ref_details.long.columns == [], "Doesn't support ref details"
        assert module.task_list.show is False, "Doesn't support task lists"

        latest_build = get_latest_build_version(domain, app_id)
        if latest_build != app.version:
            app.validate_app()
            copy = app.make_build(
                comment="Build before moving {} to an advanced module".format(
                    module.name), )
            copy.save(increment_version=False)

        module.module_type = 'advanced'
        module.doc_type = 'AdvancedModule'

        forms = []
        for form in module.forms:
            # https://github.com/dimagi/commcare-hq/blob/271ab9346745e7a8a4d647db66dc959fbb9f8159/corehq/apps/app_manager/models.py#L3182
            assert isinstance(form, Form)
            new_form = AdvancedForm(
                name=form.name,
                form_filter=form.form_filter,
                media_image=form.media_image,
                media_audio=form.media_audio,
                comment=form.comment,
            )
            new_form._parent = module
            form._parent = module

            new_form.source = form.source

            actions = form.active_actions()
            open = actions.get('open_case', None)
            update = actions.get('update_case', None)
            close = actions.get('close_case', None)
            preload = actions.get('case_preload', None)
            subcases = actions.get('subcases', None)
            case_type = module.case_type

            base_action = None
            if open:
                base_action = AdvancedOpenCaseAction(
                    case_type=case_type,
                    case_tag='open_{0}_0'.format(case_type),
                    name_path=open.name_path,
                    open_condition=open.condition,
                    case_properties=update.update if update else {},
                )
                new_form.actions.open_cases.append(base_action)
            elif update or preload or close:
                base_action = LoadUpdateAction(
                    case_type=case_type,
                    case_tag='load_{0}_0'.format(case_type),
                    case_properties=update.update if update else {},
                    preload=preload.preload if preload else {},
                )

                if module.parent_select.active:
                    select_chain = get_select_chain(app,
                                                    module,
                                                    include_self=False)
                    for n, link in enumerate(
                            reversed(list(enumerate(select_chain)))):
                        i, module = link
                        new_form.actions.load_update_cases.append(
                            LoadUpdateAction(
                                case_type=module.case_type,
                                case_tag='_'.join(['parent'] * (i + 1)),
                                details_module=module.unique_id,
                                case_index=CaseIndex(
                                    tag='_'.join(['parent'] *
                                                 (i + 2)) if n > 0 else ''),
                            ))

                    base_action.case_indices = [CaseIndex(tag='parent')]

                if close:
                    base_action.close_condition = close.condition
                new_form.actions.load_update_cases.append(base_action)

            if subcases:
                for i, subcase in enumerate(subcases):
                    open_subcase_action = AdvancedOpenCaseAction(
                        case_type=subcase.case_type,
                        case_tag='open_{0}_{1}'.format(subcase.case_type,
                                                       i + 1),
                        name_path=subcase.case_name,
                        open_condition=subcase.condition,
                        case_properties=subcase.case_properties,
                        repeat_context=subcase.repeat_context,
                        case_indices=[
                            CaseIndex(
                                tag=base_action.case_tag
                                if base_action else '',
                                reference_id=subcase.reference_id,
                            )
                        ],
                    )
                    new_form.actions.open_cases.append(open_subcase_action)

            new_form.unique_id = form.unique_id
            forms.append(new_form.to_json())

        new_module = module.to_json()
        new_module['forms'] = forms
        del new_module['display_style']
        del new_module['referral_list']
        del new_module['ref_details']
        del new_module['task_list']
        del new_module[
            'parent_select']  # This is handled in forms for advanced modules

        new_module = AdvancedModule.wrap(new_module)
        modules = app.modules
        mod_index = [
            i for i, mod in enumerate(modules) if mod.unique_id == module_id
        ][0]
        modules[mod_index] = new_module
        app.modules = modules
        app.save()

        # update xml
        app = get_current_app(domain, app_id)
        module = app.get_module_by_unique_id(module_id)
        for form in module.forms:
            real_form = app.get_form(form.unique_id)
            if form.xmlns in (DUE_LIST_XMLNS, IMMUNIZATION_XMLNS):
                new_form_source = form.source.replace(
                    "instance('commcaresession')/session/data/case_id",
                    "instance('commcaresession')/session/data/case_id_load_tasks_0"
                )
                real_form.source = new_form_source
            elif form.xmlns == ELIGIBLE_COUPLE_XMLNS:
                new_form_source = form.source.replace(
                    "instance('commcaresession')/session/data/case_id",
                    "instance('commcaresession')/session/data/case_id_load_person_0"
                )
                real_form.source = new_form_source
        app.save()
        copy = app.make_build(comment="{} moved to an advanced module".format(
            module.name), )
        copy.save(increment_version=False)