<s> import corehq . apps . app_manager . util as util <EOL> from corehq . apps . app_manager . const import APP_V2 <EOL> from corehq . apps . app_manager . models import ( <EOL> Application , Module , OpenCaseAction , OpenSubCaseAction ) <EOL> from django . test . testcases import SimpleTestCase <EOL> from mock import patch <EOL> class SchemaTest ( SimpleTestCase ) : <EOL> def setUp ( self ) : <EOL> self . models_is_usercase_in_use_patch = patch ( '<STR_LIT>' ) <EOL> self . models_is_usercase_in_use_mock = self . models_is_usercase_in_use_patch . start ( ) <EOL> self . models_is_usercase_in_use_mock . return_value = False <EOL> self . util_is_usercase_in_use_patch = patch ( '<STR_LIT>' ) <EOL> self . util_is_usercase_in_use_mock = self . util_is_usercase_in_use_patch . start ( ) <EOL> self . util_is_usercase_in_use_mock . return_value = False <EOL> def tearDown ( self ) : <EOL> self . models_is_usercase_in_use_patch . stop ( ) <EOL> self . util_is_usercase_in_use_patch . stop ( ) <EOL> def test_get_casedb_schema_empty_app ( self ) : <EOL> app = self . make_app ( ) <EOL> schema = util . get_casedb_schema ( app ) <EOL> self . assert_has_kv_pairs ( schema , { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> } ) <EOL> def test_get_casedb_schema_with_form ( self ) : <EOL> app = self . make_app ( ) <EOL> self . add_form ( app , "<STR_LIT>" ) <EOL> schema = util . get_casedb_schema ( app ) <EOL> self . assertEqual ( len ( schema [ "<STR_LIT>" ] ) , <NUM_LIT:1> , schema [ "<STR_LIT>" ] ) <EOL> self . assert_has_kv_pairs ( schema [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : { } } , <EOL> '<STR_LIT>' : None , <EOL> } ) <EOL> def test_get_casedb_schema_with_related_case_types ( self ) : <EOL> app = self . make_app ( ) <EOL> self . add_form ( app , "<STR_LIT>" ) <EOL> village = self . add_form ( app , "<STR_LIT>" ) <EOL> village . actions . subcases . append ( OpenSubCaseAction ( <EOL> case_type = '<STR_LIT>' , <EOL> reference_id = '<STR_LIT>' <EOL> ) ) <EOL> schema = util . get_casedb_schema ( app ) <EOL> subsets = { s [ "<STR_LIT:id>" ] : s for s in schema [ "<STR_LIT>" ] } <EOL> self . assertEqual ( subsets [ "<STR_LIT>" ] [ "<STR_LIT>" ] , None ) <EOL> self . assertDictEqual ( subsets [ "<STR_LIT>" ] [ "<STR_LIT>" ] , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> def test_get_session_schema_for_module_with_no_case_type ( self ) : <EOL> app = self . make_app ( ) <EOL> form = self . add_form ( app ) <EOL> schema = util . get_session_schema ( form ) <EOL> self . assert_has_kv_pairs ( schema , { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> } ) <EOL> assert "<STR_LIT>" not in schema [ "<STR_LIT>" ] , schema [ "<STR_LIT>" ] <EOL> def test_get_session_schema_for_simple_module_with_case ( self ) : <EOL> app = self . make_app ( ) <EOL> form = self . add_form ( app , "<STR_LIT>" ) <EOL> schema = util . get_session_schema ( form ) <EOL> self . assertDictEqual ( schema [ "<STR_LIT>" ] [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:source>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> def assert_has_kv_pairs ( self , test_dict , expected_dict ) : <EOL> """<STR_LIT>""" <EOL> for key , value in expected_dict . items ( ) : <EOL> self . assertEqual ( test_dict [ key ] , value ) <EOL> def add_form ( self , app , case_type = None , module_id = None ) : <EOL> if module_id is None : <EOL> module_id = len ( app . modules ) <EOL> m = app . add_module ( Module . new_module ( '<STR_LIT>' . format ( module_id ) , lang = '<STR_LIT>' ) ) <EOL> if case_type : <EOL> m . case_type = case_type <EOL> form = app . new_form ( module_id , '<STR_LIT>' . format ( case_type ) , lang = '<STR_LIT>' ) <EOL> if case_type : <EOL> form . actions . open_case = OpenCaseAction ( name_path = "<STR_LIT>" , external_id = None ) <EOL> form . actions . open_case . condition . type = '<STR_LIT>' <EOL> return form <EOL> def make_app ( self ) : <EOL> app = Application . new_app ( '<STR_LIT>' , '<STR_LIT>' , APP_V2 ) <EOL> app . version = <NUM_LIT:1> <EOL> return app </s>
