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 | ||||
from copy import copy | from copy import copy | ||||
from datetime import datetime | from datetime import datetime | ||||
from dateutil.parser import parse as parse_date | from dateutil.parser import parse as parse_date | ||||
from unittest.mock import call, Mock | from unittest.mock import call, Mock | ||||
import pytest | import pytest | ||||
from swh.model.identifiers import REVISION | |||||
from swh.web.client import typify | |||||
from swh.web.client.auth import AuthenticationError | from swh.web.client.auth import AuthenticationError | ||||
from swh.model.identifiers import parse_persistent_identifier as parse_pid | from swh.model.identifiers import parse_persistent_identifier as parse_pid | ||||
from .test_cli import oidc_profile | from .test_cli import oidc_profile | ||||
def test_get_content(web_api_client, web_api_mock): | def test_get_content(web_api_client, web_api_mock): | ||||
pid = parse_pid("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1") | pid = parse_pid("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1") | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def test_get_visits(web_api_client, web_api_mock): | ||||
assert len(visits) == 20 | assert len(visits) == 20 | ||||
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_pid = 'swh:1:snp:456550ea74af4e2eecaa406629efaaf0b9b5f976' | snapshot_pid = 'swh:1:snp:456550ea74af4e2eecaa406629efaaf0b9b5f976' | ||||
assert visits[7]["snapshot"] == parse_pid(snapshot_pid) | assert visits[7]["snapshot"] == parse_pid(snapshot_pid) | ||||
def test_typify_minimal_revision(): | |||||
revision_data = { | |||||
'id': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | |||||
'directory': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | |||||
'date': None, | |||||
'committer_date': None, | |||||
'parents': [] | |||||
} | |||||
revision_typed = typify(revision_data, REVISION) | |||||
pid = "swh:1:rev:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |||||
assert revision_typed['id'] == parse_pid(pid) | |||||
assert revision_typed['date'] is None |