<s> from corehq . apps . app_manager . tests . app_factory import AppFactory <EOL> from django . test import SimpleTestCase <EOL> from corehq . apps . app_manager . const import APP_V2 <EOL> from corehq . apps . app_manager . models import ( <EOL> AdvancedModule , <EOL> Application , <EOL> CaseIndex , <EOL> FormActionCondition , <EOL> LoadUpdateAction , <EOL> Module , <EOL> OpenSubCaseAction , <EOL> ParentSelect , <EOL> PreloadAction , <EOL> UpdateCaseAction , <EOL> ) <EOL> from corehq . apps . app_manager . tests . util import TestXmlMixin <EOL> from corehq . feature_previews import MODULE_FILTER <EOL> from corehq . toggles import NAMESPACE_DOMAIN <EOL> from toggle . shortcuts import clear_toggle_cache , update_toggle_cache <EOL> DOMAIN = '<STR_LIT>' <EOL> class ModuleAsChildTestBase ( TestXmlMixin ) : <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> child_module_class = None <EOL> def setUp ( self ) : <EOL> update_toggle_cache ( MODULE_FILTER . slug , DOMAIN , True , NAMESPACE_DOMAIN ) <EOL> self . factory = AppFactory ( domain = DOMAIN ) <EOL> self . module_0 , _ = self . factory . new_basic_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . module_1 , _ = self . factory . new_module ( self . child_module_class , '<STR_LIT>' , '<STR_LIT>' , parent_module = self . module_0 ) <EOL> self . app = self . factory . app <EOL> def tearDown ( self ) : <EOL> clear_toggle_cache ( MODULE_FILTER . slug , DOMAIN , NAMESPACE_DOMAIN ) <EOL> def test_basic_workflow ( self ) : <EOL> XML = """<STR_LIT>""" <EOL> self . assertXmlPartialEqual ( XML , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> def test_workflow_with_put_in_root ( self ) : <EOL> self . module_1 . put_in_root = True <EOL> XML = """<STR_LIT>""" <EOL> self . assertXmlPartialEqual ( XML , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> def test_deleted_parent ( self ) : <EOL> self . module_1 . root_module_id = "<STR_LIT>" <EOL> cycle_error = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> } <EOL> errors = self . app . validate_app ( ) <EOL> self . assertIn ( cycle_error , errors ) <EOL> def test_circular_relation ( self ) : <EOL> self . module_0 . root_module_id = self . module_1 . unique_id <EOL> cycle_error = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> } <EOL> errors = self . app . validate_app ( ) <EOL> self . assertIn ( cycle_error , errors ) <EOL> class AdvancedModuleAsChildTest ( ModuleAsChildTestBase , SimpleTestCase ) : <EOL> child_module_class = AdvancedModule <EOL> def test_child_module_session_datums_added ( self ) : <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' ) <EOL> self . assertXmlPartialEqual ( self . get_xml ( '<STR_LIT>' ) , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> def test_child_module_adjust_session_datums ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' ) <EOL> self . assertXmlPartialEqual ( self . get_xml ( '<STR_LIT>' ) , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> def test_form_case_id ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> m1f0 . source = self . get_xml ( '<STR_LIT>' , override_path = ( '<STR_LIT:data>' , ) ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , update = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' ) <EOL> self . assertXmlEqual ( self . get_xml ( '<STR_LIT>' ) , m1f0 . render_xform ( ) ) <EOL> def test_form_display_condition ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = AppFactory ( domain = DOMAIN ) <EOL> m0 , m0f0 = factory . new_advanced_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> factory . form_requires_case ( m0f0 ) <EOL> m0f0 . actions . load_update_cases [ <NUM_LIT:0> ] . case_tag = '<STR_LIT>' <EOL> m1 , m1f0 = factory . new_advanced_module ( '<STR_LIT>' , '<STR_LIT>' , parent_module = m0 ) <EOL> factory . form_requires_case ( m1f0 , '<STR_LIT>' , update = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' ) <EOL> m1f0 . actions . load_update_cases [ <NUM_LIT:1> ] . case_tag = '<STR_LIT>' <EOL> m1f0 . form_filter = "<STR_LIT>" <EOL> XML = """<STR_LIT>""" <EOL> self . assertXmlPartialEqual ( XML , factory . app . create_suite ( ) , "<STR_LIT>" ) <EOL> class BasicModuleAsChildTest ( ModuleAsChildTestBase , SimpleTestCase ) : <EOL> child_module_class = Module <EOL> def test_child_module_session_datums_added ( self ) : <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' ) <EOL> self . assertXmlPartialEqual ( self . get_xml ( '<STR_LIT>' ) , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> def test_grandparent_as_child_module ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , parent_case_type = '<STR_LIT>' ) <EOL> self . factory . form_opens_case ( m1f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m2 , m2f0 = self . factory . new_basic_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . factory . form_requires_case ( m2f0 , parent_case_type = '<STR_LIT>' ) <EOL> self . module_1 . root_module_id = None <EOL> m2 . root_module_id = self . module_1 . unique_id <EOL> self . assertXmlPartialEqual ( <EOL> self . get_xml ( '<STR_LIT>' ) , <EOL> self . app . create_suite ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_child_module_with_parent_select_entry_datums ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , parent_case_type = '<STR_LIT>' ) <EOL> self . factory . form_opens_case ( m1f0 , '<STR_LIT>' , is_subcase = True ) <EOL> self . assertXmlPartialEqual ( <EOL> self . get_xml ( '<STR_LIT>' ) , <EOL> self . app . create_suite ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_form_case_id ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> m1f0 . source = self . get_xml ( '<STR_LIT>' , override_path = ( '<STR_LIT:data>' , ) ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' , update = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertXmlEqual ( self . get_xml ( '<STR_LIT>' ) , m1f0 . render_xform ( ) ) <EOL> def test_form_display_condition ( self ) : <EOL> """<STR_LIT>""" <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m0f0 ) <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' , update = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> m1f0 . form_filter = "<STR_LIT>" <EOL> XML = """<STR_LIT>""" <EOL> self . assertXmlPartialEqual ( XML , self . app . create_suite ( ) , "<STR_LIT>" ) <EOL> class UserCaseOnlyModuleAsChildTest ( ModuleAsChildTestBase , SimpleTestCase ) : <EOL> """<STR_LIT>""" <EOL> child_module_class = Module <EOL> def test_child_module_session_datums_added ( self ) : <EOL> m0f0 = self . module_0 . get_form ( <NUM_LIT:0> ) <EOL> m0f0 . actions . usercase_preload = PreloadAction ( preload = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> m0f0 . actions . usercase_preload . condition . type = '<STR_LIT>' <EOL> self . factory . form_opens_case ( m0f0 , '<STR_LIT>' , is_subcase = True ) <EOL> m1f0 = self . module_1 . get_form ( <NUM_LIT:0> ) <EOL> self . factory . form_requires_case ( m1f0 , '<STR_LIT>' , parent_case_type = '<STR_LIT>' ) <EOL> self . assertXmlPartialEqual ( <EOL> self . get_xml ( '<STR_LIT>' ) , <EOL> self . app . create_suite ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> class AdvancedSubModuleTests ( SimpleTestCase , TestXmlMixin ) : <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> def test_form_rename_session_vars ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = AppFactory ( build_version = '<STR_LIT>' ) <EOL> reg_goldfish_mod , reg_goldfish_form = factory . new_basic_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> factory . form_opens_case ( reg_goldfish_form ) <EOL> reg_guppy_mod , reg_guppy_form = factory . new_advanced_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> factory . form_requires_case ( reg_guppy_form , '<STR_LIT>' ) <EOL> factory . form_opens_case ( reg_guppy_form , '<STR_LIT>' , is_subcase = True ) <EOL> upd_goldfish_mod , upd_goldfish_form = factory . new_advanced_module ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> factory . form_requires_case ( upd_goldfish_form ) <EOL> upd_goldfish_form . actions . load_update_cases [ <NUM_LIT:0> ] . case_tag = '<STR_LIT>' <EOL> upd_guppy_mod , upd_guppy_form = factory . new_advanced_module ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> parent_module = upd_goldfish_mod , <EOL> ) <EOL> upd_guppy_form . source = self . get_xml ( '<STR_LIT>' , override_path = ( '<STR_LIT:data>' , ) ) <EOL> factory . form_requires_case ( upd_guppy_form , '<STR_LIT>' , update = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> factory . form_requires_case ( <EOL> upd_guppy_form , <EOL> '<STR_LIT>' , <EOL> parent_case_type = '<STR_LIT>' , <EOL> update = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> upd_guppy_form . actions . load_update_cases [ <NUM_LIT:1> ] . case_tag = '<STR_LIT>' <EOL> self . assertXmlEqual ( self . get_xml ( '<STR_LIT>' ) , upd_guppy_form . render_xform ( ) ) <EOL> class BasicSubModuleTests ( SimpleTestCase , TestXmlMixin ) : <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> def test_parent_preload ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = AppFactory ( build_version = '<STR_LIT>' ) <EOL> upd_goldfish_mod , upd_goldfish_form = factory . new_basic_module ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> factory . form_requires_case ( upd_goldfish_form ) <EOL> guppy_mod , guppy_form = factory . new_basic_module ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> parent_module = upd_goldfish_mod , <EOL> ) <EOL> guppy_form . source = self . get_xml ( '<STR_LIT>' , override_path = ( '<STR_LIT:data>' , ) ) <EOL> factory . form_requires_case ( <EOL> guppy_form , <EOL> '<STR_LIT>' , <EOL> parent_case_type = '<STR_LIT>' , <EOL> preload = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertXmlEqual ( self . get_xml ( '<STR_LIT>' ) , guppy_form . render_xform ( ) ) </s>
