waybackpy/tests/test_snapshot.py

41 lines
1.3 KiB
Python
Raw Normal View History

2021-01-09 21:53:53 +01:00
import pytest
from waybackpy.snapshot import CdxSnapshot, datetime
def test_CdxSnapshot():
sample_input = "org,archive)/ 20080126045828 http://github.com text/html 200 Q4YULN754FHV2U6Q5JUT6Q2P57WEWNNY 1415"
2021-01-10 06:10:32 +01:00
prop_values = sample_input.split(" ")
properties = {}
2021-01-09 21:53:53 +01:00
(
2021-01-10 06:10:32 +01:00
properties["urlkey"],
properties["timestamp"],
properties["original"],
properties["mimetype"],
properties["statuscode"],
properties["digest"],
properties["length"],
) = prop_values
2021-01-09 21:53:53 +01:00
2021-01-10 06:10:32 +01:00
snapshot = CdxSnapshot(properties)
2021-01-09 21:53:53 +01:00
2021-01-10 06:10:32 +01:00
assert properties["urlkey"] == snapshot.urlkey
assert properties["timestamp"] == snapshot.timestamp
assert properties["original"] == snapshot.original
assert properties["mimetype"] == snapshot.mimetype
assert properties["statuscode"] == snapshot.statuscode
assert properties["digest"] == snapshot.digest
assert properties["length"] == snapshot.length
assert (
datetime.strptime(properties["timestamp"], "%Y%m%d%H%M%S")
== snapshot.datetime_timestamp
)
archive_url = (
"https://web.archive.org/web/"
+ properties["timestamp"]
+ "/"
+ properties["original"]
)
2021-01-09 21:53:53 +01:00
assert archive_url == snapshot.archive_url
assert sample_input == str(snapshot)