def test_read_from_dbhash_works(self): dbh = DictDbHash({ "etag:http://boop": "blah", "last_modified:http://boop": "flarg" }) assert LastmodInfo.read_from_dbhash("http://boop", dbh) == LastmodInfo( url="http://boop", etag="blah", last_modified="flarg") assert LastmodInfo.read_from_dbhash("http://bar", dbh) == LastmodInfo( "http://bar", None, None)
def test_read_from_dbhash_works(self): dbh = DictDbHash({ 'etag:http://boop': 'blah', 'last_modified:http://boop': 'flarg' }) assert LastmodInfo.read_from_dbhash('http://boop', dbh) == LastmodInfo( url="http://boop", etag="blah", last_modified="flarg") assert LastmodInfo.read_from_dbhash('http://bar', dbh) == LastmodInfo( "http://bar", None, None)
def test_write_to_dbhash_works(self): dbh = DictDbHash() LastmodInfo("http://boop", "blah", "flarg").write_to_dbhash(dbh) assert dbh.d == { "etag:http://boop": "blah", "last_modified:http://boop": "flarg", } LastmodInfo("http://boop").write_to_dbhash(dbh) assert dbh.d == {}
def test_write_to_dbhash_works(self): dbh = DictDbHash() LastmodInfo('http://boop', 'blah', 'flarg').write_to_dbhash(dbh) assert dbh.d == { 'etag:http://boop': 'blah', 'last_modified:http://boop': 'flarg' } LastmodInfo('http://boop').write_to_dbhash(dbh) assert dbh.d == {}
def reset_lastmod(db_url: str, dataset_names: List[str]): with psycopg2.connect(db_url) as conn: dbhash = load_dataset.get_dbhash(conn) for dataset in dataset_names: print(f"For the dataset {dataset}:") urls = load_dataset.get_urls_for_dataset(dataset) for url in urls: info = LastmodInfo(url) print( f"Clearing last modification metadata for {dataset}'s URL {url}." ) info.write_to_dbhash(dbhash)
def test_list_lastmod_works(db, capsys): def list_lastmod(): dbtool.main(['lastmod:list', 'hpd_registrations'], DATABASE_URL) out, err = capsys.readouterr() return out assert "has no metadata about its last modification" in list_lastmod() url = HPD_REG_URL with load_dbhash() as dbhash: info = LastmodInfo(url, etag='blah', last_modified='Tue, 01 Jan 2019 20:56:28 UTC') info.write_to_dbhash(dbhash) assert "was last modified on Tue, 01 Jan 2019 20:56:28 UTC" in list_lastmod( )
def list_lastmod(db_url: str, dataset_names: List[str]): with psycopg2.connect(db_url) as conn: dbhash = load_dataset.get_dbhash(conn) for dataset in dataset_names: print(f"For the dataset {dataset}:") urls = load_dataset.get_urls_for_dataset(dataset) for url in urls: info = LastmodInfo.read_from_dbhash(url, dbhash) if info.last_modified: print( f" The URL {url} was last modified on {info.last_modified}." ) else: print( f" The URL {url} has no metadata about its last modification date." )
def test_reset_lastmod_works(db, capsys): url = HPD_REG_URL with load_dbhash() as dbhash: info = LastmodInfo(url, etag='blah', last_modified='Tue, 01 Jan 2019 20:56:28 UTC') info.write_to_dbhash(dbhash) dbtool.main(['lastmod:reset', 'hpd_registrations'], DATABASE_URL) with load_dbhash() as dbhash: info = LastmodInfo.read_from_dbhash(url, dbhash) assert info == LastmodInfo(url=url, etag=None, last_modified=None)
def test_to_request_headers_works(self): assert LastmodInfo("http://boop", "blah", "flarg").to_request_headers() == { "If-None-Match": "blah", "If-Modified-Since": "flarg", }
def test_from_response_headers_works(self): assert LastmodInfo.from_response_headers("http://boop", { "ETag": "blah", "Last-Modified": "flarg" }) == LastmodInfo("http://boop", "blah", "flarg")
def test_to_request_headers_works(self): assert LastmodInfo('http://boop', 'blah', 'flarg').to_request_headers() == { 'If-None-Match': 'blah', 'If-Modified-Since': 'flarg' }
def test_from_response_headers_works(self): assert LastmodInfo.from_response_headers('http://boop', { 'ETag': 'blah', 'Last-Modified': 'flarg' }) == LastmodInfo('http://boop', 'blah', 'flarg')