#NEWLINE# @ mock . patch ( 'changes.lib.snapshot_garbage_collection.get_current_datetime' ) #NEWLINE# @ mock . patch ( 'changes.lib.snapshot_garbage_collection.get_plans_for_cluster' ) #NEWLINE# def test_cached_snapshot_images_all( self , get_plans , get_current_datetime ) : #NEWLINE# #INDENT# '\n        Tests the four fundamental cases for an image:\n         - No expiration date\n         - Not yet expired\n         - Expired\n         - Not part of the plans associated with the cluster\n        ' #NEWLINE# project = self . create_project ( ) #NEWLINE# plan1 = self . create_plan ( project ) #NEWLINE# plan2 = self . create_plan ( project ) #NEWLINE# plan3 = self . create_plan ( project ) #NEWLINE# plan4 = self . create_plan ( project ) #NEWLINE# get_current_datetime . return_value = self . mock_datetime #NEWLINE# get_plans . return_value = { plan1 , plan2 , plan3 } #NEWLINE# snapshot = self . create_snapshot ( project ) #NEWLINE# snapshot_image1 = self . create_snapshot_image ( snapshot , plan1 ) #NEWLINE# snapshot_image2 = self . create_snapshot_image ( snapshot , plan2 ) #NEWLINE# snapshot_image3 = self . create_snapshot_image ( snapshot , plan3 ) #NEWLINE# snapshot_image4 = self . create_snapshot_image ( snapshot , plan4 ) #NEWLINE# self . create_cached_snapshot_image ( snapshot_image1 , expiration_date = None ) #NEWLINE# self . create_cached_snapshot_image ( snapshot_image2 , expiration_date = ( self . mock_datetime + datetime . timedelta ( 0 , 1 ) ) ) #NEWLINE# self . create_cached_snapshot_image ( snapshot_image3 , expiration_date = ( self . mock_datetime - datetime . timedelta ( 0 , 1 ) ) ) #NEWLINE# self . create_cached_snapshot_image ( s , expiration_date = None ) #NEWLINE# cached_snapshot_ids = [ s . id for s in gc . get_cached_snapshot_images ( 'cluster' ) ] #NEWLINE# assert ( len ( cached_snapshot_ids ) == 2 ) #NEWLINE# assert ( snapshot_image1 . id in cached_snapshot_ids ) #NEWLINE# assert ( snapshot_image2 . id in cached_snapshot_ids )