Changeset View
Changeset View
Standalone View
Standalone View
swh/web/client/tests/test_web_api_client.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import json | import json | ||||
from dateutil.parser import parse as parse_date | from dateutil.parser import parse as parse_date | ||||
from swh.model.identifiers import parse_swhid | from swh.model.identifiers import REVISION, parse_swhid | ||||
from swh.web.client.client import typify_json | |||||
from .api_data import API_DATA | from .api_data import API_DATA | ||||
def test_get_content(web_api_client, web_api_mock): | def test_get_content(web_api_client, web_api_mock): | ||||
swhid = parse_swhid("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1") | swhid = parse_swhid("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1") | ||||
obj = web_api_client.get(swhid) | obj = web_api_client.get(swhid) | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | for swhid in swhids: | ||||
if object_id in url: | if object_id in url: | ||||
expected = json.loads(data) | expected = json.loads(data) | ||||
# Special case: snapshots response differs slightly from the Web API | # Special case: snapshots response differs slightly from the Web API | ||||
if swhid.startswith("swh:1:snp:"): | if swhid.startswith("swh:1:snp:"): | ||||
expected = expected["branches"] | expected = expected["branches"] | ||||
break | break | ||||
assert actual == expected | assert actual == expected | ||||
def test_typify_json_minimal_revision(): | |||||
revision_data = { | |||||
"id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | |||||
"directory": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | |||||
"date": None, | |||||
"committer_date": None, | |||||
"parents": [], | |||||
} | |||||
revision_typed = typify_json(revision_data, REVISION) | |||||
pid = "swh:1:rev:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |||||
assert revision_typed["id"] == parse_swhid(pid) | |||||
assert revision_typed["date"] is None |