Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def setUp(self):
        self.set_up_app()
        self.releases_form.source = get_simple_form(
            xmlns=self.releases_form.xmlns)
        self.basic_form.source = get_simple_form(xmlns=self.basic_form.xmlns)
        self.factory.app.save()

        super(ReleaseNotesResourceFileTest, self).setUp()
Exemplo n.º 3
0
    def setUp(self):
        self.app = Application.new_app(DOMAIN, "Untitled Application")
        self.app._id = '123'
        self.app.build_spec = BuildSpec(version='2.53.0', build_number=1)
        self.module = self.app.add_module(Module.new_module("Followup", None))
        self.form = self.app.new_form(0, "Untitled Form", None, attachment=get_simple_form("xmlns1.0"))
        self.form.requires = 'case'
        self.module.case_type = 'case'

        self.module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "name"},
                model="case",
                format="plain",
                field="whatever",
            ))
        )

        self.module.search_config = CaseSearch(
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='favorite_color', label={'en': 'Favorite Color'}, itemset=Itemset(
                    instance_id='item-list:colors', instance_uri='jr://fixture/item-list:colors',
                    nodeset="instance('item-list:colors')/colors_list/colors",
                    label='name', sort='name', value='value'),
                )
            ],
            data_registry="myregistry",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
            additional_registry_cases=["'another case ID'"],
        )

        self.reg_module = self.app.add_module(Module.new_module("Registration", None))
        self.reg_form = self.app.new_form(1, "Untitled Form", None, attachment=get_simple_form("xmlns1.0"))
        self.reg_module.case_type = 'case'
        self.reg_form.actions.open_case = OpenCaseAction(
            name_update=ConditionalCaseUpdate(question_path="/data/question1")
        )
        self.reg_form.actions.open_case.condition.type = 'always'
        self.reg_form.post_form_workflow = WORKFLOW_FORM
        self.reg_form.form_links = [
            FormLink(form_id=self.form.get_unique_id())
        ]

        # wrap to have assign_references called
        self.app = Application.wrap(self.app.to_json())
        # reset to newly wrapped module
        self.module = self.app.modules[0]
        self.form = self.module.forms[0]
Exemplo n.º 4
0
    def setUpClass(cls):
        super(TestPaginateReleases, cls).setUpClass()
        cls.client = Client()

        cls.domain_name = "fandago"
        cls.domain = Domain.get_or_create_with_name(cls.domain_name, is_active=True)

        cls.username = '******'
        cls.password = '******'
        cls.user = WebUser.create(cls.domain.name, cls.username, cls.password, None, None, is_admin=True)
        cls.user.eula.signed = True
        cls.user.save()

        factory = AppFactory(cls.domain_name, name="cheeto")
        m0, f0 = factory.new_basic_module("register", "cheeto")
        f0.source = get_simple_form(xmlns=f0.unique_id)
        cls.app = factory.app
        cls.app.target_commcare_flavor = 'commcare_lts'
        cls.app.save()
        cls.app_build = cls.app.make_build()
        cls.app_build.is_released = True
        cls.app_build.save()

        # publish app and build to ES
        es = get_es_new()
        initialize_index_and_mapping(es, APP_INDEX_INFO)
        send_to_elasticsearch('apps', cls.app.to_json())
        send_to_elasticsearch('apps', cls.app_build.to_json())
        es.indices.refresh(APP_INDEX_INFO.index)
Exemplo n.º 5
0
    def setUpClass(cls):
        super(TestAppGetters, cls).setUpClass()
        cls.project = Domain.get_or_create_with_name(cls.domain)

        factory = AppFactory(cls.domain, name='foo')
        m0, f0 = factory.new_basic_module("bar", "bar")
        f0.source = get_simple_form(xmlns=f0.unique_id)
        app = factory.app
        app.version = 1

        # Make builds v1 - v5. Builds v2 and v4 are released.
        app.save()  # app is v2
        cls.v2_build = app.make_build()
        cls.v2_build.is_released = True
        cls.v2_build.save()

        app.save()  # app is v3
        app.make_build().save()

        app.save()  # app is v4
        cls.v4_build = app.make_build()
        cls.v4_build.is_released = True
        cls.v4_build.save()

        app.save()  # app is v5
        cls.app_id = app._id
Exemplo n.º 6
0
 def _create_app_and_build(cls):
     factory = AppFactory(domain=cls.domain_obj.name, name="API App")
     module1, form1 = factory.new_basic_module('open_case', 'house')
     form1.source = get_simple_form()
     app = factory.app
     app.save()
     build = app.make_build()
     build.save(increment_version=False)
     return app, build
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    def setUp(self):
        # re-fetch app
        factory1 = AppFactory(self.domain,
                              "First Upstream Application",
                              include_xmlns=True)
        m0_1, f0_1 = factory1.new_basic_module("M1", None)
        f0_1.source = get_simple_form(f0_1.xmlns)
        self.master1 = factory1.app
        self.master1.save()

        factory2 = AppFactory(self.domain,
                              "Second Upstream Application",
                              include_xmlns=True)
        m0_2, f0_2 = factory2.new_basic_module("M2", None)
        f0_2.source = get_simple_form(f0_2.xmlns)
        self.master2 = factory2.app
        self.master2.save()

        self.linked_app = LinkedApplication.new_app(self.linked_domain,
                                                    "Linked Application")
        self.linked_app.family_id = self.master1._id
        self.linked_app.save()
Exemplo n.º 9
0
    def test_update_from_specific_build(self, *args):
        factory = AppFactory(self.domain, "Upstream Application")
        m0, f0 = factory.new_basic_module("M1", None)
        f0.source = get_simple_form()
        master_app = factory.app
        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)

        copy1 = self._make_build(master_app, True)

        m1, f1 = factory.new_basic_module("M2", None)
        f1.source = get_simple_form()
        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)
Exemplo n.º 10
0
    def test_multi_master_copy_master(self, *args):
        '''
        This tests that when a master app A is copied to A' and the linked app is pulled from A',
        the linked app's form unique ids remain consistent, and form and multimedia versions
        do NOT increment just because of the copy.
        '''
        self.delete_modules(self.master1)

        # Add single module and form, with image, to master, and pull linked app.
        master1_module = self.master1.add_module(
            Module.new_module('Module for master', None))
        master1_module.new_form('Form for master', 'en',
                                get_simple_form('Form-for-master'))
        image_path = 'jr://file/commcare/photo.jpg'
        self.master1.create_mapping(CommCareImage(_id='123'), image_path)
        self.master1.get_module(0).set_icon('en', image_path)
        self._make_master1_build(True)
        self.linked_app.family_id = self.master1.get_id
        self.linked_app.save()
        self._pull_linked_app(self.master1.get_id)
        build1 = self._make_linked_build()

        # Make a copy of master and pull it.
        master_copy = import_app(self.master1.get_id, self.master1.domain)
        self._make_build(master_copy, True)
        self._pull_linked_app(master_copy.get_id)
        build2 = self._make_linked_build()

        # Verify form XMLNS, form version, and multimedia version all match.
        # Verify that form unique ids in linked app match ids in master app pulled from
        form1 = build1.get_module(0).get_form(0)
        form2 = build2.get_module(0).get_form(0)
        self.assertEqual(form1.xmlns, form2.xmlns)
        self.assertEqual(form1.unique_id,
                         self.master1.get_module(0).get_form(0).unique_id)
        self.assertEqual(form2.unique_id,
                         master_copy.get_module(0).get_form(0).unique_id)
        self.assertNotEqual(build1.version, build2.version)
        self.assertEqual(form1.get_version(), build1.version)
        self.assertEqual(form2.get_version(), build2.version)
        map_item1 = build1.multimedia_map[image_path]
        map_item2 = build2.multimedia_map[image_path]
        self.assertEqual(map_item1.unique_id, map_item2.unique_id)
        self.assertEqual(map_item1.version, map_item2.version)
Exemplo n.º 11
0
    def testGetLatestBuild(self):
        factory = AppFactory(build_version='2.40.0')
        m0, f0 = factory.new_basic_module('register', 'case')
        f0.source = get_simple_form(xmlns=f0.unique_id)
        app = factory.app
        app.save()

        build1 = app.make_build()
        build1.save()
        # ensure that there was no previous version used during the build process
        self.assertEqual(app.get_latest_build.get_cache(app), {})
        self.assertEqual(build1.get_latest_build.get_cache(build1), {(): None})

        app.save()
        build2 = app.make_build()
        build2.save()
        # ensure that there was no previous version used during the build process
        self.assertEqual(app.get_latest_build.get_cache(app), {})
        self.assertEqual(
            build2.get_latest_build.get_cache(build2)[()].id, build1.id)
Exemplo n.º 12
0
    def testConvertToApplication(self):
        factory = AppFactory(build_version='2.40.0')
        m0, f0 = factory.new_basic_module('register', 'case')
        f0.source = get_simple_form(xmlns=f0.unique_id)
        factory.app.save()
        self.addCleanup(factory.app.delete)
        build = factory.app.make_build()
        build.is_released = True
        build.save()
        self.addCleanup(build.delete)

        linked_app = LinkedApplication()
        linked_app.domain = 'other-domain'
        linked_app.save()
        self.addCleanup(linked_app.delete)

        link_app(linked_app, factory.app.domain, factory.app.id)
        update_linked_app(linked_app, factory.app.id, 'system')

        unlinked_doc = linked_app.convert_to_application().to_json()
        self.assertEqual(unlinked_doc['doc_type'], 'Application')
        self.assertFalse(hasattr(unlinked_doc, 'linked_app_attrs'))
