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 = 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 copy_applications(self): from corehq.apps.app_manager.dbaccessors import get_apps_in_domain from corehq.apps.app_manager.models import ReportModule from corehq.apps.app_manager.models import import_app apps = get_apps_in_domain(self.existing_domain) for app in apps: for module in app.modules: if isinstance(module, ReportModule): for config in module.report_configs: config.report_id = self.report_map[config.report_id] if self.no_commit: new_app = Application.from_source(app.export_json(dump_json=False), self.new_domain) new_app['_id'] = 'new-{}'.format(app._id) else: new_app = import_app(app.to_json(), self.new_domain) self.log_copy(app.doc_type, app._id, new_app._id)
def copy_applications(self): from corehq.apps.app_manager.dbaccessors import get_apps_in_domain from corehq.apps.app_manager.models import ReportModule from corehq.apps.app_manager.models import import_app apps = get_apps_in_domain(self.existing_domain) for app in apps: for module in app.modules: if isinstance(module, ReportModule): for config in module.report_configs: config.report_id = self.report_map[config.report_id] if self.no_commmit: new_app = Application.from_source(app.export_json(dump_json=False), self.new_domain) new_app['_id'] = 'new-{}'.format(app._id) else: new_app = import_app(app.to_json(), self.new_domain) self.log_copy(app.doc_type, app._id, new_app._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)
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)