<s> import mock <EOL> from oslo_serialization import jsonutils <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova . objects import build_request <EOL> from nova . tests . unit import fake_build_request <EOL> from nova . tests . unit import fake_instance <EOL> from nova . tests . unit . objects import test_objects <EOL> class _TestBuildRequestObject ( object ) : <EOL> @ mock . patch . object ( build_request . BuildRequest , <EOL> '<STR_LIT>' ) <EOL> def test_get_by_instance_uuid ( self , get_by_uuid ) : <EOL> fake_req = fake_build_request . fake_db_req ( ) <EOL> get_by_uuid . return_value = fake_req <EOL> req_obj = build_request . BuildRequest . get_by_instance_uuid ( self . context , <EOL> fake_req [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( fake_req [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> req_obj . request_spec . instance_uuid ) <EOL> self . assertEqual ( fake_req [ '<STR_LIT>' ] , req_obj . instance_uuid ) <EOL> self . assertEqual ( fake_req [ '<STR_LIT>' ] , req_obj . project_id ) <EOL> self . assertIsInstance ( req_obj . request_spec , objects . RequestSpec ) <EOL> self . assertIsInstance ( req_obj . instance , objects . Instance ) <EOL> get_by_uuid . assert_called_once_with ( self . context , <EOL> fake_req [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( build_request . BuildRequest , <EOL> '<STR_LIT>' ) <EOL> def test_get_by_instance_uuid_instance_none ( self , get_by_uuid ) : <EOL> fake_req = fake_build_request . fake_db_req ( ) <EOL> fake_req [ '<STR_LIT>' ] = None <EOL> get_by_uuid . return_value = fake_req <EOL> self . assertRaises ( exception . BuildRequestNotFound , <EOL> build_request . BuildRequest . get_by_instance_uuid , self . context , <EOL> fake_req [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( build_request . BuildRequest , <EOL> '<STR_LIT>' ) <EOL> def test_get_by_instance_uuid_instance_version_too_new ( self , get_by_uuid ) : <EOL> fake_req = fake_build_request . fake_db_req ( ) <EOL> instance = fake_instance . fake_instance_obj ( self . context , <EOL> objects . Instance , uuid = fake_req [ '<STR_LIT>' ] ) <EOL> instance . VERSION = '<STR_LIT>' <EOL> fake_req [ '<STR_LIT>' ] = jsonutils . dumps ( instance . obj_to_primitive ) <EOL> get_by_uuid . return_value = fake_req <EOL> self . assertRaises ( exception . BuildRequestNotFound , <EOL> build_request . BuildRequest . get_by_instance_uuid , self . context , <EOL> fake_req [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( build_request . BuildRequest , <EOL> '<STR_LIT>' ) <EOL> def test_create ( self , create_in_db ) : <EOL> fake_req = fake_build_request . fake_db_req ( ) <EOL> req_obj = fake_build_request . fake_req_obj ( self . context , fake_req ) <EOL> def _test_create_args ( self2 , context , changes ) : <EOL> for field in [ fields for fields in <EOL> build_request . BuildRequest . fields if fields not in <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' ] ] : <EOL> self . assertEqual ( fake_req [ field ] , changes [ field ] ) <EOL> self . assertEqual ( fake_req [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> changes [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> jsonutils . dumps ( req_obj . instance . obj_to_primitive ( ) ) , <EOL> changes [ '<STR_LIT>' ] ) <EOL> return fake_req <EOL> with mock . patch . object ( build_request . BuildRequest , '<STR_LIT>' , <EOL> _test_create_args ) : <EOL> req_obj . create ( ) <EOL> def test_create_id_set ( self ) : <EOL> req_obj = build_request . BuildRequest ( self . context ) <EOL> req_obj . id = <NUM_LIT:3> <EOL> self . assertRaises ( exception . ObjectActionError , req_obj . create ) <EOL> def test_create_uuid_set ( self ) : <EOL> req_obj = build_request . BuildRequest ( self . context ) <EOL> self . assertRaises ( exception . ObjectActionError , req_obj . create ) <EOL> @ mock . patch . object ( build_request . BuildRequest , '<STR_LIT>' ) <EOL> def test_destroy ( self , destroy_in_db ) : <EOL> req_obj = build_request . BuildRequest ( self . context ) <EOL> req_obj . id = <NUM_LIT:1> <EOL> req_obj . destroy ( ) <EOL> destroy_in_db . assert_called_once_with ( self . context , req_obj . id ) <EOL> class TestBuildRequestObject ( test_objects . _LocalTest , <EOL> _TestBuildRequestObject ) : <EOL> pass <EOL> class TestRemoteBuildRequestObject ( test_objects . _RemoteTest , <EOL> _TestBuildRequestObject ) : <EOL> pass </s>
