Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_origin_save.py
Show First 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | def test_origin_exists_200_with_data(requests_mock): | ||||
assert actual_result == OriginExistenceCheckInfo( | assert actual_result == OriginExistenceCheckInfo( | ||||
origin_url=url, | origin_url=url, | ||||
exists=True, | exists=True, | ||||
content_length=10, | content_length=10, | ||||
last_modified="2011-08-21T16:26:32", | last_modified="2011-08-21T16:26:32", | ||||
) | ) | ||||
def test_origin_exists_internet_archive(requests_mock): | |||||
"""Edge case where an artifact URL to check existence is hosted on the | |||||
Internet Archive""" | |||||
url = ( | |||||
"https://web.archive.org/web/20100705043309/" | |||||
"http://www.cs.unm.edu/~mccune/old-ftp/eqp-09e.tar.gz" | |||||
) | |||||
redirect_url = ( | |||||
"https://web.archive.org/web/20100610004108/" | |||||
"http://www.cs.unm.edu/~mccune/old-ftp/eqp-09e.tar.gz" | |||||
) | |||||
requests_mock.head( | |||||
url, status_code=302, headers={"Location": redirect_url,}, | |||||
) | |||||
requests_mock.head( | |||||
redirect_url, | |||||
status_code=200, | |||||
headers={ | |||||
"X-Archive-Orig-Last-Modified": "Tue, 12 May 2009 22:09:43 GMT", | |||||
"X-Archive-Orig-Content-Length": "121421", | |||||
}, | |||||
) | |||||
actual_result = origin_exists(url) | |||||
assert actual_result == OriginExistenceCheckInfo( | |||||
origin_url=url, | |||||
exists=True, | |||||
content_length=121421, | |||||
last_modified="2009-05-12T22:09:43", | |||||
) | |||||
def test_origin_exists_200_with_data_unexpected_date_format(requests_mock): | def test_origin_exists_200_with_data_unexpected_date_format(requests_mock): | ||||
"""Existing origin should be ok, unexpected last modif time result in no time""" | """Existing origin should be ok, unexpected last modif time result in no time""" | ||||
url = "http://example.org/real-url2" | url = "http://example.org/real-url2" | ||||
# this is parsable but not as expected | # this is parsable but not as expected | ||||
unexpected_format_date = "Sun, 21 Aug 2021 16:26:32" | unexpected_format_date = "Sun, 21 Aug 2021 16:26:32" | ||||
requests_mock.head( | requests_mock.head( | ||||
url, status_code=200, headers={"last-modified": unexpected_format_date,}, | url, status_code=200, headers={"last-modified": unexpected_format_date,}, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |