def test_timestamped_uri_to_version_should_fail_for_non_playbackable_mementos(): with WaybackClient() as client: with pytest.raises(MementoPlaybackError): client.timestamped_uri_to_version( datetime(2017, 9, 29, 0, 27, 12), 'http://web.archive.org/web/20170929002712id_/https://www.fws.gov/birds/', url='https://www.fws.gov/birds/')
def test_timestamped_uri_to_version(): with WaybackClient() as client: version = client.timestamped_uri_to_version( datetime(2017, 11, 24, 15, 13, 15), 'http://web.archive.org/web/20171124151315id_/https://www.fws.gov/birds/', url='https://www.fws.gov/birds/') assert isinstance(version, dict) assert version['page_url'] == 'https://www.fws.gov/birds/'
def test_list_versions_cannot_iterate_after_session_closing(): with pytest.raises(SessionClosedError): with WaybackClient() as client: versions = client.list_versions('nasa.gov', from_date=datetime(1996, 10, 1), to_date=datetime(1997, 2, 1)) next(versions)
def test_timestamped_uri_to_version_works_with_redirects(): with WaybackClient() as client: version = client.timestamped_uri_to_version( datetime(2018, 8, 8, 9, 41, 44), 'http://web.archive.org/web/20180808094144id_/https://www.epa.gov/ghgreporting/san5779-factsheet', url='https://www.epa.gov/ghgreporting/san5779-factsheet') assert isinstance(version, dict) assert version['page_url'] == 'https://www.epa.gov/ghgreporting/san5779-factsheet' assert len(version['source_metadata']['redirects']) == 3
def test_list_versions_multipage(): # Set page size limits low enough to guarantee multiple pages with WaybackClient() as client: versions = client.list_versions('cnn.com', from_date=datetime(2001, 4, 10), to_date=datetime(2001, 5, 10), cdx_params={'limit': 25}) # Exhaust the generator and make sure no entries trigger errors. list(versions)
def test_list_versions(): with WaybackClient() as client: versions = client.list_versions('nasa.gov', from_date=datetime(1996, 10, 1), to_date=datetime(1997, 2, 1)) version = next(versions) assert version.date == datetime(1996, 12, 31, 23, 58, 47) # Exhaust the generator and make sure no entries trigger errors. list(versions)