def test_update_form_references_form_link(self):
        app = Application.new_app('domain', 'Foo')
        app.modules.append(Module(forms=[Form()]))
        app.modules.append(Module(forms=[Form(), Form()]))
        app.build_spec = BuildSpec.from_string('2.7.0/latest')
        app.get_module(0).get_form(0).source = get_simple_form(
            xmlns='xmlns-0.0')
        app.get_module(1).get_form(0).source = get_simple_form(xmlns='xmlns-1')

        original_form_id1 = app.get_module(1).get_form(0).unique_id
        original_form_id2 = app.get_module(1).get_form(1).unique_id
        app.get_module(0).get_form(0).form_links = [
            FormLink(xpath="", form_id=original_form_id1),
            FormLink(xpath="", form_id=original_form_id2),
        ]

        copy = Application.from_source(app.export_json(dump_json=False),
                                       'domain')
        new_form_id1 = copy.get_module(1).get_form(0).unique_id
        new_form_id2 = copy.get_module(1).get_form(1).unique_id
        self.assertNotEqual(original_form_id1, new_form_id1)
        self.assertNotEqual(original_form_id2, new_form_id2)
        self.assertEqual(new_form_id1,
                         copy.get_module(0).get_form(0).form_links[0].form_id)
        self.assertEqual(new_form_id2,
                         copy.get_module(0).get_form(0).form_links[1].form_id)
    def test_update_form_references_case_list_form(self):
        app = Application.new_app('domain', 'Foo')
        app.modules.append(Module(forms=[Form()]))
        app.modules.append(Module(forms=[Form()]))
        app.build_spec = BuildSpec.from_string('2.7.0/latest')
        app.get_module(0).get_form(0).source = get_simple_form(
            xmlns='xmlns-0.0')
        app.get_module(1).get_form(0).source = get_simple_form(xmlns='xmlns-1')

        original_form_id = app.get_module(1).get_form(0).unique_id
        app.get_module(0).case_list_form.form_id = original_form_id

        copy = Application.from_source(app.export_json(dump_json=False),
                                       'domain')
        new_form_id = copy.get_module(1).get_form(0).unique_id
        self.assertNotEqual(original_form_id, new_form_id)
        self.assertEqual(new_form_id,
                         copy.get_module(0).case_list_form.form_id)
Example #3
0
    def setUpClass(cls):
        super(ExportsFormsAnalyticsTest, cls).setUpClass()
        from casexml.apps.case.tests.util import delete_all_xforms
        from corehq.apps.app_manager.models import Application, Module, Form
        delete_all_xforms()

        with trap_extra_setup(ConnectionError,
                              msg="cannot connect to elasicsearch"):
            cls.es = get_es_new()
            initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO)

        cls.domain = 'exports_forms_analytics_domain'
        cls.app_id_1 = 'a' + uuid.uuid4().hex
        cls.app_id_2 = 'b' + uuid.uuid4().hex
        cls.xmlns_1 = 'my://crazy.xmlns/'
        cls.xmlns_2 = 'my://crazy.xmlns/app'
        cls.apps = [
            Application(_id=cls.app_id_2,
                        domain=cls.domain,
                        modules=[Module(forms=[Form(xmlns=cls.xmlns_2)])])
        ]
        for app in cls.apps:
            app.save()
        cls.forms = [
            create_form_for_test(domain=cls.domain,
                                 app_id=cls.app_id_1,
                                 xmlns=cls.xmlns_1,
                                 save=False),
            create_form_for_test(domain=cls.domain,
                                 app_id=cls.app_id_1,
                                 xmlns=cls.xmlns_1,
                                 save=False),
            create_form_for_test(domain=cls.domain,
                                 app_id=cls.app_id_2,
                                 xmlns=cls.xmlns_2,
                                 save=False),
        ]
        cls.error_forms = [
            create_form_for_test(domain=cls.domain,
                                 state=XFormInstance.ERROR,
                                 save=False)
        ]
        cls.all_forms = cls.forms + cls.error_forms
        for form in cls.all_forms:
            elastic_form = transform_xform_for_elasticsearch(form.to_json())
            send_to_elasticsearch('forms', elastic_form)

        cls.es.indices.refresh(XFORM_INDEX_INFO.alias)
