Skip to content
Snippets Groups Projects
Commit 2c3b16f7 authored by Jayesh's avatar Jayesh :cat2:
Browse files

Return none for missing snapshot in a visit status

Snapshot can be null for a visit status.
Return none instead of a snapshot object in that case.

Resolves T4514
parent 6e5d34e9
No related branches found
Tags v0.0.69
1 merge request!54Return none for missing snapshot in a visit status
......@@ -16,6 +16,8 @@ High level resolvers
# Every scalar is expected to resolve this way
# - As an attribute/item in the object/dict returned by a backend (eg: Origin.url)
from typing import Optional
from ariadne import ObjectType, UnionType
from graphql.type import GraphQLResolveInfo
......@@ -91,8 +93,10 @@ def snapshot_resolver(
@visit_status.field("snapshot")
def visit_snapshot_resolver(
obj, info: GraphQLResolveInfo, **kw
) -> rs.snapshot.VisitSnapshotNode:
obj: rs.visit_status.BaseVisitStatusNode, info: GraphQLResolveInfo, **kw
) -> Optional[rs.snapshot.VisitSnapshotNode]:
if obj.snapshotSWHID is None:
return None
resolver = get_node_resolver("visit-snapshot")
return resolver(obj, info, **kw)
......
......@@ -57,7 +57,6 @@ class VisitSnapshotNode(BaseSnapshotNode):
obj: BaseVisitStatusNode
def _get_node_data(self):
# self.obj.snapshotSWHID is the requested snapshot SWHID
snapshot_id = self.obj.snapshotSWHID.object_id
return self._get_snapshot_by_id(snapshot_id)
......
......@@ -18,6 +18,8 @@ class BaseVisitStatusNode(BaseNode):
@property
def snapshotSWHID(self): # To support the schema naming convention
if self._node.snapshot is None:
return None
return CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=self._node.snapshot)
......
......@@ -22,6 +22,14 @@ def get_origins():
return swh_model_data.ORIGINS
def get_visits():
return swh_model_data.ORIGIN_VISITS
def get_visit_status():
return swh_model_data.ORIGIN_VISIT_STATUSES
def get_snapshots():
return swh_model_data.SNAPSHOTS
......
# 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_visit_status, get_visits
from .utils import get_query_response
@pytest.mark.parametrize(
"visit, visit_status", list(zip(get_visits(), get_visit_status()))
)
def test_get_visit_status(client, visit, visit_status):
query_str = """
{
visit(originUrl: "%s", visitId: %s) {
status(first: 3) {
nodes {
status
date
type
snapshot {
swhid
}
}
}
}
}
""" % (
visit.origin,
visit.visit,
)
data, _ = get_query_response(client, query_str)
assert data["visit"]["status"]["nodes"][0] == {
"date": visit_status.date.isoformat(),
"snapshot": {"swhid": f"swh:1:snp:{visit_status.snapshot.hex()}"}
if visit_status.snapshot is not None
else None,
"status": visit_status.status,
"type": visit_status.type,
}
......@@ -27,7 +27,6 @@ class TestResolvers:
resolvers.visit_status.LatestVisitStatusNode,
),
(rs.snapshot_resolver, resolvers.snapshot.SnapshotNode),
(rs.visit_snapshot_resolver, resolvers.snapshot.VisitSnapshotNode),
(rs.revision_resolver, resolvers.revision.RevisionNode),
(rs.revision_directory_resolver, resolvers.directory.RevisionDirectoryNode),
(rs.release_resolver, resolvers.release.ReleaseNode),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment