'Test to see if the caching iterator interacts properly with the driver
in a case where the iterator is only partially consumed. In this case
the image is only partially filled in cache and filling wont resume.
When the iterator goes out of scope the driver should have closed the
image and moved it from incomplete/ to invalid/'

def test_caching_iterator_falloffend(self):

    def falloffend(image_id):
        data = ['a', 'b', 'c', 'd', 'e', 'f']
        checksum = None
        caching_iter = self.cache.get_caching_iter(image_id, checksum, iter(data))
        self.assertEqual('a', next(caching_iter))
    image_id = '1'
    self.assertFalse(self.cache.is_cached(image_id))
    falloffend(image_id)
    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))
