diff --git a/swh/graphql/tests/functional/test_visit_node.py b/swh/graphql/tests/functional/test_visit_node.py new file mode 100644 --- /dev/null +++ b/swh/graphql/tests/functional/test_visit_node.py @@ -0,0 +1,64 @@ +# 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 + +from datetime import datetime + +from .utils import get_query_response + + +def test_get_visit(client): + query_str = """ + { + visit(originUrl: "http://example.com/forge1", visitId: 1) { + id + date + type + latestStatus { + status + date + type + snapshot { + SWHID + } + } + status { + nodes { + status + } + } + } + } + """ + data, _ = get_query_response(client, query_str) + visit = data["visit"] + assert visit["type"] == "git" + assert datetime.fromisoformat(visit["date"]).year == datetime.now().year + assert visit["id"] == "aHR0cDovL2V4YW1wbGUuY29tL2ZvcmdlMS0x" + assert len(visit["status"]) == 1 + + assert visit["latestStatus"]["status"] == "full" + assert visit["latestStatus"]["type"] == "git" + assert ( + datetime.fromisoformat(visit["latestStatus"]["date"]).year + == datetime.now().year + ) + assert ( + visit["latestStatus"]["snapshot"]["SWHID"] + == "swh:1:snp:1a8893e6a86f444e8be8e7bda6cb34fb1735a00e" + ) + + +def test_invalid_get_visit(client): + query_str = """ + { + visit(originUrl: "http://example.com/forge1", visitId: 3) { + type + } + } + """ + data, errors = get_query_response(client, query_str) + assert data["visit"] is None + assert len(errors) == 1 + assert errors[0]["message"] == "Requested object is not available"