def test_remove_garbage_vhds_none(self, mockMetabase): # Setup some mocks callbacks = mock.MagicMock() mockDB = mock.MagicMock() mockMetabase.return_value = mockDB mockDB.write_context.side_effect = test_context mockDB.get_garbage_vhds.return_value = [] # call the code coalesce.remove_garbage_vhds("test-uri", callbacks) # check the results callbacks.volumeStartOperations.assert_called_with("test-uri", 'w') callbacks.volumeStopOperations.assert_called() callbacks.volumeDestroy.assert_not_called() mockDB.get_garbage_vhds.assert_called() mockDB.delete_vhd.assert_not_called()
def test_remove_garbage_vhds_two(self, mockMetabase): # Setup some mocks callbacks = mock.MagicMock() mockDB = mock.MagicMock() mockMetabase.return_value = mockDB mockDB.write_context.side_effect = test_context mockDB.get_garbage_vhds.return_value = [ VHD( 4, 3, 0, 10*1024, 10*1024 ), VHD( 5, 3, 0, 10*1024, 10*1024 ) ] # call the code coalesce.remove_garbage_vhds("test-uri", callbacks) # check the results callbacks.volumeStartOperations.assert_called_with("test-uri", 'w') callbacks.volumeStopOperations.assert_called() callbacks.volumeDestroy.assert_has_calls( [mock.call(mock.ANY, str(4)),mock.call(mock.ANY, str(5))], any_order=True) self.assertEquals(2, callbacks.volumeDestroy.call_count) mockDB.get_garbage_vhds.assert_called() mockDB.delete_vhd.assert_has_calls( [mock.call(4), mock.call(5)], any_order=True) self.assertEquals(2, mockDB.delete_vhd.call_count)