Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_snapshot_node.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 ..data import get_snapshots | from ..data import get_snapshots | ||||
from .utils import assert_missing_object, get_error_response, get_query_response | from .utils import assert_missing_object, get_error_response, get_query_response | ||||
@pytest.mark.parametrize("snapshot", get_snapshots()) | @pytest.mark.parametrize("snapshot", get_snapshots()) | ||||
def test_get_snapshot(client, snapshot): | def test_get_snapshot(client, snapshot): | ||||
query_str = f""" | query_str = """ | ||||
{{ | { | ||||
snapshot(swhid: "{snapshot.swhid()}") {{ | snapshot(swhid: "%s") { | ||||
id | id | ||||
swhid | swhid | ||||
branches(first:5) {{ | branches(first:5) { | ||||
nodes {{ | nodes { | ||||
type | type | ||||
name {{ | name { | ||||
text | text | ||||
}} | } | ||||
}} | } | ||||
}} | } | ||||
}} | } | ||||
}} | } | ||||
""" | """ | ||||
data, _ = get_query_response(client, query_str) | data, _ = get_query_response(client, query_str % snapshot.swhid()) | ||||
assert data["snapshot"]["swhid"] == str(snapshot.swhid()) | assert data["snapshot"]["swhid"] == str(snapshot.swhid()) | ||||
assert data["snapshot"]["id"] == snapshot.id.hex() | assert data["snapshot"]["id"] == snapshot.id.hex() | ||||
assert len(data["snapshot"]["branches"]["nodes"]) == len(snapshot.branches) | assert len(data["snapshot"]["branches"]["nodes"]) == len(snapshot.branches) | ||||
def test_get_snapshot_missing_swhid(client): | def test_get_snapshot_missing_swhid(client): | ||||
query_str = """ | query_str = """ | ||||
{ | { | ||||
Show All 19 Lines |