From 3be6ac01fc09089dc6d4a7309211dad0f63760e3 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Sun, 30 Jan 2022 20:03:40 +0530 Subject: [PATCH] created tests/test_cdx_api.py: added tests for cdx_api.py --- tests/test_cdx_api.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_cdx_api.py diff --git a/tests/test_cdx_api.py b/tests/test_cdx_api.py new file mode 100644 index 0000000..d574954 --- /dev/null +++ b/tests/test_cdx_api.py @@ -0,0 +1,36 @@ +from waybackpy.cdx_api import WaybackMachineCDXServerAPI + + +def test_a(): + user_agent = "Mozilla/5.0 (MacBook Air; M1 Mac OS X 11_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/604.1" + url = "https://twitter.com/jack" + + wayback = WaybackMachineCDXServerAPI( + url=url, + user_agent=user_agent, + match_type="prefix", + collapses=["urlkey"], + start_timestamp="201001", + end_timestamp="201002", + ) + # timeframe bound prefix matching enabled along with active urlkey based collapsing + + snapshots = wayback.snapshots() # + + for snapshot in snapshots: + assert snapshot.timestamp.startswith("2010") + + +def test_b(): + user_agent = "Mozilla/5.0 (MacBook Air; M1 Mac OS X 11_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/604.1" + url = "https://www.google.com" + + wayback = WaybackMachineCDXServerAPI( + url=url, user_agent=user_agent, start_timestamp="202101", end_timestamp="202112" + ) + # timeframe bound prefix matching enabled along with active urlkey based collapsing + + snapshots = wayback.snapshots() # + + for snapshot in snapshots: + assert snapshot.timestamp.startswith("2021")