def test_caching_gziptext(self, gziptext_cache): """Test the caching of an XML containing strange characters. Test whether the data is saved in the cache. Parameters ---------- gziptext_cache : pytest.fixture providing pydov.util.caching.GzipTextFileCache GzipTextFileCache using a temporary directory and a maximum age of 1 second. """ cached_file = os.path.join(gziptext_cache.cachedir, 'boring', '1995-056089.xml.gz') gziptext_cache.clean() assert not os.path.exists(cached_file) gziptext_cache.get(build_dov_url('data/boring/1995-056089.xml')), assert os.path.exists(cached_file) with gzip.open(cached_file, 'rb') as cf: cached_data = cf.read().decode('utf-8') assert cached_data != "" first_download_time = os.path.getmtime(cached_file) time.sleep(0.5) gziptext_cache.get(build_dov_url('data/boring/1995-056089.xml')) # assure we didn't redownload the file: assert os.path.getmtime(cached_file) == first_download_time
def test_reuse_content_gziptext(self, gziptext_cache): """Test the caching of an XML containing strange characters. Test if the contents returned by the cache are the same as the original data. Parameters ---------- gziptext_cache : pytest.fixture providing pydov.util.caching.GzipTextFileCache GzipTextFileCache using a temporary directory and a maximum age of 1 second. """ cached_file = os.path.join(gziptext_cache.cachedir, 'boring', '1995-056089.xml.gz') gziptext_cache.remove() assert not os.path.exists(cached_file) ref_data = gziptext_cache.get( build_dov_url('data/boring/1995-056089.xml')) assert os.path.exists(cached_file) cached_data = gziptext_cache.get( build_dov_url('data/boring/1995-056089.xml')) assert cached_data == ref_data
def test_save_content_gziptext(self, gziptext_cache): """Test the caching of an XML containing strange characters. Test if the contents of the saved document are the same as the original data. Parameters ---------- gziptext_cache : pytest.fixture providing pydov.util.caching.GzipTextFileCache GzipTextFileCache using a temporary directory and a maximum age of 1 second. """ cached_file = os.path.join(gziptext_cache.cachedir, 'boring', '1995-056089.xml.gz') gziptext_cache.remove() assert not os.path.exists(cached_file) ref_data = gziptext_cache.get( 'https://www.dov.vlaanderen.be/data/boring/1995-056089.xml') assert os.path.exists(cached_file) with gzip.open(cached_file, 'rb') as cached: cached_data = cached.read() assert cached_data == ref_data