diff --git a/swh/graphql/tests/data.py b/swh/graphql/tests/data.py index cb85b14..8c4db7c 100644 --- a/swh/graphql/tests/data.py +++ b/swh/graphql/tests/data.py @@ -1,20 +1,24 @@ # 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 # This module will be removed once the test data # generation in SWH-wb moved to a shared location # or to a new test data project from swh.model.tests import swh_model_data def populate_dummy_data(storage): for object_type, objects in swh_model_data.TEST_OBJECTS.items(): method = getattr(storage, object_type + "_add") method(objects) def get_origins(): return swh_model_data.ORIGINS + + +def get_snapshots(): + return swh_model_data.SNAPSHOTS diff --git a/swh/graphql/tests/functional/test_snapshot_node.py b/swh/graphql/tests/functional/test_snapshot_node.py new file mode 100644 index 0000000..115a074 --- /dev/null +++ b/swh/graphql/tests/functional/test_snapshot_node.py @@ -0,0 +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()}") {{ + id + swhid + branches(first:5) {{ + nodes {{ + type + name {{ + text + }} + }} + }} + }} + }} + """ + data, _ = get_query_response(client, query_str) + 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"]