Exemplo n.º 13
0
    def setUpClass(cls):
        super(TestGlobalAppConfig, cls).setUpClass()
        cls.project = Domain.get_or_create_with_name(cls.domain)

        cls.build_profile_id = 'english'
        factory = AppFactory(cls.domain, 'foo')
        m0, f0 = factory.new_basic_module("bar", "bar")
        f0.source = get_simple_form(xmlns=f0.unique_id)
        app = factory.app
        app.build_profiles = {
            cls.build_profile_id: BuildProfile(langs=['en'], name='English only'),
        }
        app.langs = ["en"]
        app.version = 1
        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
Exemplo n.º 14
0
    def test(self, mock):
        add_build(version='2.7.0', build_number=20655)
        domain = 'form-versioning-test'

        # set up inital app
        factory = AppFactory(domain, 'Foo')
        m0, f0 = factory.new_basic_module("bar", "bar")
        f0.source = get_simple_form(xmlns='xmlns-0.0')
        f1 = factory.new_form(m0)
        f1.source = get_simple_form(xmlns='xmlns-1')
        app = factory.app
        app.build_spec = BuildSpec.from_string('2.7.0/latest')
        app.save()

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

        # modify first form
        app.get_module(0).get_form(0).source = get_simple_form(
            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 = get_simple_form(
            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 = get_simple_form(
            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])
Exemplo n.º 15
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=get_simple_form(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)

        mock2.side_effect = XFormValidationError('')
        bad_form = self.app.new_form(
            module.id,
            "Form1",
            "en",
            attachment=INVALID_TEMPLATE.format(xmlns='xmlns-0.0'))
        kwargs['form_unique_id'] = bad_form.unique_id
        self.app.save()
        self._test_status_codes(['view_form', 'form_source'], kwargs)

        bad_form = self.app.new_form(module.id,
                                     "Form1",
                                     "en",
                                     attachment="this is not xml")
        kwargs['form_unique_id'] = bad_form.unique_id
        self.app.save()
        self._test_status_codes(['view_form', 'form_source'], kwargs)
Exemplo n.º 16
0
    def setUp(self):
        super().setUp()
        self.app = Application.new_app(DOMAIN, "Application with Shadow")
        self.app._id = '456'
        self.app.build_spec = BuildSpec(version='2.53.0', build_number=1)
        self.module = self.app.add_module(Module.new_module("Followup", None))
        self.form = self.app.new_form(0, "Untitled Form", None, attachment=get_simple_form("xmlns1.0"))
        self.form.requires = 'case'
        self.module.case_type = 'case'

        self.module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "name"},
                model="case",
                format="plain",
                field="whatever",
            ))
        )

        self.module.search_config = CaseSearch(
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='favorite_color', label={'en': 'Favorite Color'}, itemset=Itemset(
                    instance_id='item-list:colors', instance_uri='jr://fixture/item-list:colors',
                    nodeset="instance('item-list:colors')/colors_list/colors",
                    label='name', sort='name', value='value'),
                )
            ],
            data_registry="myregistry",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
            additional_registry_cases=["'another case ID'"],
        )

        self.shadow_module = self.app.add_module(ShadowModule.new_module("Shadow", "en"))
        self.shadow_module.source_module_id = self.module.unique_id

        self.shadow_module.case_details.long.columns.append(
            DetailColumn.wrap(dict(
                header={"en": "name"},
                model="case",
                format="plain",
                field="whatever",
            ))
        )

        self.shadow_module.search_config = CaseSearch(
            properties=[
                CaseSearchProperty(name='name', label={'en': 'Name'}),
                CaseSearchProperty(name='favorite_color', label={'en': 'Texture'}, itemset=Itemset(
                    instance_id='item-list:textures', instance_uri='jr://fixture/item-list:textures',
                    nodeset="instance('item-list:textures')/textures_list/textures",
                    label='name', sort='name', value='value'),
                )
            ],
            data_registry="myregistry",
            data_registry_workflow=REGISTRY_WORKFLOW_LOAD_CASE,
        )

        # wrap to have assign_references called
        self.app = Application.wrap(self.app.to_json())

        # reset to newly wrapped module
        self.module = self.app.modules[0]
        self.shadow_module = self.app.modules[1]
Exemplo n.º 17
0
 def setUp(self):
     factory = AppFactory("wizard", "Wizard's Handbook")
     m0, f0 = factory.new_basic_module("spells", "spell")
     f0.source = get_simple_form()
     self.app = factory.app
     self.app.save()