<s> import mock <EOL> from nova import db <EOL> from nova . objects import virtual_interface as vif_obj <EOL> from nova . tests . unit . objects import test_objects <EOL> fake_vif = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> class _TestVirtualInterface ( object ) : <EOL> @ staticmethod <EOL> def _compare ( test , db , obj ) : <EOL> for field , value in db . items ( ) : <EOL> test . assertEqual ( db [ field ] , getattr ( obj , field ) ) <EOL> def test_get_by_id ( self ) : <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as get : <EOL> get . return_value = fake_vif <EOL> vif = vif_obj . VirtualInterface . get_by_id ( self . context , <NUM_LIT:1> ) <EOL> self . _compare ( self , fake_vif , vif ) <EOL> def test_get_by_uuid ( self ) : <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as get : <EOL> get . return_value = fake_vif <EOL> vif = vif_obj . VirtualInterface . get_by_uuid ( self . context , <EOL> '<STR_LIT>' ) <EOL> self . _compare ( self , fake_vif , vif ) <EOL> def test_get_by_address ( self ) : <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as get : <EOL> get . return_value = fake_vif <EOL> vif = vif_obj . VirtualInterface . get_by_address ( self . context , <EOL> '<STR_LIT>' ) <EOL> self . _compare ( self , fake_vif , vif ) <EOL> def test_get_by_instance_and_network ( self ) : <EOL> with mock . patch . object ( db , <EOL> '<STR_LIT>' ) as get : <EOL> get . return_value = fake_vif <EOL> vif = vif_obj . VirtualInterface . get_by_instance_and_network ( <EOL> self . context , '<STR_LIT>' , <NUM_LIT> ) <EOL> self . _compare ( self , fake_vif , vif ) <EOL> def test_create ( self ) : <EOL> vif = vif_obj . VirtualInterface ( context = self . context ) <EOL> vif . address = '<STR_LIT>' <EOL> vif . network_id = <NUM_LIT> <EOL> vif . instance_uuid = '<STR_LIT>' <EOL> vif . uuid = '<STR_LIT>' <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as create : <EOL> create . return_value = fake_vif <EOL> vif . create ( ) <EOL> self . assertEqual ( self . context , vif . _context ) <EOL> vif . _context = None <EOL> self . _compare ( self , fake_vif , vif ) <EOL> def test_delete_by_instance_uuid ( self ) : <EOL> with mock . patch . object ( db , <EOL> '<STR_LIT>' ) as delete : <EOL> vif_obj . VirtualInterface . delete_by_instance_uuid ( self . context , <EOL> '<STR_LIT>' ) <EOL> delete . assert_called_with ( self . context , '<STR_LIT>' ) <EOL> class TestVirtualInterfaceObject ( test_objects . _LocalTest , <EOL> _TestVirtualInterface ) : <EOL> pass <EOL> class TestRemoteVirtualInterfaceObject ( test_objects . _RemoteTest , <EOL> _TestVirtualInterface ) : <EOL> pass <EOL> class _TestVirtualInterfaceList ( object ) : <EOL> def test_get_all ( self ) : <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as get : <EOL> get . return_value = [ fake_vif ] <EOL> vifs = vif_obj . VirtualInterfaceList . get_all ( self . context ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( vifs ) ) <EOL> _TestVirtualInterface . _compare ( self , fake_vif , vifs [ <NUM_LIT:0> ] ) <EOL> def test_get_by_instance_uuid ( self ) : <EOL> with mock . patch . object ( db , '<STR_LIT>' ) as get : <EOL> get . return_value = [ fake_vif ] <EOL> vifs = vif_obj . VirtualInterfaceList . get_by_instance_uuid ( <EOL> self . context , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( vifs ) ) <EOL> _TestVirtualInterface . _compare ( self , fake_vif , vifs [ <NUM_LIT:0> ] ) <EOL> class TestVirtualInterfaceList ( test_objects . _LocalTest , <EOL> _TestVirtualInterfaceList ) : <EOL> pass <EOL> class TestRemoteVirtualInterfaceList ( test_objects . _RemoteTest , <EOL> _TestVirtualInterfaceList ) : <EOL> pass </s>