Example #4
0
    def test_repeat_subcases_schema_generation(self):
        module = Module(case_type='child', _parent=Application())
        form = Form().with_id(0, module)
        form.actions.subcases = [
            OpenSubCaseAction(
                repeat_context='/data/repeat',
                case_properties={
                    'weight':
                    ConditionalCaseUpdate(
                        question_path='/data/repeat/group/weight'),
                },
                subcase_index=0,
                _nest=True).with_id(0, None),
            OpenSubCaseAction(
                repeat_context='/data/repeat',
                case_properties={
                    'height':
                    ConditionalCaseUpdate(question_path='/data/repeat/height'),
                },
                subcase_index=1,
                _nest=True).with_id(1, None),
            OpenSubCaseAction(
                repeat_context='/data/repeat/nested_repeat',
                case_properties={
                    'age':
                    ConditionalCaseUpdate(
                        question_path='/data/repeat/nested_repeat/age'),
                },
                subcase_index=2,
                _nest=False).with_id(2, None),
        ]

        schema = FormExportDataSchema._add_export_items_for_cases(
            ExportGroupSchema(path=MAIN_TABLE),
            [form],
            ['/data/repeat', '/data/nested_repeat'],
        )[0]

        self.assertEqual(len(schema.group_schemas), len(form.actions.subcases))
        for group_schema, action in zip(schema.group_schemas,
                                        form.actions.subcases):
            base_path = 'form.{}'.format(action.repeat_context[6:].replace(
                '/', '.'))
            if action._nest:
                base_path += '.{}'.format(action.form_element_name)
            self._check_subcase_repeat_group_schema(
                group_schema, list(action.case_properties), base_path)
Example #5
0
    def setUpClass(cls):
        from casexml.apps.case.tests.util import delete_all_xforms
        from corehq.apps.app_manager.models import Application, Module, Form
        delete_all_xforms()

        with trap_extra_setup(ConnectionError,
                              msg="cannot connect to elasicsearch"):
            cls.es = get_es_new()
            initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO)

        cls.domain = 'exports_forms_analytics_domain'
        cls.app_id_1 = 'a' + uuid.uuid4().hex
        cls.app_id_2 = 'b' + uuid.uuid4().hex
        cls.xmlns_1 = 'my://crazy.xmlns/'
        cls.xmlns_2 = 'my://crazy.xmlns/app'
        cls.apps = [
            Application(_id=cls.app_id_2,
                        domain=cls.domain,
                        modules=[Module(forms=[Form(xmlns=cls.xmlns_2)])])
        ]
        for app in cls.apps:
            app.save()
        cls.forms = [
            XFormInstance(domain=cls.domain,
                          app_id=cls.app_id_1,
                          xmlns=cls.xmlns_1),
            XFormInstance(domain=cls.domain,
                          app_id=cls.app_id_1,
                          xmlns=cls.xmlns_1),
            XFormInstance(domain=cls.domain,
                          app_id=cls.app_id_2,
                          xmlns=cls.xmlns_2),
        ]
        cls.error_forms = [XFormError(domain=cls.domain)]
        cls.all_forms = cls.forms + cls.error_forms
        for form in cls.all_forms:
            form.save()
            send_to_elasticsearch('forms', form.to_json())

        cls.es.indices.refresh(XFORM_INDEX_INFO.index)
        update_analytics_indexes()
 def setUp(self):
     self.form = Form()
Example #7
0
    def test(self, mock):
        add_build(version='2.7.0', build_number=20655)
        domain = 'form-versioning-test'

        # set up inital app
        app = Application.new_app(domain, 'Foo')
        app.modules.append(Module(forms=[Form(), Form()]))
        app.build_spec = BuildSpec.from_string('2.7.0/latest')
        app.get_module(0).get_form(0).source = BLANK_TEMPLATE.format(
            xmlns='xmlns-0.0')
        app.get_module(0).get_form(1).source = BLANK_TEMPLATE.format(
            xmlns='xmlns-1')
        app.save()

        # make a build
        build1 = app.make_build()
        build1.save()

        # modify first form
        app.get_module(0).get_form(0).source = BLANK_TEMPLATE.format(
            xmlns='xmlns-0.1')
        app.save()

        # make second build
        build2 = app.make_build()
        build2.save()

        # modify first form
        app.get_module(0).get_form(0).source = BLANK_TEMPLATE.format(
            xmlns='xmlns-0.2')
        app.save()
        app.save()
        app.save()

        # make third build
        build3 = app.make_build()
        build3.save()

        self.assertEqual(self.get_form_versions(build1), [1, 1])
        self.assertEqual(self.get_form_versions(build2), [2, 1])
        self.assertEqual(self.get_form_versions(build3), [5, 1])

        # revert to build2
        app = app.make_reversion_to_copy(build2)
        app.save()

        # make reverted build
        build4 = app.make_build()
        build4.save()

        self.assertEqual(self.get_form_versions(build4), [6, 1])

        # copy app
        xxx_app = import_app(app.export_json(dump_json=False), domain)

        # make build of copy
        xxx_build1 = xxx_app.make_build()
        xxx_build1.save()

        # modify first form of copy app
        xxx_app.get_module(0).get_form(0).source = BLANK_TEMPLATE.format(
            xmlns='xmlns-0.xxx.0')
        xxx_app.save()

        # make second build of copy
        xxx_build2 = xxx_app.make_build()
        xxx_build2.save()

        self.assertEqual(self.get_form_versions(xxx_build1), [1, 1])
        self.assertEqual(self.get_form_versions(xxx_build2), [2, 1])