<s> import copy <EOL> import mock <EOL> import six <EOL> from openstack . cluster . v1 import profile as sdk_profile <EOL> from openstack import exceptions as sdk_exc <EOL> from openstackclient . common import exceptions as exc <EOL> from openstackclient . common import utils <EOL> from senlinclient . tests . unit . v1 import fakes <EOL> from senlinclient . v1 import profile as osc_profile <EOL> class TestProfile ( fakes . TestClusteringv1 ) : <EOL> def setUp ( self ) : <EOL> super ( TestProfile , self ) . setUp ( ) <EOL> self . mock_client = self . app . client_manager . clustering <EOL> class TestProfileShow ( TestProfile ) : <EOL> get_response = { "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:false>' , <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : '<STR_LIT:false>' , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <EOL> "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:result>" : { <EOL> "<STR_LIT:value>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:value>" <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:file>" : { <EOL> "<STR_LIT:default>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:64> <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : "<STR_LIT:1.0>" <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:null>' , <EOL> "<STR_LIT:user>" : "<STR_LIT>" <EOL> } } <EOL> def setUp ( self ) : <EOL> super ( TestProfileShow , self ) . setUp ( ) <EOL> self . cmd = osc_profile . ShowProfile ( self . app , None ) <EOL> self . mock_client . get_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( <EOL> attrs = self . get_response [ '<STR_LIT>' ] ) ) <EOL> utils . get_dict_properties = mock . Mock ( return_value = '<STR_LIT>' ) <EOL> def test_profile_show ( self ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . get_profile . assert_called_with ( '<STR_LIT>' ) <EOL> def test_profile_show_not_found ( self ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . mock_client . get_profile . side_effect = sdk_exc . ResourceNotFound ( ) <EOL> self . assertRaises ( <EOL> exc . CommandError , <EOL> self . cmd . take_action , <EOL> parsed_args ) <EOL> class TestProfileList ( TestProfile ) : <EOL> columns = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:type>' , '<STR_LIT>' ] <EOL> data = { "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:name>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:user>" : "<STR_LIT>" <EOL> } <EOL> ] } <EOL> defaults = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> def setUp ( self ) : <EOL> super ( TestProfileList , self ) . setUp ( ) <EOL> self . cmd = osc_profile . ListProfile ( self . app , None ) <EOL> self . mock_client . profiles = mock . Mock ( <EOL> return_value = self . data ) <EOL> def test_profile_list_defaults ( self ) : <EOL> arglist = [ ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . profiles . assert_called_with ( ** self . defaults ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> def test_profile_list_full_id ( self ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . profiles . assert_called_with ( ** self . defaults ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> def test_profile_list_limit ( self ) : <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT:3>' <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT:3>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . profiles . assert_called_with ( ** kwargs ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> def test_profile_list_sort ( self ) : <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . profiles . assert_called_with ( ** kwargs ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> def test_profile_list_sort_invalid_key ( self ) : <EOL> self . mock_client . profiles = mock . Mock ( <EOL> return_value = self . data ) <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . mock_client . profiles . side_effect = sdk_exc . HttpException ( ) <EOL> self . assertRaises ( sdk_exc . HttpException , <EOL> self . cmd . take_action , parsed_args ) <EOL> def test_profile_list_sort_invalid_direction ( self ) : <EOL> self . mock_client . profiles = mock . Mock ( <EOL> return_value = self . data ) <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . mock_client . profiles . side_effect = sdk_exc . HttpException ( ) <EOL> self . assertRaises ( sdk_exc . HttpException , <EOL> self . cmd . take_action , parsed_args ) <EOL> def test_profile_list_filter ( self ) : <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . profiles . assert_called_with ( ** kwargs ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> class TestProfileDelete ( TestProfile ) : <EOL> def setUp ( self ) : <EOL> super ( TestProfileDelete , self ) . setUp ( ) <EOL> self . cmd = osc_profile . DeleteProfile ( self . app , None ) <EOL> self . mock_client . delete_profile = mock . Mock ( ) <EOL> def test_profile_delete ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . delete_profile . assert_has_calls ( <EOL> [ mock . call ( '<STR_LIT>' , False ) , mock . call ( '<STR_LIT>' , False ) , <EOL> mock . call ( '<STR_LIT>' , False ) ] <EOL> ) <EOL> def test_profile_delete_force ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . delete_profile . assert_has_calls ( <EOL> [ mock . call ( '<STR_LIT>' , False ) , mock . call ( '<STR_LIT>' , False ) , <EOL> mock . call ( '<STR_LIT>' , False ) ] <EOL> ) <EOL> def test_profile_delete_not_found ( self ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> self . mock_client . delete_profile . side_effect = sdk_exc . ResourceNotFound <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> error = self . assertRaises ( exc . CommandError , self . cmd . take_action , <EOL> parsed_args ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> str ( error ) ) <EOL> def test_profile_delete_one_found_one_not_found ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . mock_client . delete_profile . side_effect = ( <EOL> [ None , sdk_exc . ResourceNotFound ] <EOL> ) <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> error = self . assertRaises ( exc . CommandError , <EOL> self . cmd . take_action , parsed_args ) <EOL> self . mock_client . delete_profile . assert_has_calls ( <EOL> [ mock . call ( '<STR_LIT>' , False ) , mock . call ( '<STR_LIT>' , False ) ] <EOL> ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( error ) ) <EOL> @ mock . patch ( '<STR_LIT>' , spec = six . StringIO ) <EOL> def test_profile_delete_prompt_yes ( self , mock_stdin ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> mock_stdin . isatty . return_value = True <EOL> mock_stdin . readline . return_value = '<STR_LIT:y>' <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> mock_stdin . readline . assert_called_with ( ) <EOL> self . mock_client . delete_profile . assert_called_with ( '<STR_LIT>' , <EOL> False ) <EOL> @ mock . patch ( '<STR_LIT>' , spec = six . StringIO ) <EOL> def test_profile_delete_prompt_no ( self , mock_stdin ) : <EOL> arglist = [ '<STR_LIT>' ] <EOL> mock_stdin . isatty . return_value = True <EOL> mock_stdin . readline . return_value = '<STR_LIT:n>' <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> mock_stdin . readline . assert_called_with ( ) <EOL> self . mock_client . delete_profile . assert_not_called ( ) <EOL> class TestProfileCreate ( TestProfile ) : <EOL> spec_path = '<STR_LIT>' <EOL> response = { "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:image>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : <NUM_LIT:1.0> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:user>" : "<STR_LIT>" } } <EOL> defaults = { "<STR_LIT>" : { <EOL> "<STR_LIT:version>" : <NUM_LIT:1.0> , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:image>" : "<STR_LIT>" } <EOL> } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> def setUp ( self ) : <EOL> super ( TestProfileCreate , self ) . setUp ( ) <EOL> self . cmd = osc_profile . CreateProfile ( self . app , None ) <EOL> self . mock_client . create_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( attrs = self . response [ '<STR_LIT>' ] ) ) <EOL> self . mock_client . get_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( attrs = self . response [ '<STR_LIT>' ] ) ) <EOL> utils . get_dict_properties = mock . Mock ( return_value = '<STR_LIT>' ) <EOL> def test_profile_create_defaults ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , self . spec_path ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . create_profile . assert_called_with ( ** self . defaults ) <EOL> def test_profile_create_metadata ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , self . spec_path , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> kwargs = copy . deepcopy ( self . defaults ) <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . create_profile . assert_called_with ( ** kwargs ) <EOL> class TestProfileUpdate ( TestProfile ) : <EOL> response = { "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:image>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : <NUM_LIT:1.0> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:user>" : "<STR_LIT>" } } <EOL> defaults = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> } <EOL> def setUp ( self ) : <EOL> super ( TestProfileUpdate , self ) . setUp ( ) <EOL> self . cmd = osc_profile . UpdateProfile ( self . app , None ) <EOL> self . mock_client . update_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( attrs = self . response [ '<STR_LIT>' ] ) ) <EOL> self . mock_client . get_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( attrs = self . response [ '<STR_LIT>' ] ) ) <EOL> self . mock_client . find_profile = mock . Mock ( <EOL> return_value = sdk_profile . Profile ( attrs = self . response [ '<STR_LIT>' ] ) ) <EOL> utils . get_dict_properties = mock . Mock ( return_value = '<STR_LIT>' ) <EOL> def test_profile_update_defaults ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . cmd . take_action ( parsed_args ) <EOL> self . mock_client . update_profile . assert_called_with ( <EOL> '<STR_LIT>' , ** self . defaults ) <EOL> def test_profile_update_not_found ( self ) : <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , [ ] ) <EOL> self . mock_client . find_profile . return_value = None <EOL> error = self . assertRaises ( <EOL> exc . CommandError , <EOL> self . cmd . take_action , <EOL> parsed_args ) <EOL> self . assertIn ( '<STR_LIT>' , str ( error ) ) </s>
