#NEWLINE# @ mock . patch ( 'nova.objects.instance.Instance.obj_make_compatible' ) #NEWLINE# def test_get_by_security_group( self , mock_compat ) : #NEWLINE# #INDENT# fake_secgroup = dict ( test_security_group . fake_secgroup ) #NEWLINE# fake_secgroup [ 'instances' ] = [ fake_instance . fake_db_instance ( id = 1 , system_metadata = { #NEWLINE# #INDENT# 'foo' : 'bar' , #NEWLINE# #UNINDENT# } ) , fake_instance . fake_db_instance ( id = 2 ) ] #NEWLINE# with mock . patch . object ( db , 'security_group_get' ) as sgg : #NEWLINE# #INDENT# sgg . return_value = fake_secgroup #NEWLINE# secgroup = security_group . SecurityGroup ( ) #NEWLINE# secgroup . id = fake_secgroup [ 'id' ] #NEWLINE# instances = instance . InstanceList . get_by_security_group ( self . context , instances ) #NEWLINE# #UNINDENT# self . assertEqual ( 2 , len ( instances ) ) #NEWLINE# self . assertEqual ( [ 1 , 2 ] , [ x . id for x in instances ] ) #NEWLINE# self . assertTrue ( instances [ 0 ] . obj_attr_is_set ( 'system_metadata' ) ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'foo' : 'bar' , #NEWLINE# #UNINDENT# } , instances [ 0 ] . system_metadata )