Changeset View
Changeset View
Standalone View
Standalone View
swh/web/client/tests/test_web_api_client.py
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | def test_get_visits(web_api_client, web_api_mock): | ||||
timestamp = parse_date("2018-07-31 04:34:23.298931+00:00") | timestamp = parse_date("2018-07-31 04:34:23.298931+00:00") | ||||
assert visits[0]["date"] == timestamp | assert visits[0]["date"] == timestamp | ||||
assert visits[0]["snapshot"] is None | assert visits[0]["snapshot"] is None | ||||
snapshot_swhid = "swh:1:snp:456550ea74af4e2eecaa406629efaaf0b9b5f976" | snapshot_swhid = "swh:1:snp:456550ea74af4e2eecaa406629efaaf0b9b5f976" | ||||
assert visits[7]["snapshot"] == CoreSWHID.from_string(snapshot_swhid) | assert visits[7]["snapshot"] == CoreSWHID.from_string(snapshot_swhid) | ||||
def test_get_last_visit(web_api_client, web_api_mock): | |||||
visit = web_api_client.last_visit("https://github.com/NixOS/nixpkgs") | |||||
assert visit is not None | |||||
timestamp = parse_date("2021-09-02 20:20:31.231786+00:00") | |||||
assert visit["date"] == timestamp | |||||
snapshot_swhid = "swh:1:snp:6e1fe7858066ff1a6905080ac6503a3a12b84f59" | |||||
assert visit["snapshot"] == CoreSWHID.from_string(snapshot_swhid) | |||||
def test_origin_search(web_api_client, web_api_mock): | def test_origin_search(web_api_client, web_api_mock): | ||||
limited_results = list(web_api_client.origin_search("python", limit=5)) | limited_results = list(web_api_client.origin_search("python", limit=5)) | ||||
assert len(limited_results) == 5 | assert len(limited_results) == 5 | ||||
results = list(web_api_client.origin_search("foo bar baz qux", with_visit=True)) | results = list(web_api_client.origin_search("foo bar baz qux", with_visit=True)) | ||||
actual_urls = [r["url"] for r in results] | actual_urls = [r["url"] for r in results] | ||||
actual_visits = [r["origin_visits_url"] for r in results] | actual_visits = [r["origin_visits_url"] for r in results] | ||||
# Check *some* of the URLS since the search could return more results in the future | # Check *some* of the URLS since the search could return more results in the future | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |