def test_child_module_adjusted_datums_basic_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(Module.new_module("New Module", lang="en"))
        module.case_type = "guppy"
        form = module.new_form("Untitled Form", "en", self.get_xml("original"))

        form.requires = "case"
        form.actions.update_case = UpdateCaseAction(update={"question1": "/data/question1"})
        form.actions.update_case.condition.type = "always"

        root_module = self.app.add_module(Module.new_module("root module", None))
        root_module.unique_id = "m_root"
        root_module.case_type = "test_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

        module.parent_select.active = True
        module.parent_select.module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml("child_module_adjusted_case_id_basic"), form.render_xform())
    def test_subcase_repeat_mixed_form(self):
        app = Application.new_app(None, "Untitled Application", application_version=APP_V2)
        module_0 = app.add_module(Module.new_module('parent', None))
        module_0.unique_id = 'm0'
        module_0.case_type = 'parent'
        form = app.new_form(0, "Form", None, attachment=self.get_xml('subcase_repeat_mixed_form_pre'))

        module_1 = app.add_module(Module.new_module('subcase', None))
        module_1.unique_id = 'm1'
        module_1.case_type = 'subcase'

        form.actions.open_case = OpenCaseAction(name_path="/data/parent_name")
        form.actions.open_case.condition.type = 'always'

        form.actions.subcases.append(OpenSubCaseAction(
            case_type=module_1.case_type,
            case_name="/data/first_child_name",
            condition=FormActionCondition(type='always')
        ))
        # subcase in the middle that has a repeat context
        form.actions.subcases.append(OpenSubCaseAction(
            case_type=module_1.case_type,
            case_name="/data/repeat_child/repeat_child_name",
            repeat_context='/data/repeat_child',
            condition=FormActionCondition(type='always')
        ))
        form.actions.subcases.append(OpenSubCaseAction(
            case_type=module_1.case_type,
            case_name="/data/last_child_name",
            condition=FormActionCondition(type='always')
        ))

        self.assertXmlEqual(self.get_xml('subcase_repeat_mixed_form_post'),
                            app.get_module(0).get_form(0).render_xform())
Пример #3
0
def apps_modules_setup(test_case):
    """
    Additional setUp and tearDown for get_apps_modules tests
    """
    test_case.app.add_module(Module.new_module("Module0", "en"))
    test_case.app.save()

    test_case.other_app = Application.new_app(test_case.project.name, "OtherApp")
    test_case.other_app.add_module(Module.new_module("Module0", "en"))
    test_case.other_app.save()

    test_case.deleted_app = Application.new_app(test_case.project.name, "DeletedApp")
    test_case.deleted_app.add_module(Module.new_module("Module0", "en"))
    test_case.deleted_app.save()
    test_case.deleted_app.delete_app()
    test_case.deleted_app.save()  # delete_app() changes doc_type. This save() saves that.

    test_case.linked_app = create_linked_app(test_case.project.name, test_case.app.id,
                                             test_case.project.name, 'LinkedApp')
    try:
        yield
    finally:
        Application.get_db().delete_doc(test_case.linked_app.id)
        Application.get_db().delete_doc(test_case.deleted_app.id)
        Application.get_db().delete_doc(test_case.other_app.id)
Пример #4
0
    def setUpClass(cls):
        super(TestDelayedSchema, cls).setUpClass()
        cls.current_app = Application.new_app(cls.domain, "Untitled Application")
        cls.current_app._id = '1234'
        cls.current_app.version = 10
        module = cls.current_app.add_module(Module.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", 'en', attachment=cls.get_xml('basic_form').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.build = Application.new_app(cls.domain, "Untitled Application")
        cls.build._id = '5678'
        cls.build.copy_of = cls.current_app._id
        cls.build.version = 5
        cls.build.has_submissions = True
        module = cls.build.add_module(Module.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", 'en',
                               attachment=cls.get_xml('basic_form_version2').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.apps = [
            cls.current_app,
            cls.build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
    def test_child_module_adjusted_datums_basic_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(Module.new_module('New Module', lang='en'))
        module.case_type = 'guppy'
        form = module.new_form("Untitled Form", "en", self.get_xml('original_form', override_path=('data',)))

        form.requires = 'case'
        form.actions.update_case = UpdateCaseAction(update={'question1': '/data/question1'})
        form.actions.update_case.condition.type = 'always'

        root_module = self.app.add_module(Module.new_module('root module', None))
        root_module.unique_id = 'm_root'
        root_module.case_type = 'test_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

        module.parent_select.active = True
        module.parent_select.module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml('child_module_adjusted_case_id_basic'), form.render_xform())
    def setUp(self):
        self.app = Application.new_app('domain', "Untitled Application")

        self.parent = self.app.add_module(Module.new_module('Parent Module', None))
        self.app.new_form(self.parent.id, "Parent Form", None)

        self.child = self.app.add_module(Module.new_module('Child Module', None))
        self.child.root_module_id = self.parent.unique_id
        self.app.new_form(self.child.id, "Child Form", None)

        self.shadow = self.app.add_module(ShadowModule.new_module('Shadow Module', None))
Пример #7
0
    def _get_family_app(self):
        app = Application.new_app('domain', "Untitled Application")

        parent = app.add_module(Module.new_module('module', None))
        app.new_form(parent.id, "Untitled Form", None)

        child = app.add_module(Module.new_module('module', None))
        child.root_module_id = parent.unique_id

        app.new_form(child.id, "Untitled Form", None)
        shadow = app.add_module(ShadowModule.new_module('module', None))

        return (app, shadow)
Пример #8
0
    def test_overwrite_app_maintain_ids(self):
        module = self.plain_master_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        module = self.linked_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        id_map_before = _get_form_id_map(self.linked_app)

        overwrite_app(self.linked_app, self.plain_master_app, {})
        self.assertEqual(
            id_map_before,
            _get_form_id_map(LinkedApplication.get(self.linked_app._id))
        )
Пример #9
0
 def _make_module(self, app, module_id, case_type):
     m = app.add_module(Module.new_module('Module{}'.format(module_id), lang='en'))
     m.case_type = case_type
     mf = app.new_form(module_id, 'form {}'.format(case_type), lang='en')
     mf.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
     mf.actions.open_case.condition.type = 'always'
     return m
Пример #10
0
    def test_case_list_lookup_w_extras_and_responses(self):
        app = Application.new_app('domain', 'Untitled Application')
        module = app.add_module(Module.new_module('Untitled Module', None))
        module.case_type = 'patient'
        module.case_details.short.lookup_enabled = True
        module.case_details.short.lookup_action = "callout.commcarehq.org.dummycallout.LAUNCH"
        module.case_details.short.lookup_extras = [
            {'key': 'action_0', 'value': 'com.biometrac.core.SCAN'},
            {'key': "action_1", 'value': "com.biometrac.core.IDENTIFY"},
        ]
        module.case_details.short.lookup_responses = [
            {"key": "match_id_0"},
            {"key": "match_id_1"},
        ]

        expected = """
        <partial>
            <lookup action="callout.commcarehq.org.dummycallout.LAUNCH">
                <extra key="action_0" value="com.biometrac.core.SCAN"/>
                <extra key="action_1" value="com.biometrac.core.IDENTIFY"/>
                <response key="match_id_0"/>
                <response key="match_id_1"/>
            </lookup>
        </partial>
        """

        self.assertXmlPartialEqual(
            expected,
            app.create_suite(),
            "./detail/lookup"
        )
Пример #11
0
    def create_two_module_app(self, domain_name, app_name):

        app = Application.new_app(domain_name, app_name)
        app.add_module(Module.new_module('Module 1', None))
        app.add_module(Module.new_module('Module 2', None))

        for m_id in range(2):
            app.new_form(m_id, "Form", None)

        app.save()

        print "Application {app_name}: {app_url} created in domain {domain_name}".format(
            app_name=app_name,
            app_url=reverse('view_app', args=[domain_name, app._id], absolute=True),
            domain_name=domain_name
        )
Пример #12
0
def new_module(request, domain, app_id):
    "Adds a module to an app"
    app = get_app(domain, app_id)
    lang = request.COOKIES.get('lang', app.langs[0])
    name = request.POST.get('name')
    module_type = request.POST.get('module_type', 'case')
    if module_type == 'case':
        module = app.add_module(Module.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')
        return response
    elif module_type in MODULE_TYPE_MAP:
        fn = MODULE_TYPE_MAP[module_type][FN]
        validations = MODULE_TYPE_MAP[module_type][VALIDATIONS]
        error = next((v[1] for v in validations if v[0](app)), None)
        if error:
            messages.warning(request, error)
            return back_to_main(request, domain, app_id=app.id)
        else:
            return fn(request, domain, app, name, lang)
    else:
        logger.error('Unexpected module type for new module: "%s"' % module_type)
        return back_to_main(request, domain, app_id=app_id)
Пример #13
0
    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',)).decode('utf-8'))

        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 build_app_with_recently_fixed_form(self, mock):
        """
        Generates an app with a form that:
        - had an "undefined" xmlns
        - had forms submitted with the bad xmlns
        - had xmlns changed to something real
        - had forms submitted with real xmlns
        """
        form_name = "Untitled Form"

        app = Application.new_app(DOMAIN, 'Normal App')
        module = app.add_module(Module.new_module('New Module', lang='en'))
        form_source = self.get_xml('form_template').decode('utf-8').format(
            xmlns="undefined", name=form_name
        )
        form = module.new_form(form_name, "en", form_source)
        app.save()
        bad_build = app.make_build()
        bad_build.save()

        bad_xform = self._submit_form(form.xmlns, form_name, app._id, bad_build._id)

        xmlns = generate_random_xmlns()
        form = app.get_form(form.unique_id)
        form.source = self.get_xml('form_template').decode('utf-8').format(
            xmlns=xmlns, name=form_name
        )
        form.xmlns = xmlns
        app.save()

        good_build = app.make_build()
        good_build.save()
        good_xform = self._submit_form(form.xmlns, form_name, app._id, good_build._id)

        return form, good_build, bad_build, good_xform, bad_xform
    def build_app_with_bad_form(self, mock):
        """
        Generates an app with one normal form, and one form with "undefined" xmlns
        Generates submissions against both forms.
        """
        xmlns = generate_random_xmlns()
        good_form_name = "Untitled Form"
        bad_form_name = "Bad Form"

        app = Application.new_app(DOMAIN, 'Normal App')
        module = app.add_module(Module.new_module('New Module', lang='en'))
        good_form_source = self.get_xml('form_template').decode('utf-8').format(xmlns=xmlns, name=good_form_name)
        good_form = module.new_form(good_form_name, "en", good_form_source)
        bad_form_source = self.get_xml('form_template').decode('utf-8').format(
            xmlns="undefined", name=bad_form_name)
        bad_form = module.new_form(bad_form_name, "en", bad_form_source)
        app.save()
        build = app.make_build()
        build.save()

        good_xform = self._submit_form(xmlns, good_form_name, app._id, build._id)

        bad_xforms = []
        for i in range(2):
            bad_xform = self._submit_form("undefined", bad_form_name, app._id, build._id)
            bad_xforms.append(bad_xform)

        return good_form, bad_form, good_xform, bad_xforms
Пример #16
0
    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(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.
        """
        self.form.actions.load_update_cases.append(LoadUpdateAction(
            case_type=self.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 = self.module.case_type

        root_module_form = self.app.new_form(1, '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
        self.module.root_module_id = root_module.unique_id

        self.assertXmlEqual(self.get_xml('child_module_adjusted_case_id'), self.form.render_xform())
Пример #18
0
    def test_download_file_bad_xform_404(self):
        '''
        This tests that the `download_file` view returns
        HTTP code 404 for XML that cannot be generated...
        in some sense it does not exist.
        '''

        module = self.app.add_module(Module.new_module("Module0", "en"))

        # These builds are checked in to the repo for use in tests
        build1 = {'version': '1.2.dev', 'build_number': 7106}
        build2 = {'version': '2.7.0', 'build_number': 20655}

        add_build(**build1)
        add_build(**build2)

        with open(os.path.join(os.path.dirname(__file__), "data", "invalid_form.xml")) as f:
            xform_str = f.read()
        self.app.new_form(module.id, name="Form0-0", attachment=xform_str, lang="en")
        self.app.save()

        response = self.client.get(reverse('app_download_file', kwargs=dict(domain=self.domain.name,
                                                                            app_id=self.app.get_id,
                                                                            path='modules-0/forms-0.xml')))
        self.assertEqual(response.status_code, 404)
Пример #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(Module.new_module("New Module", lang="en"))
     self.form = self.app.new_form(0, "New Form", lang="en")
     self.module.case_type = "test_case_type"
     self.form.source = self.get_xml("original_form", override_path=("data",))
Пример #20
0
    def new_edit_subject_module(self, app, reg_form_id):

        def add_edit_form_to_module(module_):
            edit_form = module_.new_form('Edit Subject', None)
            edit_form.get_unique_id()
            edit_form.source = self.get_subject_form_source('Edit Subject')
            edit_form.requires = 'case'
            update = dict(self.case_update, name='/data/' + CC_SUBJECT_KEY)
            preload = {v: k for k, v in update.items()}
            edit_form.actions.case_preload = PreloadAction(
                preload=preload,
                condition=FormActionCondition(type='always')
            )
            edit_form.actions.update_case = UpdateCaseAction(
                update=update,
                condition=FormActionCondition(type='always')
            )

        module = app.add_module(Module.new_module('Study Subjects', None))
        module.unique_id = 'study_subjects'
        module.case_type = 'subject'
        module.case_list_form = CaseListForm(
            form_id=reg_form_id,
            label={'en': 'Register Subject'}
        )
        add_edit_form_to_module(module)
        return module
Пример #21
0
    def test_case_tile_pull_down(self):
        app = Application.new_app('domain', 'Untitled Application')

        module = app.add_module(Module.new_module('Untitled Module', None))
        module.case_type = 'patient'
        module.case_details.short.use_case_tiles = True
        module.case_details.short.persist_tile_on_forms = True
        module.case_details.short.pull_down_tile = True

        module.case_details.short.columns = [
            DetailColumn(
                header={'en': 'a'},
                model='case',
                field='a',
                format='plain',
                case_tile_field='header'
            ),
            DetailColumn(
                header={'en': 'b'},
                model='case',
                field='b',
                format='plain',
                case_tile_field='top_left'
            ),
            DetailColumn(
                header={'en': 'c'},
                model='case',
                field='c',
                format='enum',
                enum=[
                    MappingItem(key='male', value={'en': 'Male'}),
                    MappingItem(key='female', value={'en': 'Female'}),
                ],
                case_tile_field='sex'
            ),
            DetailColumn(
                header={'en': 'd'},
                model='case',
                field='d',
                format='plain',
                case_tile_field='bottom_left'
            ),
            DetailColumn(
                header={'en': 'e'},
                model='case',
                field='e',
                format='date',
                case_tile_field='date'
            ),
        ]

        form = app.new_form(0, "Untitled Form", None)
        form.xmlns = 'http://id_m0-f0'
        form.requires = 'case'

        self.assertXmlPartialEqual(
            self.get_xml('case_tile_pulldown_session'),
            app.create_suite(),
            "./entry/session"
        )
 def setUp(self):
     self.app = Application.new_app('domain', 'New App', APP_V2)
     self.app.version = 3
     self.module = self.app.add_module(Module.new_module('New Module', lang='en'))
     self.form = self.app.new_form(0, 'New Form', lang='en')
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original')
Пример #23
0
 def setUp(self):
     self.app = Application.new_app(DOMAIN, "Untitled Application")
     self.module = self.app.add_module(Module.new_module("Untitled Module", None))
     self.app.new_form(0, "Untitled Form", None)
     self.module.case_type = 'case'
     self.module.search_config = CaseSearch(
         command_label={'en': 'Search Patients Nationally'},
         properties=[
             CaseSearchProperty(name='name', label={'en': 'Name'}),
             CaseSearchProperty(name='dob', label={'en': 'Date of birth'})
         ],
         relevant="{} and {}".format("instance('groups')/groups/group", CLAIM_DEFAULT_RELEVANT_CONDITION),
         default_properties=[
             DefaultCaseSearchProperty(
                 property=u'ɨŧsȺŧɍȺᵽ',
                 defaultValue=(
                     u"instance('casedb')/case"
                     u"[@case_id='instance('commcaresession')/session/data/case_id']"
                     u"/ɨŧsȺŧɍȺᵽ")
             ),
             DefaultCaseSearchProperty(
                 property='name',
                 defaultValue="instance('locations')/locations/location[@id=123]/@type",
             ),
         ],
     )
Пример #24
0
def new_module(request, domain, app_id):
    "Adds a module to an app"
    app = get_app(domain, app_id)
    from corehq.apps.app_manager.views.utils import get_default_followup_form_xml
    lang = request.COOKIES.get('lang', app.langs[0])
    name = request.POST.get('name')
    module_type = request.POST.get('module_type', 'case')

    if module_type == 'case' or module_type == 'survey':  # survey option added for V2
        if module_type == 'case':
            name = name or 'Case List'
        else:
            name = name or 'Surveys'

        module = app.add_module(Module.new_module(name, lang))
        module_id = module.id

        form_id = None
        unstructured = add_ons.show("empty_case_lists", request, app)
        if module_type == 'case':
            if not unstructured:
                form_id = 0

                # registration form
                register = app.new_form(module_id, _("Registration Form"), lang)
                register.actions.open_case = OpenCaseAction(condition=FormActionCondition(type='always'))
                register.actions.update_case = UpdateCaseAction(
                    condition=FormActionCondition(type='always'))

                # one followup form
                msg = _("This is your follow up form. "
                        "Delete this label and add questions for any follow up visits.")
                attachment = get_default_followup_form_xml(context={'lang': lang, 'default_label': msg})
                followup = app.new_form(module_id, _("Followup Form"), lang, attachment=attachment)
                followup.requires = "case"
                followup.actions.update_case = UpdateCaseAction(condition=FormActionCondition(type='always'))

            _init_module_case_type(module)
        else:
            form_id = 0
            app.new_form(module_id, _("Survey"), lang)

        app.save()
        response = back_to_main(request, domain, app_id=app_id,
                                module_id=module_id, form_id=form_id)
        response.set_cookie('suppress_build_errors', 'yes')
        return response
    elif module_type in MODULE_TYPE_MAP:
        fn = MODULE_TYPE_MAP[module_type][FN]
        validations = MODULE_TYPE_MAP[module_type][VALIDATIONS]
        error = next((v[1] for v in validations if v[0](app)), None)
        if error:
            messages.warning(request, error)
            return back_to_main(request, domain, app_id=app.id)
        else:
            return fn(request, domain, app, name, lang)
    else:
        logger.error('Unexpected module type for new module: "%s"' % module_type)
        return back_to_main(request, domain, app_id=app_id)
Пример #25
0
 def setUp(self):
     self.domain = Domain(name='test')
     self.domain.save()
     app = Application.new_app('test', "Test Application", lang='en')
     module = Module.new_module("Untitled Module", 'en')
     app.add_module(module)
     app.new_form(0, "Untitled Form", 'en')
     app.save()
Пример #26
0
 def setUp(self):
     self.domain = 'domain'
     self.app = Application.new_app(self.domain, 'New App')
     self.app.version = 3
     self.module = self.app.add_module(Module.new_module('New Module', lang='en'))
     self.form = self.app.new_form(0, 'New Form', lang='en')
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original_form', override_path=('data',)).decode('utf-8')
Пример #27
0
 def _make_module(self, app, module_id, case_type):
     m = app.add_module(Module.new_module('Module{}'.format(module_id), lang='en'))
     m.case_type = case_type
     mf = app.new_form(module_id, 'form {}'.format(case_type), lang='en',
                       attachment=self.get_xml('standard_questions').decode('utf-8'))
     mf.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
     mf.actions.open_case.condition.type = 'always'
     return m
    def setUp(self):
        self.app = Application.new_app('domain', "Untitled Application", application_version=APP_V2)
        self.app.build_langs = self.app.langs = ['en', 'afr', 'fra']
        module1 = self.app.add_module(Module.new_module('module', None))
        form1 = self.app.new_form(module1.id, "Untitled Form", None)
        form1.source = self.get_xml('initial_xform')

        self.form1_worksheet = self.get_worksheet('module1_form1')
Пример #29
0
 def setUpClass(cls):
     cls.domain = 'app-manager-analytics-test'
     cls.app = Application.new_app(cls.domain, "My App")
     cls.app.add_module(Module.new_module("My Module", 'en'))
     cls.app.get_module(0).new_form("My Form", 'en')
     cls.app.get_module(0).get_form(0).xmlns = 'myxmlns'
     cls.app.save()
     cls.app_id = cls.app.get_id
     update_analytics_indexes()
Пример #30
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.app = Application.new_app('domain', 'New App')
        self.app.version = 3
        self.fish_module = self.app.add_module(Module.new_module('Fish Module', lang='en'))
        self.fish_module.case_type = 'fish'
        self.fish_form = self.app.new_form(0, 'New Form', lang='en')
        self.fish_form.source = self.get_xml('original')

        self.freshwater_module = self.app.add_module(Module.new_module('Freshwater Module', lang='en'))
        self.freshwater_module.case_type = 'freshwater'
        self.freshwater_form = self.app.new_form(0, 'New Form', lang='en')
        self.freshwater_form.source = self.get_xml('original')

        self.aquarium_module = self.app.add_module(Module.new_module('Aquarium Module', lang='en'))
        self.aquarium_module.case_type = 'aquarium'
Пример #31
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.app = Application.new_app('domain', 'New App', APP_V2)
        self.app.version = 3
        self.fish_module = self.app.add_module(Module.new_module('Fish Module', lang='en'))
        self.fish_module.case_type = 'fish'
        self.fish_form = self.app.new_form(0, 'New Form', lang='en')
        self.fish_form.source = self.get_xml('original')

        self.freshwater_module = self.app.add_module(Module.new_module('Freshwater Module', lang='en'))
        self.freshwater_module.case_type = 'freshwater'
        self.freshwater_form = self.app.new_form(0, 'New Form', lang='en')
        self.freshwater_form.source = self.get_xml('original')

        self.aquarium_module = self.app.add_module(Module.new_module('Aquarium Module', lang='en'))
        self.aquarium_module.case_type = 'aquarium'
Пример #32
0
    def create_two_module_app(self, domain_name, app_name):

        app = Application.new_app(domain_name, app_name)
        app.add_module(Module.new_module('Module 1', None))
        app.add_module(Module.new_module('Module 2', None))

        for m_id in range(2):
            app.new_form(m_id, "Form", None)

        app.save()

        print(
            "Application {app_name}: {app_url} created in domain {domain_name}"
            .format(app_name=app_name,
                    app_url=reverse('view_app',
                                    args=[domain_name, app._id],
                                    absolute=True),
                    domain_name=domain_name))
Пример #33
0
 def setUp(self):
     self.app = Application.new_app('domain', 'New App')
     self.app.version = 3
     self.module = self.app.add_module(
         Module.new_module('New Module', lang='en'))
     self.form = self.app.new_form(0, 'New Form', lang='en')
     self.module.case_type = 'test_case_type'
     self.form.source = self.get_xml('original_form',
                                     override_path=('data', ))
 def setUpClass(cls):
     super(TestZapierIntegration, cls).setUpClass()
     cls.domain = TEST_DOMAIN
     cls.domain_object, cls.web_user, cls.api_key = bootrap_domain_for_zapier(cls.domain)
     cls.application = Application.new_app(cls.domain, 'Test App')
     cls.application.save()
     module = cls.application.add_module(Module.new_module("Module 1", "en"))
     cls.application.new_form(module.id, name="Form1", attachment=XFORM, lang="en")
     cls.application.save()
 def setUp(self):
     self.app = Application.new_app("domain", "New App", APP_V2)
     self.app.version = 3
     self.module = self.app.add_module(Module.new_module("New Module", lang="en"))
     self.form = self.app.new_form(0, "New Form", lang="en")
     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()
Пример #36
0
    def test_case_detail_icon_mapping(self):
        app = Application.new_app('domain',
                                  'Untitled Application',
                                  application_version=APP_V2)

        module = app.add_module(Module.new_module('Untitled Module', None))
        module.case_type = 'patient'

        module.case_details.short.columns = [
            DetailColumn(
                header={'en': 'Age range'},
                model='case',
                field='age',
                format='enum-image',
                enum=[
                    MappingItem(key='10',
                                value={'en': 'jr://icons/10-year-old.png'}),
                    MappingItem(key='age > 50',
                                value={'en': 'jr://icons/old-icon.png'}),
                ],
            ),
        ]

        key1_varname = '10'
        key2_varname = hashlib.md5('age > 50').hexdigest()[:8]

        icon_mapping_spec = """
            <partial>
              <template form="image" width="13%">
                <text>
                  <xpath function="if(age = '10', $k{key1_varname}, if(age > 50, $h{key2_varname}, ''))">
                    <variable name="h{key2_varname}">
                      <locale id="m0.case_short.case_age_1.enum.h{key2_varname}"/>
                    </variable>
                    <variable name="k{key1_varname}">
                      <locale id="m0.case_short.case_age_1.enum.k{key1_varname}"/>
                    </variable>
                  </xpath>
                </text>
              </template>
            </partial>
        """.format(
            key1_varname=key1_varname,
            key2_varname=key2_varname,
        )
        # check correct suite is generated
        self.assertXmlPartialEqual(icon_mapping_spec, app.create_suite(),
                                   './detail/field/template[@form="image"]')
        # check icons map correctly
        app_strings = commcare_translations.loads(app.create_app_strings('en'))
        self.assertEqual(
            app_strings['m0.case_short.case_age_1.enum.h{key2_varname}'.format(
                key2_varname=key2_varname, )], 'jr://icons/old-icon.png')
        self.assertEqual(
            app_strings['m0.case_short.case_age_1.enum.k{key1_varname}'.format(
                key1_varname=key1_varname, )], 'jr://icons/10-year-old.png')
Пример #37
0
    def test_overwrite_filter_column(self):
        dest_module = self.app.add_module(
            Module.new_module('Dest Module', lang='en'))
        dest_detail = getattr(dest_module.case_details, "short")
        dest_detail.overwrite_attrs(self.src_detail, self.cols_and_filter)

        self.assertEqual(self.src_detail.columns, dest_detail.columns)
        self.assertEqual(self.src_detail.filter, dest_detail.filter)
        self.remove_attrs(dest_detail)
        self.assertNotEqual(self.src_detail.to_json(), dest_detail.to_json())
    def setUp(self):
        self.app = Application.new_app('domain',
                                       "Untitled Application",
                                       application_version=APP_V2)
        self.app.langs = ['en', 'afr', 'fra']
        module1 = self.app.add_module(Module.new_module('module', None))
        form1 = self.app.new_form(module1.id, "Untitled Form", None)
        form1.source = self.get_xml('initial_xform')

        self.form1_worksheet = self.get_worksheet('module1_form1')
    def setUp(self):
        create_domain(self.domain)
        couch_user = CommCareUser.create(self.domain, self.username, self.password)
        userID = couch_user.user_id
        couch_user.first_name = self.first_name
        couch_user.last_name = self.last_name
        couch_user.save()
        self.sm = SuccessMessage(self.message, userID, tz=self.tz)

        c = Client()

        app = Application.new_app(self.domain, "Test App", application_version=APP_V1)
        app.add_module(Module.new_module("Test Module", "en"))
        form = app.new_form(0, "Test Form", "en")
        form.xmlns = self.xmlns
        app.success_message = {"en": self.message}
        app.save()
        # hack: prime the view once so the success message takes even though we use stale queries in submissions
        Application.get_db().view('exports_forms/by_xmlns', limit=1).one()
        def fake_form_submission(userID=userID, username=self.username, xmlns=self.xmlns, time=None):
            submission = submission_template % {
                "userID": userID,
                "username": username,
                "xmlns": xmlns
            }
            f = StringIO(submission.encode('utf-8'))
            f.name = "tempfile.xml"
            kwargs = dict(HTTP_X_SUBMIT_TIME=json_format_datetime(time)) if time else {}
            response = c.post("/a/{self.domain}/receiver/".format(self=self), {
                'xml_submission_file': f,
            }, **kwargs)
            return response

        self.num_forms_today = 0
        self.num_forms_this_week = 0
        now = datetime.utcnow()
        tznow = now + self.tz
        week_start = tznow - timedelta(days=tznow.weekday())
        week_start = datetime(week_start.year, week_start.month, week_start.day) - self.tz
        day_start = datetime(tznow.year, tznow.month, tznow.day) - self.tz
        spacing = 6
        for h in xrange((24/spacing)*8):
            time = now-timedelta(hours=spacing*h)
            response = fake_form_submission(time=time)
            if time > week_start:
                self.num_forms_this_week += 1
            if time > day_start:
                self.num_forms_today += 1
            self.assertEqual(
                response.content,
                get_simple_response_xml(("Thanks {self.first_name} ({self.first_name} {self.last_name})! "
                "You have submitted {self.num_forms_today} forms today "
                "and {self.num_forms_this_week} forms since Monday.").format(self=self),
                    nature=ResponseNature.SUBMIT_SUCCESS)
            )
Пример #40
0
    def test_subcase_repeat_mixed_form(self):
        app = Application.new_app(None, "Untitled Application")
        module_0 = app.add_module(Module.new_module('parent', None))
        module_0.unique_id = 'm0'
        module_0.case_type = 'parent'
        form = app.new_form(
            0,
            "Form",
            None,
            attachment=self.get_xml('subcase_repeat_mixed_form_pre').decode(
                'utf-8'))

        module_1 = app.add_module(Module.new_module('subcase', None))
        module_1.unique_id = 'm1'
        module_1.case_type = 'subcase'

        form.actions.open_case = OpenCaseAction(
            name_update=ConditionalCaseUpdate(
                question_path="/data/parent_name"))
        form.actions.open_case.condition.type = 'always'

        form.actions.subcases.append(
            OpenSubCaseAction(case_type=module_1.case_type,
                              name_update=ConditionalCaseUpdate(
                                  question_path="/data/first_child_name"),
                              condition=FormActionCondition(type='always')))
        # subcase in the middle that has a repeat context
        form.actions.subcases.append(
            OpenSubCaseAction(
                case_type=module_1.case_type,
                name_update=ConditionalCaseUpdate(
                    question_path="/data/repeat_child/repeat_child_name"),
                repeat_context='/data/repeat_child',
                condition=FormActionCondition(type='always')))
        form.actions.subcases.append(
            OpenSubCaseAction(case_type=module_1.case_type,
                              name_update=ConditionalCaseUpdate(
                                  question_path="/data/last_child_name"),
                              condition=FormActionCondition(type='always')))

        self.assertXmlEqual(self.get_xml('subcase_repeat_mixed_form_post'),
                            app.get_module(0).get_form(0).render_xform())
Пример #41
0
 def new_module_for_app(self, app, subject_module):
     """
     Return a CommCare module
     """
     module = app.add_module(Module.new_module(self.name, None))
     module.unique_id = self.unique_id
     module.case_type = 'event'
     module.root_module_id = subject_module.unique_id
     module.parent_select.active = True
     module.parent_select.module_id = subject_module.unique_id
     return module
Пример #42
0
 def setUp(self):
     self.domain = Domain(name='test')
     self.domain.save()
     app = Application.new_app('test',
                               "Test Application",
                               lang='en',
                               application_version=APP_V2)
     module = Module.new_module("Untitled Module", 'en')
     app.add_module(module)
     app.new_form(0, "Untitled Form", 'en')
     app.save()
Пример #43
0
    def test_overwrite_other_configs(self):
        dest_module = self.app.add_module(
            Module.new_module('Dest Module', lang='en'))
        dest_detail = getattr(dest_module.case_details, "short")
        dest_detail.overwrite_attrs(self.src_detail, self.case_tile)

        self.assertNotEqual(str(self.src_detail.columns),
                            str(dest_detail.columns))
        self.assertNotEqual(self.src_detail.filter, dest_detail.filter)
        self.assertEqual(self.src_detail.persist_tile_on_forms,
                         dest_detail.persist_tile_on_forms)
Пример #44
0
    def setUp(self):
        self.app = Application.new_app('domain', 'New App', APP_V2)
        self.app.version = 3
        self.module = self.app.add_module(Module.new_module('New Module', lang='en'))
        self.form = self.app.new_form(0, 'New Form', lang='en')
        self.module.case_type = 'test_case_type'
        self.form.source = self.get_xml('original')
        self.form.actions.open_case = OpenCaseAction(name_path="/data/question1", external_id=None)
        self.form.actions.open_case.condition.type = 'always'

        self.careplan_module = new_careplan_module(self.app, None, None, self.module)
Пример #45
0
 def _add_form_with_report_reference(self, app, report_app_config):
     other_module = app.add_module(Module.new_module('m0', None))
     form = other_module.new_form('f0', None)
     report_reference = "instance('commcare-reports:{}')/rows/row[0]/@index".format(report_app_config.report_slug)
     form.source = self.get_xml('very_simple_form').decode('utf-8')
     form.source = form.source.replace(
         """<bind nodeset="/data/question1" type="xsd:string"/>""",
         """<bind nodeset="/data/question1" type="xsd:string" calculate="{}"/>""".format(report_reference),
     )
     app.save()
     return form
Пример #46
0
    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'
Пример #47
0
    def test_basic_app(self, mock1, mock2):
        module = self.app.add_module(Module.new_module("Module0", "en"))
        form = self.app.new_form(
            module.id,
            "Form0",
            "en",
            attachment=BLANK_TEMPLATE.format(xmlns='xmlns-0.0'))
        self.app.save()
        self._send_to_es(self.app)

        kwargs = {
            'domain': self.project.name,
            'app_id': self.app.id,
        }
        self._test_status_codes([
            'view_app',
            'release_manager',
            AppCaseSummaryView.urlname,
            AppFormSummaryView.urlname,
        ], kwargs)

        build = self.app.make_build()
        build.save()
        self._send_to_es(build)

        content = self._json_content_from_get('current_app_version', {
            'domain': self.project.name,
            'app_id': self.app.id,
        })
        self.assertEqual(content['currentVersion'], 1)
        self.app.save()
        self._send_to_es(self.app)

        content = self._json_content_from_get('current_app_version', {
            'domain': self.project.name,
            'app_id': self.app.id,
        })
        self.assertEqual(content['currentVersion'], 2)

        content = self._json_content_from_get('paginate_releases', {
            'domain': self.project.name,
            'app_id': self.app.id,
        }, {'limit': 5})
        self.assertEqual(len(content['apps']), 1)
        content = content['apps'][0]
        self.assertEqual(content['copy_of'], self.app.id)

        kwargs['module_unique_id'] = module.unique_id
        self._test_status_codes(['view_module'], kwargs)

        del kwargs['module_unique_id']
        kwargs['form_unique_id'] = form.unique_id
        self._test_status_codes(['view_form', 'form_source'], kwargs)
 def setUp(self):
     self.app = Application.new_app(DOMAIN, "Untitled Application")
     self.module = self.app.add_module(
         Module.new_module("Untitled Module", None))
     self.app.new_form(0, "Untitled Form", None)
     self.module.case_type = 'case'
     self.module.search_config = CaseSearch(
         command_label={'en': 'Search Patients Nationally'},
         properties=[
             CaseSearchProperty(name='name', label={'en': 'Name'}),
             CaseSearchProperty(name='dob', label={'en': 'Date of birth'})
         ])
Пример #49
0
 def _make_module(self, app, module_id, case_type):
     m = app.add_module(
         Module.new_module('Module{}'.format(module_id), lang='en'))
     m.case_type = case_type
     mf = app.new_form(module_id,
                       'form {}'.format(case_type),
                       lang='en',
                       attachment=self.get_xml('standard_questions'))
     mf.actions.open_case = OpenCaseAction(name_path="/data/question1",
                                           external_id=None)
     mf.actions.open_case.condition.type = 'always'
     return m
Пример #50
0
    def test_update_from_specific_build(self, *args):
        master_app = Application.new_app(self.domain, "Master Application")
        master_app.save()
        self.addCleanup(master_app.delete)

        linked_app = LinkedApplication.new_app(self.linked_domain,
                                               "Linked Application")
        linked_app.save()
        self.addCleanup(linked_app.delete)

        master_app.add_module(Module.new_module('M1', None))
        copy1 = self._make_build(master_app, True)

        master_app.add_module(Module.new_module('M2', None))
        master_app.save()  # increment version number
        self._make_build(master_app, True)

        update_linked_app(linked_app, copy1, 'test_update_from_specific_build')
        linked_app = LinkedApplication.get(linked_app._id)
        self.assertEqual(len(linked_app.modules), 1)
        self.assertEqual(linked_app.version, copy1.version)
Пример #51
0
    def test_module_filter_with_session(self):
        app = Application.new_app('domain', "Untitled Application")
        app.build_spec.version = '2.20.0'
        module = app.add_module(Module.new_module('m0', None))
        form = module.new_form('f0', None)
        form.xmlns = 'f0-xmlns'

        module.module_filter = "#session/user/mod/filter = '123'"
        self.assertXmlPartialEqual(self.get_xml('module-filter-user'),
                                   app.create_suite(), "./menu[@id='m0']")
        self.assertXmlPartialEqual(self.get_xml('module-filter-user-entry'),
                                   app.create_suite(), "./entry[1]")
Пример #52
0
    def test_module_filter(self):
        """
        Ensure module filter gets added correctly
        """
        app = Application.new_app('domain', "Untitled Application")
        app.build_spec.version = '2.20.0'
        module = app.add_module(Module.new_module('m0', None))
        module.new_form('f0', None)

        module.module_filter = "/mod/filter = '123'"
        self.assertXmlPartialEqual(self.get_xml('module-filter'),
                                   app.create_suite(), "./menu[@id='m0']")
Пример #53
0
    def setUp(self):
        self.all_attrs = [
            'search_properties', 'search_default_properties',
            'search_claim_options'
        ]

        self.app = Application.new_app('domain', "Untitled Application")
        self.src_module = self.app.add_module(
            Module.new_module('Src Module', lang='en'))
        self.case_search_config = CaseSearch(
            search_label=CaseSearchLabel(
                label={'en': 'Search Patients Nationally'}),
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='dob', label={'en': 'Date of birth'})
            ],
            auto_launch=True,
            default_search=True,
            additional_relevant="instance('groups')/groups/group",
            search_filter=
            "name = instance('item-list:trees')/trees_list/trees[favorite='yes']/name",
            search_button_display_condition="false()",
            blacklisted_owner_ids_expression=
            "instance('commcaresession')/session/context/userid",
            default_properties=[
                DefaultCaseSearchProperty(
                    property='ɨŧsȺŧɍȺᵽ',
                    defaultValue=
                    ("instance('casedb')/case"
                     "[@case_id='instance('commcaresession')/session/data/case_id']/ɨŧsȺŧɍȺᵽ"
                     )),
                DefaultCaseSearchProperty(
                    property='name',
                    defaultValue=
                    "instance('locations')/locations/location[@id=123]/@type"),
            ],
        )
        self.src_module.search_config = self.case_search_config
        self.dest_module = self.app.add_module(
            Module.new_module('Dest Module', lang='en'))
Пример #54
0
    def setUp(self):
        self.attrs_dict1 = {
            'columns': True,
            'filter': True,
            'sort_elements': True,
            'sort_nodeset_columns': True,
            'custom_variables': True,
            'custom_xml': True,
            'case_tile_configuration': True,
            'print_template': True
        }
        self.attrs_dict2 = {
            'columns': True,
            'filter': True,
            'sort_elements': False,
            'sort_nodeset_columns': False,
            'custom_variables': False,
            'custom_xml': False,
            'case_tile_configuration': False,
            'print_template': False
        }
        self.attrs_dict3 = {
            'columns': False,
            'filter': False,
            'sort_elements': False,
            'sort_nodeset_columns': False,
            'custom_variables': False,
            'custom_xml': False,
            'case_tile_configuration': True,
            'print_template': False
        }

        self.app = Application.new_app('domain', "Untitled Application")
        self.src_module = self.app.add_module(
            Module.new_module('Src Module', lang='en'))
        self.src_module_detail_type = getattr(self.src_module.case_details,
                                              "short")
        self.header_ = getattr(self.src_module_detail_type.columns[0],
                               'header')
        self.header_['en'] = 'status'
        self.filter_ = setattr(self.src_module_detail_type, 'filter', 'a > b')
        self.sort_nodeset_columns = setattr(self.src_module_detail_type,
                                            'sort_nodeset_columns', True)
        self.custom_variables = setattr(self.src_module_detail_type,
                                        'custom_variables', 'def')
        self.custom_xml = setattr(self.src_module_detail_type, 'custom_xml',
                                  'ghi')
        self.print_template = getattr(self.src_module_detail_type,
                                      'print_template')
        self.print_template['name'] = 'test'
        self.case_tile_configuration = setattr(self.src_module_detail_type,
                                               'persist_tile_on_forms', True)
Пример #55
0
    def test_child_module_adjusted_datums_basic_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(Module.new_module('New Module',
                                                       lang='en'))
        module.case_type = 'guppy'
        form = module.new_form(
            "Untitled Form", "en",
            self.get_xml('original_form',
                         override_path=('data', )).decode('utf-8'))

        form.requires = 'case'
        form.actions.update_case = UpdateCaseAction(
            update={'question1': '/data/question1'})
        form.actions.update_case.condition.type = 'always'

        root_module = self.app.add_module(
            Module.new_module('root module', None))
        root_module.unique_id = 'm_root'
        root_module.case_type = 'test_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

        module.parent_select.active = True
        module.parent_select.module_id = root_module.unique_id

        self.assertXmlEqual(
            self.get_xml('child_module_adjusted_case_id_basic'),
            form.render_xform())
Пример #56
0
    def test_overwrite_app_override_form_unique_ids(self):
        module = self.master1.add_module(Module.new_module('M1', None))
        master_form = module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        add_xform_resource_overrides(self.linked_domain, self.linked_app.get_id, {master_form.unique_id: '123'})
        overwrite_app(self.linked_app, self.master1)

        self.assertEqual(
            {master_form.xmlns: '123'},
            self._get_form_ids_by_xmlns(LinkedApplication.get(self.linked_app._id))
        )

        ResourceOverride.objects.filter(domain=self.linked_domain, app_id=self.linked_app.get_id).delete()
Пример #57
0
 def add_form(self, app, case_type=None, module_id=None):
     if module_id is None:
         module_id = len(app.modules)
         m = app.add_module(
             Module.new_module('Module{}'.format(module_id), lang='en'))
         if case_type:
             m.case_type = case_type
     form = app.new_form(module_id, 'form {}'.format(case_type), lang='en')
     if case_type:
         form.actions.open_case = OpenCaseAction(
             name_path="/data/question1", external_id=None)
         form.actions.open_case.condition.type = 'always'
     return form
Пример #58
0
    def test_careplan_module(self):
        target_module = self.app.add_module(Module.new_module("Module0", "en"))
        target_module.case_type = 'person'

        module = new_careplan_module(self.app, 'Module1', 'en', target_module)

        self.app.save()
        self._test_status_codes(
            ['view_module'], {
                'domain': self.domain.name,
                'app_id': self.app.id,
                'module_id': module.id,
            })
Пример #59
0
    def test_overwrite_other_configs(self):
        dest_module = self.app.add_module(
            Module.new_module('Dest Module', lang='en'))
        dest_module_detail_type = getattr(dest_module.case_details, "short")
        dest_module_detail_type.overwrite_from_module_detail(
            self.src_module_detail_type, self.attrs_dict3)

        self.assertNotEqual(str(self.src_module_detail_type.columns),
                            str(dest_module_detail_type.columns))
        self.assertNotEqual(self.src_module_detail_type.filter,
                            dest_module_detail_type.filter)
        self.assertEqual(self.src_module_detail_type.persist_tile_on_forms,
                         dest_module_detail_type.persist_tile_on_forms)
Пример #60
0
    def test_usercase_id_added_preload(self):
        app = Application.new_app('domain', "Untitled Application")

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

        child_form = app.new_form(0, "Untitled Form", None)
        child_form.xmlns = 'http://id_m1-f0'
        child_form.requires = 'case'
        child_form.actions.usercase_preload = PreloadAction(preload={'/data/question1': 'name'})
        child_form.actions.usercase_preload.condition.type = 'always'

        self.assertXmlPartialEqual(self.get_xml('usercase_entry'), app.create_suite(), "./entry[1]")