def clean_apk_version(self): # make sure it points to a valid BuildSpec apk_version = self.cleaned_data['apk_version'] if apk_version == LATEST_APK_VALUE: return apk_version try: BuildSpec.from_string(apk_version) return apk_version except ValueError: raise forms.ValidationError(_('Invalid APK version %(version)s'), params={'version': apk_version})
def clean_apk_version(self): # make sure it points to a valid BuildSpec apk_version = self.cleaned_data['apk_version'] if apk_version == LATEST_APK_VALUE: return apk_version try: BuildSpec.from_string(apk_version) return apk_version except ValueError: raise forms.ValidationError( _('Invalid APK version %(version)s'), params={'version': apk_version})
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 make_app(self, spec): app = Application.new_app('domain', "Untitled Application", application_version=APP_V2) app.build_spec = BuildSpec.from_string('2.9.0/latest') case_type = "frog" for m_spec in spec["m"]: m_type = m_spec['type'] m_class = Module if m_type == 'basic' else AdvancedModule module = app.add_module(m_class.new_module(m_spec['name'], None)) module.unique_id = m_spec['name'] module.case_type = m_spec.get("case_type", "frog") module.root_module_id = m_spec.get("parent", None) for f_spec in m_spec['f']: form_name = f_spec["name"] form = app.new_form(module.id, form_name, None) form.unique_id = form_name for a_spec in f_spec.get('actions', []): if isinstance(a_spec, dict): action = a_spec['action'] case_type = a_spec.get("case_type", case_type) parent = a_spec.get("parent", None) else: action = a_spec if 'open' == action: if m_type == "basic": form.actions.open_case = OpenCaseAction(name_path="/data/question1") form.actions.open_case.condition.type = 'always' else: form.actions.open_cases.append(AdvancedOpenCaseAction( case_type=case_type, case_tag='open_{}'.format(case_type), name_path='/data/name' )) elif 'update' == action: if m_type == "basic": form.requires = 'case' form.actions.update_case = UpdateCaseAction(update={'question1': '/data/question1'}) form.actions.update_case.condition.type = 'always' else: form.actions.load_update_cases.append(LoadUpdateAction( case_type=case_type, case_tag='update_{}'.format(case_type), parent_tag=parent, )) elif 'open_subacse': if m_type == "basic": form.actions.subcases.append(OpenSubCaseAction( case_type=case_type, case_name="/data/question1", condition=FormActionCondition(type='always') )) else: form.actions.open_cases.append(AdvancedOpenCaseAction( case_type=case_type, case_tag='subcase_{}'.format(case_type), name_path='/data/name', parent_tag=parent )) return app
def setUp(self): self.app = Application.new_app('domain', "my app", application_version=APP_V2) self.module = self.app.add_module(Module.new_module("Module 1", None)) self.form = self.app.new_form(0, "Form 1", None) self.min_spec = BuildSpec.from_string('2.21/latest') self.app.build_spec = self.min_spec
def setUpClass(cls): cls.domain = Domain(name='app-manager-testviews-domain', is_active=True) cls.domain.save() cls.username = '******' cls.password = '******' cls.user = WebUser.create(cls.domain.name, cls.username, cls.password, is_active=True) cls.user.is_superuser = True cls.user.save() cls.build = add_build(version='2.7.0', build_number=20655) cls.app = Application.new_app(cls.domain.name, "TestApp", application_version=APP_V1) cls.app.build_spec = BuildSpec.from_string('2.7.0/latest') toggles.CUSTOM_PROPERTIES.set("domain:{domain}".format(domain=cls.domain.name), True)
def get_latest_apk_version(self): from corehq.apps.app_manager.models import LATEST_APK_VALUE from corehq.apps.builds.models import BuildSpec from corehq.apps.builds.utils import get_default_build_spec if self.app.global_app_config.apk_prompt == "off": return {} else: configured_version = self.app.global_app_config.apk_version if configured_version == LATEST_APK_VALUE: value = get_default_build_spec().version else: value = BuildSpec.from_string(configured_version).version force = self.app.global_app_config.apk_prompt == "forced" return {"value": value, "force": force}
def get_latest_apk_version(self): from corehq.apps.app_manager.models import LATEST_APK_VALUE from corehq.apps.builds.models import BuildSpec from corehq.apps.builds.utils import get_default_build_spec if self.app.global_app_config.apk_prompt == "off": return {} else: configured_version = self.app.global_app_config.apk_version if configured_version == LATEST_APK_VALUE: value = get_default_build_spec().version else: value = BuildSpec.from_string(configured_version).version force = self.app.global_app_config.apk_prompt == "forced" return {"value": value, "force": force}
def test_suite_media_with_app_profile(self, *args): # Test that suite includes only media relevant to the profile app = Application.new_app('domain', "my app") app.add_module(Module.new_module("Module 1", None)) app.new_form(0, "Form 1", None) app.build_spec = BuildSpec.from_string('2.21.0/latest') app.build_profiles = OrderedDict({ 'en': BuildProfile(langs=['en'], name='en-profile'), 'hin': BuildProfile(langs=['hin'], name='hin-profile'), 'all': BuildProfile(langs=['en', 'hin'], name='all-profile'), }) app.langs = ['en', 'hin'] image_path = 'jr://file/commcare/module0_en.png' audio_path = 'jr://file/commcare/module0_en.mp3' app.get_module(0).set_icon('en', image_path) app.get_module(0).set_audio('en', audio_path) # Generate suites and default app strings for each profile suites = {} locale_ids = {} for build_profile_id in app.build_profiles.keys(): suites[build_profile_id] = app.create_suite(build_profile_id=build_profile_id) default_app_strings = app.create_app_strings('default', build_profile_id) locale_ids[build_profile_id] = {line.split('=')[0] for line in default_app_strings.splitlines()} # Suite should have only the relevant images media_xml = self.makeXML("modules.m0", "modules.m0.icon", "modules.m0.audio") self.assertXmlPartialEqual(media_xml, suites['all'], "././menu[@id='m0']/display") no_media_xml = self.XML_without_media("modules.m0") self.assertXmlPartialEqual(media_xml, suites['en'], "././menu[@id='m0']/display") no_media_xml = self.XML_without_media("modules.m0") self.assertXmlPartialEqual(no_media_xml, suites['hin'], "././menu[@id='m0']/text") # Default app strings should have only the relevant locales self.assertIn('modules.m0', locale_ids['all']) self.assertIn('modules.m0.icon', locale_ids['all']) self.assertIn('modules.m0.audio', locale_ids['all']) self.assertIn('modules.m0', locale_ids['en']) self.assertIn('modules.m0.icon', locale_ids['en']) self.assertIn('modules.m0.audio', locale_ids['en']) self.assertIn('modules.m0', locale_ids['hin']) self.assertNotIn('modules.m0.icon', locale_ids['hin']) self.assertNotIn('modules.m0.audio', locale_ids['hin'])
def test_suite_media_with_app_profile(self, *args): # Test that suite includes only media relevant to the profile app = Application.new_app('domain', "my app") app.add_module(Module.new_module("Module 1", None)) app.new_form(0, "Form 1", None) app.build_spec = BuildSpec.from_string('2.21.0/latest') app.build_profiles = OrderedDict({ 'en': BuildProfile(langs=['en'], name='en-profile'), 'hin': BuildProfile(langs=['hin'], name='hin-profile'), 'all': BuildProfile(langs=['en', 'hin'], name='all-profile'), }) app.langs = ['en', 'hin'] image_path = 'jr://file/commcare/module0_en.png' audio_path = 'jr://file/commcare/module0_en.mp3' app.get_module(0).set_icon('en', image_path) app.get_module(0).set_audio('en', audio_path) # Generate suites and default app strings for each profile suites = {} locale_ids = {} for build_profile_id in app.build_profiles.keys(): suites[build_profile_id] = app.create_suite(build_profile_id=build_profile_id) default_app_strings = app.create_app_strings('default', build_profile_id) locale_ids[build_profile_id] = {line.split('=')[0] for line in default_app_strings.splitlines()} # Suite should have only the relevant images media_xml = self.makeXML("modules.m0", "modules.m0.icon", "modules.m0.audio") self.assertXmlPartialEqual(media_xml, suites['all'], "././menu[@id='m0']/display") no_media_xml = self.XML_without_media("modules.m0") self.assertXmlPartialEqual(media_xml, suites['en'], "././menu[@id='m0']/display") no_media_xml = self.XML_without_media("modules.m0") self.assertXmlPartialEqual(no_media_xml, suites['hin'], "././menu[@id='m0']/text") # Default app strings should have only the relevant locales self.assertIn('modules.m0', locale_ids['all']) self.assertIn('modules.m0.icon', locale_ids['all']) self.assertIn('modules.m0.audio', locale_ids['all']) self.assertIn('modules.m0', locale_ids['en']) self.assertIn('modules.m0.icon', locale_ids['en']) self.assertIn('modules.m0.audio', locale_ids['en']) self.assertIn('modules.m0', locale_ids['hin']) self.assertNotIn('modules.m0.icon', locale_ids['hin']) self.assertNotIn('modules.m0.audio', locale_ids['hin'])
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 = BLANK_TEMPLATE.format(xmlns='xmlns-0.0') app.get_module(1).get_form(0).source = BLANK_TEMPLATE.format(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)
def setUpClass(cls): cls.domain = Domain(name='app-manager-testviews-domain', is_active=True) cls.domain.save() cls.username = '******' cls.password = '******' cls.user = WebUser.create(cls.domain.name, cls.username, cls.password, is_active=True) cls.user.is_superuser = True cls.user.save() cls.build = add_build(version='2.7.0', build_number=20655) cls.app = Application.new_app(cls.domain.name, "TestApp") cls.app.build_spec = BuildSpec.from_string('2.7.0/latest') toggles.CUSTOM_PROPERTIES.set( "domain:{domain}".format(domain=cls.domain.name), True)
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)
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 = BLANK_TEMPLATE.format(xmlns='xmlns-0.0') app.get_module(1).get_form(0).source = BLANK_TEMPLATE.format(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(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])
def setUp(self): self.app = Application.new_app("domain", "my app", application_version=APP_V2) self.module = self.app.add_module(Module.new_module("Module 1", None)) self.form = self.app.new_form(0, "Form 1", None) self.min_spec = BuildSpec.from_string("2.21/latest") self.app.build_spec = self.min_spec
def setUp(self): self.app = Application.new_app(self.project.name, "TestApp") self.app.build_spec = BuildSpec.from_string('2.7.0/latest') self.client.login(username=self.username, password=self.password)
def setUp(self): self.app = Application.new_app('domain', "my app") self.module = self.app.add_module(Module.new_module("Module 1", None)) self.form = self.app.new_form(0, "Form 1", None) self.min_spec = BuildSpec.from_string('2.21/latest') self.app.build_spec = self.min_spec
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])
def setUp(self): self.app = Application.new_app(self.project.name, "TestApp") self.app.build_spec = BuildSpec.from_string('2.7.0/latest') self.client.login(username=self.username, password=self.password)
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])