Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_swhid_resolve.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 pytest | import pytest | ||||
from . import utils | from . import utils | ||||
from ..data import get_directories, get_releases, get_revisions, get_snapshots | from ..data import ( | ||||
get_contents, | |||||
get_directories, | |||||
get_releases, | |||||
get_revisions, | |||||
get_snapshots, | |||||
) | |||||
def test_invalid_swhid(client): | def test_invalid_swhid(client): | ||||
query_str = """ | query_str = """ | ||||
{ | { | ||||
resolveSwhid(swhid: "swh:1:dir:dae0d245988b472abd30a4f968b919d0019b6c7") { | resolveSwhid(swhid: "swh:1:dir:dae0d245988b472abd30a4f968b919d0019b6c7") { | ||||
nodes { | nodes { | ||||
type | type | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | assert data == { | ||||
"__typename": "Directory", | "__typename": "Directory", | ||||
"swhid": str(directory.swhid()), | "swhid": str(directory.swhid()), | ||||
}, | }, | ||||
"type": "directory", | "type": "directory", | ||||
} | } | ||||
] | ] | ||||
} | } | ||||
} | } | ||||
@pytest.mark.parametrize("content", get_contents()) | |||||
def test_content_swhid_resolve(client, content): | |||||
query_str = """ | |||||
{ | |||||
resolveSwhid(swhid: "%s") { | |||||
nodes { | |||||
type | |||||
target { | |||||
__typename | |||||
... on Content { | |||||
swhid | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
""" | |||||
data, _ = utils.get_query_response(client, query_str % content.swhid()) | |||||
assert data == { | |||||
"resolveSwhid": { | |||||
"nodes": [ | |||||
{ | |||||
"target": { | |||||
"__typename": "Content", | |||||
"swhid": str(content.swhid()), | |||||
}, | |||||
"type": "content", | |||||
} | |||||
] | |||||
} | |||||
} |