Beispiel #1
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)
Beispiel #2
0
    def setUpClass(cls):
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(
                Application(domain=cls.domain,
                            name='foo',
                            version=1,
                            modules=[Module()]).to_json()),
            RemoteApp.wrap(
                RemoteApp(domain=cls.domain, version=1, name='bar').to_json()),
        ]
        for app in cls.apps:
            app.save()
Beispiel #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 = [
            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()
Beispiel #4
0
    def setUpClass(cls):
        super(TestGlobalAppConfig, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        cls.build_profile_id = 'english'
        app = Application(
            domain=cls.domain,
            name='foo',
            langs=["en"],
            version=1,
            modules=[Module()],
            build_profiles={
                cls.build_profile_id: BuildProfile(langs=['en'], name='English only'),
            }
        )  # app is v1

        app.save()  # app is now v2

        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # v2 is starred

        app.save()  # app is now v3
        cls.v3_build = app.make_build()
        cls.v3_build.is_released = True
        cls.v3_build.save()  # v3 is starred

        app.save()  # app is v4

        # Add a build-profile-specific release at v2
        cls.latest_profile = LatestEnabledBuildProfiles(
            domain=cls.domain,
            app_id=app.get_id,
            build_profile_id=cls.build_profile_id,
            version=cls.v2_build.version,
            build_id=cls.v2_build.get_id,
            active=True,
        )
        cls.latest_profile.save()

        cls.app = app
    def setUpClass(cls):
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        app_doc = Application(domain=cls.domain,
                              name='foo',
                              langs=["en"],
                              version=1,
                              modules=[Module()]).to_json()
        app = Application.wrap(app_doc)  # app is v1

        app.save()  # app is v2
        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # There is a starred build at v2

        app.save()  # app is v3
        app.make_build().save()  # There is a build at v3

        app.save()  # app is v4
        cls.app_id = app._id
    def setUpClass(cls):
        super(TestLatestAppInfo, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        app = Application(domain=cls.domain,
                          name='foo',
                          langs=["en"],
                          version=1,
                          modules=[Module()])  # app is v1

        app.save()  # app is v2
        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()  # There is a starred build at v2

        app.save()  # app is v3
        app.make_build().save()  # There is a build at v3

        app.save()  # app is v4
        cls.app = app
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()
        cls.first_saved_version = 2
        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(
                Application(domain=cls.domain,
                            name='foo',
                            version=1,
                            modules=[Module()]).to_json()),
            RemoteApp.wrap(
                RemoteApp(domain=cls.domain, version=1, name='bar').to_json()),
        ]
        for app in cls.apps:
            app.save()

        cls.decoy_apps = [
            # this one is a build
            Application(
                domain=cls.domain,
                copy_of=cls.apps[0].get_id,
                version=cls.first_saved_version,
                has_submissions=True,
            ),
            # this one is another build
            Application(domain=cls.domain,
                        copy_of=cls.apps[0].get_id,
                        version=12),

            # this one is another app
            Application(domain=cls.domain, copy_of='1234', version=12),
            # this one is in the wrong domain
            Application(domain='decoy-domain', version=5)
        ]
        for app in cls.decoy_apps:
            app.save()
Beispiel #8
0
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.project = Domain.get_or_create_with_name(cls.domain, is_active=True)
        cls.first_saved_version = 2

        cls.normal_app = Application.wrap(
            Application(domain=cls.domain, name='foo', version=1, modules=[Module()]).to_json()
        )
        cls.normal_app.save()

        cls.remote_app = RemoteApp.wrap(RemoteApp(domain=cls.domain, version=1, name='bar').to_json())
        cls.remote_app.save()

        cls.linked_app = LinkedApplication.wrap(
            LinkedApplication(domain=cls.domain, version=1, name='linked-app', upstream_app_id='abc123').to_json()
        )
        cls.linked_app.save()

        cls.decoy_apps = [
            # this one is a build
            Application(
                domain=cls.domain,
                copy_of=cls.normal_app.get_id,
                version=cls.first_saved_version,
                has_submissions=True,
            ),
            # this one is another build
            Application(domain=cls.domain, copy_of=cls.normal_app.get_id, version=12),

            # this one is another app
            Application(domain=cls.domain, copy_of='1234', version=12),
            # this one is in the wrong domain
            Application(domain='decoy-domain', version=5)
        ]
        for app in cls.decoy_apps:
            app.save()
Beispiel #9
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])