diff --git a/swh/graphql/tests/functional/test_snapshot_node.py b/swh/graphql/tests/functional/test_snapshot_node.py index 115a074..2950486 100644 --- a/swh/graphql/tests/functional/test_snapshot_node.py +++ b/swh/graphql/tests/functional/test_snapshot_node.py @@ -1,57 +1,57 @@ # Copyright (C) 2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import pytest from ..data import get_snapshots from .utils import assert_missing_object, get_error_response, get_query_response @pytest.mark.parametrize("snapshot", get_snapshots()) def test_get_snapshot(client, snapshot): - query_str = f""" - {{ - snapshot(swhid: "{snapshot.swhid()}") {{ + query_str = """ + { + snapshot(swhid: "%s") { id swhid - branches(first:5) {{ - nodes {{ + branches(first:5) { + nodes { type - name {{ + name { 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"]["id"] == snapshot.id.hex() assert len(data["snapshot"]["branches"]["nodes"]) == len(snapshot.branches) def test_get_snapshot_missing_swhid(client): query_str = """ { snapshot(swhid: "swh:1:snp:0949d7a8c96347dba09be8d79085b8207f345412") { swhid } } """ assert_missing_object(client, query_str, "snapshot") def test_get_snapshot_invalid_swhid(client): query_str = """ { snapshot(swhid: "swh:1:snp:invalid") { swhid } } """ errors = get_error_response(client, query_str) assert len(errors) == 1 assert "Invalid SWHID: invalid syntax" in errors[0]["message"] diff --git a/swh/graphql/tests/functional/test_visit_node.py b/swh/graphql/tests/functional/test_visit_node.py index 6bd8e4d..0b1fece 100644 --- a/swh/graphql/tests/functional/test_visit_node.py +++ b/swh/graphql/tests/functional/test_visit_node.py @@ -1,68 +1,66 @@ # Copyright (C) 2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import pytest from ..data import get_origins from .utils import assert_missing_object, get_query_response @pytest.mark.parametrize("origin", get_origins()) def test_get_visit(client, storage, origin): query_str = """ - {{ - visit(originUrl: "{origin_url}", visitId: {visit_id}) {{ + { + visit(originUrl: "%s", visitId: %s) { visitId date type - latestStatus {{ + latestStatus { status date type - snapshot {{ + snapshot { swhid - }} - }} - status {{ - nodes {{ + } + } + status { + nodes { status - }} - }} - }} - }} + } + } + } + } """ visits_and_statuses = storage.origin_visit_get_with_statuses(origin.url).results for vws in visits_and_statuses: visit = vws.visit statuses = vws.statuses - data, _ = get_query_response( - client, query_str.format(origin_url=origin.url, visit_id=visit.visit) - ) + data, _ = get_query_response(client, query_str % (origin.url, visit.visit)) assert data["visit"] == { "visitId": visit.visit, "type": visit.type, "date": visit.date.isoformat(), "latestStatus": { "date": statuses[-1].date.isoformat(), "type": statuses[-1].type, "status": statuses[-1].status, "snapshot": ({"swhid": f"swh:1:snp:{statuses[-1].snapshot.hex()}"}) if statuses[-1].snapshot else None, }, "status": {"nodes": [{"status": status.status} for status in statuses]}, } def test_invalid_get_visit(client): query_str = """ { visit(originUrl: "http://example.com/forge1", visitId: 3) { type } } """ assert_missing_object(client, query_str, "visit")