<s> from oslo_serialization import jsonutils <EOL> import webob <EOL> from nova import compute <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova . objects import instance as instance_obj <EOL> from nova import test <EOL> from nova . tests . unit . api . openstack import fakes <EOL> from nova . tests . unit import fake_instance <EOL> UUID1 = '<STR_LIT>' <EOL> UUID2 = '<STR_LIT>' <EOL> UUID3 = '<STR_LIT>' <EOL> def fake_compute_get ( * args , ** kwargs ) : <EOL> inst = fakes . stub_instance ( <NUM_LIT:1> , uuid = UUID3 , task_state = "<STR_LIT>" , <EOL> vm_state = "<STR_LIT>" , power_state = <NUM_LIT:1> ) <EOL> return fake_instance . fake_instance_obj ( args [ <NUM_LIT:1> ] , ** inst ) <EOL> def fake_compute_get_all ( * args , ** kwargs ) : <EOL> db_list = [ <EOL> fakes . stub_instance ( <NUM_LIT:1> , uuid = UUID1 , task_state = "<STR_LIT>" , <EOL> vm_state = "<STR_LIT>" , power_state = <NUM_LIT:1> ) , <EOL> fakes . stub_instance ( <NUM_LIT:2> , uuid = UUID2 , task_state = "<STR_LIT>" , <EOL> vm_state = "<STR_LIT>" , power_state = <NUM_LIT:2> ) , <EOL> ] <EOL> fields = instance_obj . INSTANCE_DEFAULT_FIELDS <EOL> return instance_obj . _make_instance_list ( args [ <NUM_LIT:1> ] , <EOL> objects . InstanceList ( ) , <EOL> db_list , fields ) <EOL> class ExtendedStatusTestV21 ( test . TestCase ) : <EOL> content_type = '<STR_LIT:application/json>' <EOL> prefix = '<STR_LIT>' <EOL> fake_url = '<STR_LIT>' <EOL> def _set_flags ( self ) : <EOL> pass <EOL> def _make_request ( self , url ) : <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT>' ] = self . content_type <EOL> res = req . get_response ( fakes . wsgi_app_v21 ( <EOL> init_only = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) ) <EOL> return res <EOL> def setUp ( self ) : <EOL> super ( ExtendedStatusTestV21 , self ) . setUp ( ) <EOL> fakes . stub_out_nw_api ( self ) <EOL> self . stubs . Set ( compute . api . API , '<STR_LIT>' , fake_compute_get ) <EOL> self . stubs . Set ( compute . api . API , '<STR_LIT>' , fake_compute_get_all ) <EOL> self . _set_flags ( ) <EOL> return_server = fakes . fake_instance_get ( ) <EOL> self . stub_out ( '<STR_LIT>' , return_server ) <EOL> def _get_server ( self , body ) : <EOL> return jsonutils . loads ( body ) . get ( '<STR_LIT>' ) <EOL> def _get_servers ( self , body ) : <EOL> return jsonutils . loads ( body ) . get ( '<STR_LIT>' ) <EOL> def assertServerStates ( self , server , vm_state , power_state , task_state ) : <EOL> self . assertEqual ( server . get ( '<STR_LIT>' % self . prefix ) , vm_state ) <EOL> self . assertEqual ( int ( server . get ( '<STR_LIT>' % self . prefix ) ) , <EOL> power_state ) <EOL> self . assertEqual ( server . get ( '<STR_LIT>' % self . prefix ) , task_state ) <EOL> def test_show ( self ) : <EOL> url = self . fake_url + '<STR_LIT>' % UUID3 <EOL> res = self . _make_request ( url ) <EOL> self . assertEqual ( res . status_int , <NUM_LIT:200> ) <EOL> self . assertServerStates ( self . _get_server ( res . body ) , <EOL> vm_state = '<STR_LIT>' , <EOL> power_state = <NUM_LIT:1> , <EOL> task_state = '<STR_LIT>' ) <EOL> def test_detail ( self ) : <EOL> url = self . fake_url + '<STR_LIT>' <EOL> res = self . _make_request ( url ) <EOL> self . assertEqual ( res . status_int , <NUM_LIT:200> ) <EOL> for i , server in enumerate ( self . _get_servers ( res . body ) ) : <EOL> self . assertServerStates ( server , <EOL> vm_state = '<STR_LIT>' % ( i + <NUM_LIT:1> ) , <EOL> power_state = ( i + <NUM_LIT:1> ) , <EOL> task_state = '<STR_LIT>' % ( i + <NUM_LIT:1> ) ) <EOL> def test_no_instance_passthrough_404 ( self ) : <EOL> def fake_compute_get ( * args , ** kwargs ) : <EOL> raise exception . InstanceNotFound ( instance_id = '<STR_LIT>' ) <EOL> self . stubs . Set ( compute . api . API , '<STR_LIT>' , fake_compute_get ) <EOL> url = self . fake_url + '<STR_LIT>' <EOL> res = self . _make_request ( url ) <EOL> self . assertEqual ( res . status_int , <NUM_LIT> ) <EOL> class ExtendedStatusTestV2 ( ExtendedStatusTestV21 ) : <EOL> def _set_flags ( self ) : <EOL> self . flags ( <EOL> osapi_compute_extension = [ <EOL> '<STR_LIT>' ] , <EOL> osapi_compute_ext_list = [ '<STR_LIT>' ] ) <EOL> def _make_request ( self , url ) : <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT>' ] = self . content_type <EOL> res = req . get_response ( fakes . wsgi_app ( init_only = ( '<STR_LIT>' , ) ) ) <EOL> return res </s>
