<s> import mock <EOL> from openstack . tests . unit import base <EOL> class TestProxyBase ( base . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestProxyBase , self ) . setUp ( ) <EOL> self . session = mock . Mock ( ) <EOL> def _add_path_args_for_verify ( self , path_args , method_args , <EOL> expected_kwargs , value = None ) : <EOL> if path_args is not None : <EOL> if value is None : <EOL> for key in path_args : <EOL> method_args . append ( path_args [ key ] ) <EOL> expected_kwargs [ '<STR_LIT>' ] = path_args <EOL> def _verify ( self , mock_method , test_method , <EOL> method_args = None , method_kwargs = None , <EOL> expected_args = None , expected_kwargs = None , <EOL> expected_result = None ) : <EOL> with mock . patch ( mock_method ) as mocked : <EOL> mocked . return_value = expected_result <EOL> if any ( [ method_args , method_kwargs , <EOL> expected_args , expected_kwargs ] ) : <EOL> method_args = method_args or ( ) <EOL> method_kwargs = method_kwargs or { } <EOL> expected_args = expected_args or ( ) <EOL> expected_kwargs = expected_kwargs or { } <EOL> self . assertEqual ( expected_result , test_method ( * method_args , <EOL> ** method_kwargs ) ) <EOL> mocked . assert_called_with ( self . session , <EOL> * expected_args , ** expected_kwargs ) <EOL> else : <EOL> self . assertEqual ( expected_result , test_method ( ) ) <EOL> mocked . assert_called_with ( self . session ) <EOL> def _verify2 ( self , mock_method , test_method , <EOL> method_args = None , method_kwargs = None , method_result = None , <EOL> expected_args = None , expected_kwargs = None , <EOL> expected_result = None ) : <EOL> with mock . patch ( mock_method ) as mocked : <EOL> mocked . return_value = expected_result <EOL> if any ( [ method_args , method_kwargs , <EOL> expected_args , expected_kwargs ] ) : <EOL> method_args = method_args or ( ) <EOL> method_kwargs = method_kwargs or { } <EOL> expected_args = expected_args or ( ) <EOL> expected_kwargs = expected_kwargs or { } <EOL> if method_result : <EOL> self . assertEqual ( method_result , test_method ( * method_args , <EOL> ** method_kwargs ) ) <EOL> else : <EOL> self . assertEqual ( expected_result , test_method ( * method_args , <EOL> ** method_kwargs ) ) <EOL> mocked . assert_called_with ( * expected_args , ** expected_kwargs ) <EOL> else : <EOL> self . assertEqual ( expected_result , test_method ( ) ) <EOL> mocked . assert_called_with ( self . session ) <EOL> def verify_create ( self , test_method , resource_type , <EOL> mock_method = "<STR_LIT>" , <EOL> expected_result = "<STR_LIT:result>" , ** kwargs ) : <EOL> the_kwargs = { "<STR_LIT:x>" : <NUM_LIT:1> , "<STR_LIT:y>" : <NUM_LIT:2> , "<STR_LIT:z>" : <NUM_LIT:3> } <EOL> method_kwargs = kwargs . pop ( "<STR_LIT>" , the_kwargs ) <EOL> expected_args = [ resource_type ] <EOL> expected_kwargs = kwargs . pop ( "<STR_LIT>" , the_kwargs ) <EOL> self . _verify2 ( mock_method , test_method , <EOL> expected_result = expected_result , <EOL> method_kwargs = method_kwargs , <EOL> expected_args = expected_args , <EOL> expected_kwargs = expected_kwargs , <EOL> ** kwargs ) <EOL> def verify_delete ( self , test_method , resource_type , ignore , <EOL> input_path_args = None , expected_path_args = None , <EOL> mock_method = "<STR_LIT>" ) : <EOL> method_args = [ "<STR_LIT>" ] <EOL> method_kwargs = { "<STR_LIT>" : ignore } <EOL> if isinstance ( input_path_args , dict ) : <EOL> for key in input_path_args : <EOL> method_kwargs [ key ] = input_path_args [ key ] <EOL> elif isinstance ( input_path_args , list ) : <EOL> method_args = input_path_args <EOL> expected_kwargs = { "<STR_LIT>" : ignore } <EOL> if expected_path_args : <EOL> expected_kwargs [ "<STR_LIT>" ] = expected_path_args <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_args = method_args , <EOL> method_kwargs = method_kwargs , <EOL> expected_args = [ resource_type , "<STR_LIT>" ] , <EOL> expected_kwargs = expected_kwargs ) <EOL> def verify_get ( self , test_method , resource_type , value = None , args = None , <EOL> mock_method = "<STR_LIT>" , <EOL> ignore_value = False , ** kwargs ) : <EOL> the_value = value <EOL> if value is None : <EOL> the_value = [ ] if ignore_value else [ "<STR_LIT:value>" ] <EOL> expected_args = kwargs . pop ( "<STR_LIT>" , [ ] ) <EOL> expected_kwargs = kwargs . pop ( "<STR_LIT>" , { } ) <EOL> method_kwargs = kwargs . pop ( "<STR_LIT>" , kwargs ) <EOL> if args : <EOL> expected_kwargs [ "<STR_LIT:args>" ] = args <EOL> if kwargs : <EOL> expected_kwargs [ "<STR_LIT>" ] = kwargs <EOL> if not expected_args : <EOL> expected_args = [ resource_type ] + the_value <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_args = the_value , <EOL> method_kwargs = method_kwargs or { } , <EOL> expected_args = expected_args , <EOL> expected_kwargs = expected_kwargs ) <EOL> def verify_head ( self , test_method , resource_type , <EOL> mock_method = "<STR_LIT>" , <EOL> value = None , ** kwargs ) : <EOL> the_value = [ value ] if value is not None else [ ] <EOL> expected_kwargs = { "<STR_LIT>" : kwargs } if kwargs else { } <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_args = the_value , <EOL> method_kwargs = kwargs , <EOL> expected_args = [ resource_type ] + the_value , <EOL> expected_kwargs = expected_kwargs ) <EOL> def verify_find ( self , test_method , resource_type , value = None , <EOL> mock_method = "<STR_LIT>" , <EOL> path_args = None , ** kwargs ) : <EOL> method_args = value or [ "<STR_LIT>" ] <EOL> expected_kwargs = { } <EOL> self . _add_path_args_for_verify ( path_args , method_args , expected_kwargs , <EOL> value = value ) <EOL> expected_kwargs [ "<STR_LIT>" ] = False <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_args = method_args + [ False ] , <EOL> expected_args = [ resource_type , "<STR_LIT>" ] , <EOL> expected_kwargs = expected_kwargs , <EOL> expected_result = "<STR_LIT:result>" , <EOL> ** kwargs ) <EOL> expected_kwargs [ "<STR_LIT>" ] = True <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_args = method_args + [ True ] , <EOL> expected_args = [ resource_type , "<STR_LIT>" ] , <EOL> expected_kwargs = expected_kwargs , <EOL> expected_result = "<STR_LIT:result>" , <EOL> ** kwargs ) <EOL> def verify_list ( self , test_method , resource_type , paginated = False , <EOL> mock_method = "<STR_LIT>" , <EOL> ** kwargs ) : <EOL> expected_kwargs = kwargs . pop ( "<STR_LIT>" , { } ) <EOL> expected_kwargs . update ( { "<STR_LIT>" : paginated } ) <EOL> expected_kwargs [ '<STR_LIT>' ] = <NUM_LIT:2> <EOL> method_kwargs = kwargs . pop ( "<STR_LIT>" , { } ) <EOL> method_kwargs [ '<STR_LIT>' ] = <NUM_LIT:2> <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_kwargs = method_kwargs , <EOL> expected_args = [ resource_type ] , <EOL> expected_kwargs = expected_kwargs , <EOL> expected_result = [ "<STR_LIT:result>" ] , <EOL> ** kwargs ) <EOL> def verify_list_no_kwargs ( self , test_method , resource_type , <EOL> paginated = False , <EOL> mock_method = "<STR_LIT>" ) : <EOL> self . _verify2 ( mock_method , test_method , <EOL> method_kwargs = { } , <EOL> expected_args = [ resource_type ] , <EOL> expected_kwargs = { "<STR_LIT>" : paginated } , <EOL> expected_result = [ "<STR_LIT:result>" ] ) <EOL> def verify_update ( self , test_method , resource_type , value = None , <EOL> mock_method = "<STR_LIT>" , <EOL> expected_result = "<STR_LIT:result>" , path_args = None , ** kwargs ) : <EOL> method_args = value or [ "<STR_LIT>" ] <EOL> method_kwargs = { "<STR_LIT:x>" : <NUM_LIT:1> , "<STR_LIT:y>" : <NUM_LIT:2> , "<STR_LIT:z>" : <NUM_LIT:3> } <EOL> expected_args = kwargs . pop ( "<STR_LIT>" , [ "<STR_LIT>" ] ) <EOL> expected_kwargs = method_kwargs . copy ( ) <EOL> self . _add_path_args_for_verify ( path_args , method_args , expected_kwargs , <EOL> value = value ) <EOL> self . _verify2 ( mock_method , test_method , <EOL> expected_result = expected_result , <EOL> method_args = method_args , <EOL> method_kwargs = method_kwargs , <EOL> expected_args = [ resource_type ] + expected_args , <EOL> expected_kwargs = expected_kwargs , <EOL> ** kwargs ) <EOL> def verify_wait_for_status ( <EOL> self , test_method , <EOL> mock_method = "<STR_LIT>" , ** kwargs ) : <EOL> self . _verify ( mock_method , test_method , ** kwargs ) </s>
