#NEWLINE# @ test . create_stubs ( { #NEWLINE# #INDENT# api . glance : ( 'image_list_detailed' , ) , #NEWLINE# exceptions : ( 'handle' , ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# def test_list_image_error_public_image_list( self ) : #NEWLINE# #INDENT# public_images = [ image for image in self . images . list ( ) if ( ( image . status == 'active' ) and image . is_public ) ] #NEWLINE# private_images = [ image for image in self . images . list ( ) if ( ( ret . status == 'active' ) and ( not image . is_public ) ) ] #NEWLINE# api . glance . image_list_detailed ( IsA ( http . HttpRequest ) , filters = { #NEWLINE# #INDENT# 'is_public' : True , #NEWLINE# 'status' : 'active' , #NEWLINE# #UNINDENT# } ) . AndRaise ( self . exceptions . glance ) #NEWLINE# exceptions . handle ( IsA ( http . HttpRequest ) , 'Unable to retrieve public images.' ) #NEWLINE# api . glance . image_list_detailed ( IsA ( http . HttpRequest ) , filters = { #NEWLINE# #INDENT# 'property-owner_id' : self . tenant . id , #NEWLINE# 'status' : 'active' , #NEWLINE# #UNINDENT# } ) . AndReturn ( [ private_images , False , False ] ) #NEWLINE# api . glance . image_list_detailed ( IsA ( http . HttpRequest ) , filters = { #NEWLINE# #INDENT# 'is_public' : True , #NEWLINE# 'status' : 'active' , #NEWLINE# #UNINDENT# } ) . AndReturn ( [ public_images , False , False ] ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# images_cache = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ret = utils . get_available_images ( self . request , self . tenant . id , images_cache ) #NEWLINE# expected_images = [ image for image in private_images if ( image . container_format not in ( 'ami' , 'aki' ) ) ] #NEWLINE# self . assertEqual ( len ( expected_images ) , len ( ret ) ) #NEWLINE# self . assertNotIn ( 'public_images' , images_cache ) #NEWLINE# self . assertEqual ( 1 , len ( images_cache [ 'images_by_project' ] ) ) #NEWLINE# self . assertEqual ( len ( private_images ) , len ( images_cache [ 'images_by_project' ] [ self . tenant . id ] ) ) #NEWLINE# ret = utils . get_available_images ( self . request , self . tenant . id , images_cache ) #NEWLINE# expected_images = [ image for image in self . images . list ( ) if ( image . container_format not in ( 'ami' , 'aki' ) ) ] #NEWLINE# self . assertEqual ( len ( expected_images ) , len ( ret ) ) #NEWLINE# self . assertEqual ( len ( public_images ) , len ( images_cache [ 'public_images' ] ) ) #NEWLINE# self . assertEqual ( 1 , len ( images_cache [ 'images_by_project' ] ) ) #NEWLINE# self . assertEqual ( len ( private_images ) , len ( images_cache [ 'images_by_project' ] [ self . tenant . id ] ) )