'Test to see if open_for_write works in a failure case for each driver
This case is where an exception is raised while the file is being
written. The image is partially filled in cache and filling wont resume
so verify the image is moved to invalid/ directory'

def test_open_for_write_with_exception(self):

    image_id = '1'
    self.assertFalse(self.cache.is_cached(image_id))
    try:
        with self.cache.driver.open_for_write(image_id):
            raise IOError
    except Exception as e:
        self.assertIsInstance(e, IOError)
    self.assertFalse(self.cache.is_cached(image_id), ('Image    %s    was    cached!' % image_id))
    incomplete_file_path = os.path.join(self.cache_dir, 'incomplete', image_id)
    invalid_file_path = os.path.join(self.cache_dir, 'invalid', image_id)
    self.assertFalse(os.path.exists(incomplete_file_path))
    self.assertTrue(os.path.exists(invalid_file_path))
