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-2021 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 | ||||
import pytest | |||||
from swh.model.identifiers import REVISION, CoreSWHID | from swh.model.identifiers import REVISION, CoreSWHID | ||||
from swh.web.client.client import typify_json | 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): | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | expected = [ | ||||
"https://archive.softwareheritage.org/api/1/origin/https://bitbucket.org/foobarbazqux/rp.git/visits/", # NoQA: E501 | "https://archive.softwareheritage.org/api/1/origin/https://bitbucket.org/foobarbazqux/rp.git/visits/", # NoQA: E501 | ||||
), | ), | ||||
] | ] | ||||
for (url, visit) in expected: | for (url, visit) in expected: | ||||
assert url in actual_urls | assert url in actual_urls | ||||
assert visit in actual_visits | assert visit in actual_visits | ||||
@pytest.mark.parametrize( | |||||
"visit_type,origin", | |||||
[ | |||||
("git", "https://gitlab.org/gazelle/itest"), | |||||
("git", "https://git.renater.fr/anonscm/git/6po/6po.git"), | |||||
("git", "https://github.com/colobot/colobot"), | |||||
], | |||||
) | |||||
def test_origin_save(visit_type, origin, web_api_client, web_api_mock): | |||||
"""Post save code now is allowed from the client.""" | |||||
save_request = web_api_client.origin_save(visit_type, origin) | |||||
assert save_request is not None | |||||
assert save_request["save_request_status"] == "accepted" | |||||
assert save_request["visit_date"] is None | |||||
def test_known(web_api_client, web_api_mock): | def test_known(web_api_client, web_api_mock): | ||||
# full list of SWHIDs for which we mock a {known: True} answer | # full list of SWHIDs for which we mock a {known: True} answer | ||||
known_swhids = [ | known_swhids = [ | ||||
"swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1", | "swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1", | ||||
"swh:1:dir:977fc4b98c0e85816348cebd3b12026407c368b6", | "swh:1:dir:977fc4b98c0e85816348cebd3b12026407c368b6", | ||||
"swh:1:rev:aafb16d69fd30ff58afdd69036a26047f3aebdc6", | "swh:1:rev:aafb16d69fd30ff58afdd69036a26047f3aebdc6", | ||||
"swh:1:rel:208f61cc7a5dbc9879ae6e5c2f95891e270f09ef", | "swh:1:rel:208f61cc7a5dbc9879ae6e5c2f95891e270f09ef", | ||||
"swh:1:snp:6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a", | "swh:1:snp:6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a", | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |