<s> import copy <EOL> import mock <EOL> import warlock <EOL> from glanceclient . v2 import schemas <EOL> from openstackclient . common import exceptions <EOL> from openstackclient . image . v2 import image <EOL> from openstackclient . tests import fakes <EOL> from openstackclient . tests . identity . v3 import fakes as identity_fakes <EOL> from openstackclient . tests . image . v2 import fakes as image_fakes <EOL> class TestImage ( image_fakes . TestImagev2 ) : <EOL> def setUp ( self ) : <EOL> super ( TestImage , self ) . setUp ( ) <EOL> self . images_mock = self . app . client_manager . image . images <EOL> self . images_mock . reset_mock ( ) <EOL> self . image_members_mock = self . app . client_manager . image . image_members <EOL> self . image_members_mock . reset_mock ( ) <EOL> self . project_mock = self . app . client_manager . identity . projects <EOL> self . project_mock . reset_mock ( ) <EOL> self . domain_mock = self . app . client_manager . identity . domains <EOL> self . domain_mock . reset_mock ( ) <EOL> def setup_images_mock ( self , count ) : <EOL> images = image_fakes . FakeImage . create_images ( count = count ) <EOL> self . images_mock . get = image_fakes . FakeImage . get_images ( <EOL> images , <EOL> <NUM_LIT:0> ) <EOL> return images <EOL> class TestImageCreate ( TestImage ) : <EOL> def setUp ( self ) : <EOL> super ( TestImageCreate , self ) . setUp ( ) <EOL> self . new_image = image_fakes . FakeImage . create_one_image ( ) <EOL> self . images_mock . create . return_value = self . new_image <EOL> self . project_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . PROJECT ) , <EOL> loaded = True , <EOL> ) <EOL> self . domain_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . DOMAIN ) , <EOL> loaded = True , <EOL> ) <EOL> self . images_mock . get . return_value = copy . deepcopy ( <EOL> image_fakes . FakeImage . get_image_info ( self . new_image ) ) <EOL> self . images_mock . update . return_value = self . new_image <EOL> self . cmd = image . CreateImage ( self . app , None ) <EOL> def test_image_reserve_no_options ( self ) : <EOL> mock_exception = { <EOL> '<STR_LIT>' : exceptions . CommandError ( '<STR_LIT:x>' ) , <EOL> } <EOL> self . images_mock . configure_mock ( ** mock_exception ) <EOL> arglist = [ <EOL> self . new_image . name <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , image . DEFAULT_CONTAINER_FORMAT ) , <EOL> ( '<STR_LIT>' , image . DEFAULT_DISK_FORMAT ) , <EOL> ( '<STR_LIT:name>' , self . new_image . name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . images_mock . create . assert_called_with ( <EOL> name = self . new_image . name , <EOL> container_format = image . DEFAULT_CONTAINER_FORMAT , <EOL> disk_format = image . DEFAULT_DISK_FORMAT , <EOL> ) <EOL> self . assertEqual ( self . images_mock . update . call_args_list , [ ] ) <EOL> self . images_mock . upload . assert_called_with ( <EOL> mock . ANY , mock . ANY , <EOL> ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_columns ( self . new_image ) , <EOL> columns ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_data ( self . new_image ) , <EOL> data ) <EOL> @ mock . patch ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> def test_image_reserve_options ( self , mock_open ) : <EOL> mock_file = mock . MagicMock ( name = '<STR_LIT>' ) <EOL> mock_open . return_value = mock_file <EOL> mock_open . read . return_value = None <EOL> mock_exception = { <EOL> '<STR_LIT>' : exceptions . CommandError ( '<STR_LIT:x>' ) , <EOL> } <EOL> self . images_mock . configure_mock ( ** mock_exception ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:4>' , <EOL> ( '<STR_LIT>' <EOL> if self . new_image . protected else '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' <EOL> if self . new_image . visibility == '<STR_LIT>' else '<STR_LIT>' ) , <EOL> '<STR_LIT>' , self . new_image . owner , <EOL> '<STR_LIT>' , identity_fakes . domain_id , <EOL> self . new_image . name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , self . new_image . protected ) , <EOL> ( '<STR_LIT>' , not self . new_image . protected ) , <EOL> ( '<STR_LIT>' , self . new_image . visibility == '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , self . new_image . visibility == '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , self . new_image . owner ) , <EOL> ( '<STR_LIT>' , identity_fakes . domain_id ) , <EOL> ( '<STR_LIT:name>' , self . new_image . name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . images_mock . create . assert_called_with ( <EOL> name = self . new_image . name , <EOL> container_format = '<STR_LIT>' , <EOL> disk_format = '<STR_LIT>' , <EOL> min_disk = <NUM_LIT:10> , <EOL> min_ram = <NUM_LIT:4> , <EOL> owner = identity_fakes . project_id , <EOL> protected = self . new_image . protected , <EOL> visibility = self . new_image . visibility , <EOL> ) <EOL> self . assertEqual ( self . images_mock . update . call_args_list , [ ] ) <EOL> self . images_mock . upload . assert_called_with ( <EOL> mock . ANY , mock . ANY , <EOL> ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_columns ( self . new_image ) , <EOL> columns ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_data ( self . new_image ) , <EOL> data ) <EOL> def test_image_create_with_unexist_owner ( self ) : <EOL> self . project_mock . get . side_effect = exceptions . NotFound ( None ) <EOL> self . project_mock . find . side_effect = exceptions . NotFound ( None ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:4>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT:name>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , <EOL> parsed_args , <EOL> ) <EOL> def test_image_create_with_unexist_project ( self ) : <EOL> self . project_mock . get . side_effect = exceptions . NotFound ( None ) <EOL> self . project_mock . find . side_effect = exceptions . NotFound ( None ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:4>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , <EOL> parsed_args , <EOL> ) <EOL> @ mock . patch ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> def test_image_create_file ( self , mock_open ) : <EOL> mock_file = mock . MagicMock ( name = '<STR_LIT>' ) <EOL> mock_open . return_value = mock_file <EOL> mock_open . read . return_value = ( <EOL> image_fakes . FakeImage . get_image_data ( self . new_image ) ) <EOL> mock_exception = { <EOL> '<STR_LIT>' : exceptions . CommandError ( '<STR_LIT:x>' ) , <EOL> } <EOL> self . images_mock . configure_mock ( ** mock_exception ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ( '<STR_LIT>' <EOL> if not self . new_image . protected else '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' <EOL> if self . new_image . visibility == '<STR_LIT>' else '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . new_image . tags [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , self . new_image . tags [ <NUM_LIT:1> ] , <EOL> self . new_image . name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:file>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , self . new_image . protected ) , <EOL> ( '<STR_LIT>' , not self . new_image . protected ) , <EOL> ( '<STR_LIT>' , self . new_image . visibility == '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , self . new_image . visibility == '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT:2>' } ) , <EOL> ( '<STR_LIT>' , self . new_image . tags ) , <EOL> ( '<STR_LIT:name>' , self . new_image . name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . images_mock . create . assert_called_with ( <EOL> name = self . new_image . name , <EOL> container_format = image . DEFAULT_CONTAINER_FORMAT , <EOL> disk_format = image . DEFAULT_DISK_FORMAT , <EOL> protected = self . new_image . protected , <EOL> visibility = self . new_image . visibility , <EOL> Alpha = '<STR_LIT:1>' , <EOL> Beta = '<STR_LIT:2>' , <EOL> tags = self . new_image . tags , <EOL> ) <EOL> self . assertEqual ( self . images_mock . update . call_args_list , [ ] ) <EOL> self . images_mock . upload . assert_called_with ( <EOL> mock . ANY , mock . ANY , <EOL> ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_columns ( self . new_image ) , <EOL> columns ) <EOL> self . assertEqual ( <EOL> image_fakes . FakeImage . get_image_data ( self . new_image ) , <EOL> data ) <EOL> def test_image_create_dead_options ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> self . new_image . name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:name>' , self . new_image . name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , parsed_args ) <EOL> class TestAddProjectToImage ( TestImage ) : <EOL> columns = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:status>' , <EOL> ) <EOL> datalist = ( <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> image_fakes . member_status , <EOL> ) <EOL> def setUp ( self ) : <EOL> super ( TestAddProjectToImage , self ) . setUp ( ) <EOL> self . images_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( image_fakes . IMAGE ) , <EOL> loaded = True , <EOL> ) <EOL> self . image_members_mock . create . return_value = fakes . FakeModel ( <EOL> copy . deepcopy ( image_fakes . MEMBER ) , <EOL> ) <EOL> self . project_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . PROJECT ) , <EOL> loaded = True , <EOL> ) <EOL> self . domain_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . DOMAIN ) , <EOL> loaded = True , <EOL> ) <EOL> self . cmd = image . AddProjectToImage ( self . app , None ) <EOL> def test_add_project_to_image_no_option ( self ) : <EOL> arglist = [ <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . project_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . image_members_mock . create . assert_called_with ( <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_add_project_to_image_with_option ( self ) : <EOL> arglist = [ <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> '<STR_LIT>' , identity_fakes . domain_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . project_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . domain_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . image_members_mock . create . assert_called_with ( <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> class TestImageDelete ( TestImage ) : <EOL> def setUp ( self ) : <EOL> super ( TestImageDelete , self ) . setUp ( ) <EOL> self . images_mock . delete . return_value = None <EOL> self . cmd = image . DeleteImage ( self . app , None ) <EOL> def test_image_delete_no_options ( self ) : <EOL> images = self . setup_images_mock ( count = <NUM_LIT:1> ) <EOL> arglist = [ <EOL> images [ <NUM_LIT:0> ] . id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ images [ <NUM_LIT:0> ] . id ] ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> self . images_mock . delete . assert_called_with ( images [ <NUM_LIT:0> ] . id ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_delete_multi_images ( self ) : <EOL> images = self . setup_images_mock ( count = <NUM_LIT:3> ) <EOL> arglist = [ i . id for i in images ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , arglist ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> calls = [ mock . call ( i . id ) for i in images ] <EOL> self . images_mock . delete . assert_has_calls ( calls ) <EOL> self . assertIsNone ( result ) <EOL> class TestImageList ( TestImage ) : <EOL> columns = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> datalist = ( <EOL> ( <EOL> image_fakes . image_id , <EOL> image_fakes . image_name , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ) <EOL> def setUp ( self ) : <EOL> super ( TestImageList , self ) . setUp ( ) <EOL> self . api_mock = mock . Mock ( ) <EOL> self . api_mock . image_list . side_effect = [ <EOL> [ copy . deepcopy ( image_fakes . IMAGE ) ] , [ ] , <EOL> ] <EOL> self . app . client_manager . image . api = self . api_mock <EOL> self . cmd = image . ListImage ( self . app , None ) <EOL> def test_image_list_no_options ( self ) : <EOL> arglist = [ ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> def test_image_list_public_option ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( <EOL> public = True , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> def test_image_list_private_option ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( <EOL> private = True , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> def test_image_list_shared_option ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( <EOL> shared = True , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> def test_image_list_long_option ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , True ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( ) <EOL> collist = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( ( <EOL> image_fakes . image_id , <EOL> image_fakes . image_name , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> False , <EOL> image_fakes . image_owner , <EOL> '<STR_LIT>' , <EOL> ) , ) <EOL> self . assertEqual ( datalist , tuple ( data ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_image_list_property_option ( self , sf_mock ) : <EOL> sf_mock . return_value = [ <EOL> copy . deepcopy ( image_fakes . IMAGE ) , <EOL> ] <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , { '<STR_LIT:a>' : '<STR_LIT:1>' } ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( ) <EOL> sf_mock . assert_called_with ( <EOL> [ image_fakes . IMAGE ] , <EOL> attr = '<STR_LIT:a>' , <EOL> value = '<STR_LIT:1>' , <EOL> property_field = '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_image_list_sort_option ( self , si_mock ) : <EOL> si_mock . return_value = [ <EOL> copy . deepcopy ( image_fakes . IMAGE ) <EOL> ] <EOL> arglist = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> verifylist = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( ) <EOL> si_mock . assert_called_with ( <EOL> [ image_fakes . IMAGE ] , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , tuple ( data ) ) <EOL> def test_image_list_limit_option ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , str ( <NUM_LIT:1> ) , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( <EOL> limit = <NUM_LIT:1> , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( len ( self . datalist ) , len ( tuple ( data ) ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_image_list_marker_option ( self , fr_mock ) : <EOL> fr_mock . return_value = mock . Mock ( ) <EOL> fr_mock . return_value . id = image_fakes . image_id <EOL> arglist = [ <EOL> '<STR_LIT>' , image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . api_mock . image_list . assert_called_with ( <EOL> marker = image_fakes . image_id , <EOL> ) <EOL> class TestRemoveProjectImage ( TestImage ) : <EOL> def setUp ( self ) : <EOL> super ( TestRemoveProjectImage , self ) . setUp ( ) <EOL> self . images_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( image_fakes . IMAGE ) , <EOL> loaded = True , <EOL> ) <EOL> self . project_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . PROJECT ) , <EOL> loaded = True , <EOL> ) <EOL> self . domain_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . DOMAIN ) , <EOL> loaded = True , <EOL> ) <EOL> self . image_members_mock . delete . return_value = None <EOL> self . cmd = image . RemoveProjectImage ( self . app , None ) <EOL> def test_remove_project_image_no_options ( self ) : <EOL> arglist = [ <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . project_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> self . image_members_mock . delete . assert_called_with ( <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_remove_project_image_with_options ( self ) : <EOL> arglist = [ <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> '<STR_LIT>' , identity_fakes . domain_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . project_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . domain_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> self . image_members_mock . delete . assert_called_with ( <EOL> image_fakes . image_id , <EOL> identity_fakes . project_id , <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> class TestImageSet ( TestImage ) : <EOL> def setUp ( self ) : <EOL> super ( TestImageSet , self ) . setUp ( ) <EOL> self . model = warlock . model_factory ( <EOL> image_fakes . IMAGE_schema , <EOL> schemas . SchemaBasedModel , <EOL> ) <EOL> self . project_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . PROJECT ) , <EOL> loaded = True , <EOL> ) <EOL> self . domain_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . DOMAIN ) , <EOL> loaded = True , <EOL> ) <EOL> self . images_mock . get . return_value = self . model ( ** image_fakes . IMAGE ) <EOL> self . images_mock . update . return_value = self . model ( ** image_fakes . IMAGE ) <EOL> self . cmd = image . SetImage ( self . app , None ) <EOL> def test_image_set_options ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:2>' , <EOL> '<STR_LIT>' , '<STR_LIT:4>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , identity_fakes . project_name , <EOL> '<STR_LIT>' , identity_fakes . domain_id , <EOL> image_fakes . image_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , identity_fakes . project_name ) , <EOL> ( '<STR_LIT>' , identity_fakes . domain_id ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : identity_fakes . project_id , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , ** kwargs ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_with_unexist_owner ( self ) : <EOL> self . project_mock . get . side_effect = exceptions . NotFound ( None ) <EOL> self . project_mock . find . side_effect = exceptions . NotFound ( None ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , parsed_args ) <EOL> def test_image_set_with_unexist_project ( self ) : <EOL> self . project_mock . get . side_effect = exceptions . NotFound ( None ) <EOL> self . project_mock . find . side_effect = exceptions . NotFound ( None ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , parsed_args ) <EOL> def test_image_set_bools1 ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_bools2 ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_properties ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT:2>' } ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_fake_properties ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_tag ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_activate ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> self . images_mock . reactivate . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ) <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_deactivate ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> self . images_mock . deactivate . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ) <EOL> self . images_mock . update . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_tag_merge ( self ) : <EOL> old_image = copy . copy ( image_fakes . IMAGE ) <EOL> old_image [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . images_mock . get . return_value = self . model ( ** old_image ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } <EOL> a , k = self . images_mock . update . call_args <EOL> self . assertEqual ( image_fakes . image_id , a [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( '<STR_LIT>' in k ) <EOL> self . assertEqual ( set ( kwargs [ '<STR_LIT>' ] ) , set ( k [ '<STR_LIT>' ] ) ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_tag_merge_dupe ( self ) : <EOL> old_image = copy . copy ( image_fakes . IMAGE ) <EOL> old_image [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . images_mock . get . return_value = self . model ( ** old_image ) <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' ] ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } <EOL> a , k = self . images_mock . update . call_args <EOL> self . assertEqual ( image_fakes . image_id , a [ <NUM_LIT:0> ] ) <EOL> self . assertTrue ( '<STR_LIT>' in k ) <EOL> self . assertEqual ( set ( kwargs [ '<STR_LIT>' ] ) , set ( k [ '<STR_LIT>' ] ) ) <EOL> self . assertIsNone ( result ) <EOL> def test_image_set_dead_options ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> image_fakes . image_name , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:image>' , image_fakes . image_name ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , parsed_args ) <EOL> class TestImageShow ( TestImage ) : <EOL> def setUp ( self ) : <EOL> super ( TestImageShow , self ) . setUp ( ) <EOL> self . model = warlock . model_factory ( <EOL> image_fakes . IMAGE_schema , <EOL> schemas . SchemaBasedModel , <EOL> ) <EOL> self . images_mock . get . return_value = self . model ( ** image_fakes . IMAGE ) <EOL> self . cmd = image . ShowImage ( self . app , None ) <EOL> def test_image_show ( self ) : <EOL> arglist = [ <EOL> image_fakes . image_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT:image>' , image_fakes . image_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . images_mock . get . assert_called_with ( <EOL> image_fakes . image_id , <EOL> ) <EOL> self . assertEqual ( image_fakes . IMAGE_columns , columns ) <EOL> self . assertEqual ( image_fakes . IMAGE_SHOW_data , data ) </s>
