<s> import datetime <EOL> from oslo_serialization import jsonutils <EOL> import webob <EOL> from nova . compute import flavors <EOL> from nova import test <EOL> from nova . tests . unit . api . openstack import fakes <EOL> def fake_get_flavor_by_flavor_id ( flavorid , ctxt = None ) : <EOL> return { <EOL> '<STR_LIT:id>' : flavorid , <EOL> '<STR_LIT>' : str ( flavorid ) , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:name>' : u'<STR_LIT:test>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> def fake_get_all_flavors_sorted_list ( context = None , inactive = False , <EOL> filters = None , sort_key = '<STR_LIT>' , <EOL> sort_dir = '<STR_LIT>' , limit = None , marker = None ) : <EOL> return [ <EOL> fake_get_flavor_by_flavor_id ( <NUM_LIT:1> ) , <EOL> fake_get_flavor_by_flavor_id ( <NUM_LIT:2> ) <EOL> ] <EOL> class FlavorExtraDataTestV21 ( test . NoDBTestCase ) : <EOL> base_url = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( FlavorExtraDataTestV21 , self ) . setUp ( ) <EOL> ext = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . flags ( osapi_compute_extension = [ ext ] ) <EOL> self . stubs . Set ( flavors , '<STR_LIT>' , <EOL> fake_get_flavor_by_flavor_id ) <EOL> self . stubs . Set ( flavors , '<STR_LIT>' , <EOL> fake_get_all_flavors_sorted_list ) <EOL> @ property <EOL> def app ( self ) : <EOL> return fakes . wsgi_app_v21 ( init_only = ( '<STR_LIT>' ) ) <EOL> def _verify_flavor_response ( self , flavor , expected ) : <EOL> for key in expected : <EOL> self . assertEqual ( flavor [ key ] , expected [ key ] ) <EOL> def test_show ( self ) : <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } <EOL> } <EOL> url = self . base_url + '<STR_LIT>' <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT:application/json>' <EOL> res = req . get_response ( self . app ) <EOL> body = jsonutils . loads ( res . body ) <EOL> self . _verify_flavor_response ( body [ '<STR_LIT>' ] , expected [ '<STR_LIT>' ] ) <EOL> def test_detail ( self ) : <EOL> expected = [ <EOL> { <EOL> '<STR_LIT:id>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , <EOL> { <EOL> '<STR_LIT:id>' : '<STR_LIT:2>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , <EOL> ] <EOL> url = self . base_url + '<STR_LIT>' <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT:application/json>' <EOL> res = req . get_response ( self . app ) <EOL> body = jsonutils . loads ( res . body ) <EOL> for i , flavor in enumerate ( body [ '<STR_LIT>' ] ) : <EOL> self . _verify_flavor_response ( flavor , expected [ i ] ) <EOL> class FlavorExtraDataTestV2 ( FlavorExtraDataTestV21 ) : <EOL> @ property <EOL> def app ( self ) : <EOL> return fakes . wsgi_app ( init_only = ( '<STR_LIT>' , ) ) </s>
