<s> import copy <EOL> import mock <EOL> import random <EOL> import uuid <EOL> from openstackclient . common import utils as common_utils <EOL> from openstackclient . tests import fakes <EOL> from openstackclient . tests import utils <EOL> from openstackclient . tests . identity . v3 import fakes as identity_fakes <EOL> image_id = '<STR_LIT>' <EOL> image_name = '<STR_LIT>' <EOL> image_owner = '<STR_LIT>' <EOL> image_protected = False <EOL> image_visibility = '<STR_LIT>' <EOL> image_tags = [ ] <EOL> IMAGE = { <EOL> '<STR_LIT:id>' : image_id , <EOL> '<STR_LIT:name>' : image_name , <EOL> '<STR_LIT>' : image_owner , <EOL> '<STR_LIT>' : image_protected , <EOL> '<STR_LIT>' : image_visibility , <EOL> '<STR_LIT>' : image_tags <EOL> } <EOL> IMAGE_columns = tuple ( sorted ( IMAGE ) ) <EOL> IMAGE_data = tuple ( ( IMAGE [ x ] for x in sorted ( IMAGE ) ) ) <EOL> IMAGE_SHOW = copy . copy ( IMAGE ) <EOL> IMAGE_SHOW [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> IMAGE_SHOW_data = tuple ( ( IMAGE_SHOW [ x ] for x in sorted ( IMAGE_SHOW ) ) ) <EOL> member_status = '<STR_LIT>' <EOL> MEMBER = { <EOL> '<STR_LIT>' : identity_fakes . project_id , <EOL> '<STR_LIT>' : image_id , <EOL> '<STR_LIT:status>' : member_status , <EOL> } <EOL> IMAGE_schema = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } , <EOL> "<STR_LIT:name>" : "<STR_LIT:image>" , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:name>" : { <EOL> "<STR_LIT:type>" : [ <EOL> "<STR_LIT:null>" , <EOL> "<STR_LIT:string>" <EOL> ] , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:255> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : [ <EOL> "<STR_LIT:null>" , <EOL> "<STR_LIT:string>" <EOL> ] , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:255> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:size>" : { <EOL> "<STR_LIT:type>" : [ <EOL> "<STR_LIT:null>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:status>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : <NUM_LIT:255> <EOL> } , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" <EOL> } , <EOL> } <EOL> } <EOL> class FakeImagev2Client ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . images = mock . Mock ( ) <EOL> self . images . resource_class = fakes . FakeResource ( None , { } ) <EOL> self . image_members = mock . Mock ( ) <EOL> self . image_members . resource_class = fakes . FakeResource ( None , { } ) <EOL> self . auth_token = kwargs [ '<STR_LIT>' ] <EOL> self . management_url = kwargs [ '<STR_LIT>' ] <EOL> class TestImagev2 ( utils . TestCommand ) : <EOL> def setUp ( self ) : <EOL> super ( TestImagev2 , self ) . setUp ( ) <EOL> self . app . client_manager . image = FakeImagev2Client ( <EOL> endpoint = fakes . AUTH_URL , <EOL> token = fakes . AUTH_TOKEN , <EOL> ) <EOL> self . app . client_manager . identity = identity_fakes . FakeIdentityv3Client ( <EOL> endpoint = fakes . AUTH_URL , <EOL> token = fakes . AUTH_TOKEN , <EOL> ) <EOL> class FakeImage ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def create_one_image ( attrs = None ) : <EOL> """<STR_LIT>""" <EOL> attrs = attrs or { } <EOL> image_info = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' + uuid . uuid4 ( ) . hex , <EOL> '<STR_LIT:name>' : '<STR_LIT>' + uuid . uuid4 ( ) . hex , <EOL> '<STR_LIT>' : '<STR_LIT>' + uuid . uuid4 ( ) . hex , <EOL> '<STR_LIT>' : bool ( random . choice ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) , <EOL> '<STR_LIT>' : random . choice ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : [ uuid . uuid4 ( ) . hex for r in range ( <NUM_LIT:2> ) ] , <EOL> } <EOL> image_info . update ( attrs ) <EOL> image = fakes . FakeResource ( <EOL> None , <EOL> image_info , <EOL> loaded = True ) <EOL> return image <EOL> @ staticmethod <EOL> def create_images ( attrs = None , count = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> images = [ ] <EOL> for n in range ( <NUM_LIT:0> , count ) : <EOL> images . append ( FakeImage . create_one_image ( attrs ) ) <EOL> return images <EOL> @ staticmethod <EOL> def get_images ( images = None , count = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> if images is None : <EOL> images = FakeImage . create_images ( count ) <EOL> return mock . MagicMock ( side_effect = images ) <EOL> @ staticmethod <EOL> def get_image_info ( image = None ) : <EOL> """<STR_LIT>""" <EOL> if image is not None : <EOL> return image . _info <EOL> return { } <EOL> @ staticmethod <EOL> def get_image_columns ( image = None ) : <EOL> """<STR_LIT>""" <EOL> if image is not None : <EOL> return tuple ( k for k in sorted ( <EOL> FakeImage . get_image_info ( image ) . keys ( ) ) ) <EOL> return tuple ( [ ] ) <EOL> @ staticmethod <EOL> def get_image_data ( image = None ) : <EOL> """<STR_LIT>""" <EOL> data_list = [ ] <EOL> if image is not None : <EOL> for x in sorted ( FakeImage . get_image_info ( image ) . keys ( ) ) : <EOL> if x == '<STR_LIT>' : <EOL> data_list . append ( <EOL> common_utils . format_list ( getattr ( image , x ) ) ) <EOL> else : <EOL> data_list . append ( getattr ( image , x ) ) <EOL> return tuple ( data_list ) </s>
