def test_cache_delete_url(): cache = Cache(CACHE_DIR) path = cache.fetch(TEST_URL, filename=TEST_FILENAME) assert exists(path), "Expected %s to exist after download" % path cache.delete_url(TEST_URL) assert not exists(path), \ "Expected %s to be deleted after call to delete_url" % path
def test_cache_fetch_google(): cache = Cache(CACHE_DIR) path = cache.fetch(TEST_URL, filename=TEST_FILENAME) assert path.endswith(TEST_FILENAME), \ "Expected local file to be named %s but got %s" % ( TEST_FILENAME, path) assert exists(path), "File not found: %s" % path eq_(path, cache.local_path(TEST_URL, filename=TEST_FILENAME))
def test_cache_missing_file(): """test_cache_missing_file : Files can be deleted from the file system, Cache should be aware that these files no longer exist """ cache = Cache(CACHE_DIR) path = cache.fetch(TEST_URL, filename=TEST_FILENAME) # does the filename exist? assert exists(path) # does the cache know the URL has been downloaded? assert cache.exists(TEST_URL, filename=TEST_FILENAME) remove(path) assert not cache.exists(TEST_URL, filename=TEST_FILENAME), \ "Local file for %s has been deleted from the file system" % TEST_URL
def test_cache_fetch_force(mock_download): cache = Cache("datacache_test") cache.fetch("http://www.google.com", filename="google", force=True) cache.fetch("http://www.google.com", filename="google", force=True) assert len(mock_download.call_args_list) == 2, \ "Expected two separate calls to _download, given force=True"