diff --git a/swh/graphql/resolvers/visit_status.py b/swh/graphql/resolvers/visit_status.py --- a/swh/graphql/resolvers/visit_status.py +++ b/swh/graphql/resolvers/visit_status.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information from swh.graphql.errors import NullableObjectError +from swh.graphql.utils import utils from swh.model.swhids import CoreSWHID, ObjectType from swh.storage.interface import PagedResult @@ -62,3 +63,7 @@ after=self._get_after_arg(), first=self._get_first_arg(), ) + + def _get_index_cursor(self, index: int, node: BaseVisitStatusNode): + # Visit status is using a different cursor, hence the override + return utils.get_encoded_cursor(utils.get_formatted_date(node.date)) diff --git a/swh/graphql/tests/data.py b/swh/graphql/tests/data.py --- a/swh/graphql/tests/data.py +++ b/swh/graphql/tests/data.py @@ -3,16 +3,21 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import datetime + from swh.model.model import ( Directory, DirectoryEntry, ObjectType, + OriginVisitStatus, Release, Revision, RevisionType, ) from swh.model.tests import swh_model_data +UTC = datetime.timezone.utc + def populate_search_data(search): search.origin_update({"url": origin.url} for origin in get_origins()) @@ -122,10 +127,25 @@ ] +def get_visit_with_multiple_status(): + return [ + OriginVisitStatus( + origin=get_origins()[0].url, + date=datetime.datetime(2014, 5, 7, 4, 20, 39, 432222, tzinfo=UTC), + visit=1, + type="git", + status="ongoing", + snapshot=None, + metadata=None, + ) + ] + + GRAPHQL_EXTRA_TEST_OBJECTS = { "release": get_releases_with_target(), "revision": get_revisions_with_parents(), "directory": get_directories_with_nested_path(), + "origin_visit_status": get_visit_with_multiple_status(), } diff --git a/swh/graphql/tests/functional/test_visit_node.py b/swh/graphql/tests/functional/test_visit_node.py --- a/swh/graphql/tests/functional/test_visit_node.py +++ b/swh/graphql/tests/functional/test_visit_node.py @@ -117,7 +117,7 @@ "visit": { "date": "2013-05-07T04:20:39.369271+00:00", "latestStatus": { - "date": "2013-05-07T04:20:39.432222+00:00", + "date": "2014-05-07T04:20:39.432222+00:00", "status": "ongoing", }, "type": "git", diff --git a/swh/graphql/tests/functional/test_visit_status.py b/swh/graphql/tests/functional/test_visit_status.py --- a/swh/graphql/tests/functional/test_visit_status.py +++ b/swh/graphql/tests/functional/test_visit_status.py @@ -5,7 +5,7 @@ import pytest -from ..data import get_visit_status, get_visits +from ..data import get_origins, get_visit_status, get_visits from .utils import get_query_response @@ -41,3 +41,63 @@ "status": visit_status.status, "type": visit_status.type, } + + +def test_visit_status_pagination(client): + # visit status is using a different cursor, hence separate test + query_str = """ + { + visit(originUrl: "%s", visitId: %s) { + statuses(first: 1) { + pageInfo { + hasNextPage + endCursor + } + edges { + cursor + node { + status + } + } + } + } + } + """ % ( + get_origins()[0].url, + 1, + ) + data, _ = get_query_response(client, query_str) + # request again with the endcursor + end_cursor = data["visit"]["statuses"]["pageInfo"]["endCursor"] + query_str = """ + { + visit(originUrl: "%s", visitId: %s) { + statuses(first: 1, after: "%s") { + pageInfo { + hasNextPage + endCursor + } + edges { + cursor + node { + status + } + } + } + } + } + """ % ( + get_origins()[0].url, + 1, + end_cursor, + ) + data, _ = get_query_response(client, query_str) + assert data["visit"]["statuses"] == { + "edges": [ + { + "cursor": "MjAxNC0wNS0wN1QwNDoyMDozOS40MzIyMjIrMDA6MDA=", + "node": {"status": "ongoing"}, + } + ], + "pageInfo": {"endCursor": None, "hasNextPage": False}, + }