def test_do_not_overwrite_stale_cache(self):
        """Test whether a stale copy of the data which exists in the cache is
        not overwritten by the 404 error page."""
        bs = BoringSearch(objecttype=pydov.types.boring.Boring)

        testdata_path = os.path.join(
            'tests', 'data', 'types', 'boring', 'boring.xml')

        cache_path = os.path.join(
            pydov.cache.cachedir, 'boring', '2004-103984.xml.gz'
        )
        os.makedirs(os.path.dirname(cache_path))

        with open(testdata_path, 'r') as testdata:
            with gzip.open(cache_path, 'wb') as cached_data:
                cached_data.write(testdata.read().encode('utf8'))
        time.sleep(0.5)

        bs.search(query=PropertyIsEqualTo(
            'pkey_boring', build_dov_url('data/boring/2004-103984')))

        with gzip.open(cache_path, 'rb') as cached_data:
            assert 'GEO-04/169-BNo-B1' in cached_data.read().decode('utf8')