Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_search.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from . import utils | from . import utils | ||||
def test_search_origins(client): | def test_search_origins(client): | ||||
query_str = """ | query_str = """ | ||||
query doSearch($query: String!, $first: Int!) { | query doSearch($query: String!, $first: Int!) { | ||||
search(query: $query, first: $first) { | search(query: $query, first: $first) { | ||||
nodes { | nodes { | ||||
targetType | |||||
target { | target { | ||||
type | |||||
node { | |||||
...on Origin { | ...on Origin { | ||||
url | url | ||||
latestVisit { | latestVisit { | ||||
date | date | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
pageInfo { | pageInfo { | ||||
hasNextPage | hasNextPage | ||||
endCursor | endCursor | ||||
} | } | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
data, _ = utils.get_query_response(client, query_str, query="fox", first=1) | data, _ = utils.get_query_response(client, query_str, query="fox", first=1) | ||||
assert len(data["search"]["nodes"]) == 1 | assert len(data["search"]["nodes"]) == 1 | ||||
assert data == { | assert data == { | ||||
"search": { | "search": { | ||||
"nodes": [ | "nodes": [ | ||||
{ | { | ||||
"target": { | "target": { | ||||
"type": "origin", | |||||
"node": { | |||||
"url": "https://somewhere.org/den/fox", | "url": "https://somewhere.org/den/fox", | ||||
"latestVisit": {"date": "2018-11-27T17:20:39+00:00"}, | "latestVisit": {"date": "2018-11-27T17:20:39+00:00"}, | ||||
}, | }, | ||||
"targetType": "origin", | }, | ||||
} | } | ||||
], | ], | ||||
"pageInfo": {"endCursor": "MQ==", "hasNextPage": True}, | "pageInfo": {"endCursor": "MQ==", "hasNextPage": True}, | ||||
} | } | ||||
} | } | ||||
def test_search_missing_url(client): | def test_search_missing_url(client): | ||||
query_str = """ | query_str = """ | ||||
query doSearch($query: String!, $first: Int!) { | query doSearch($query: String!, $first: Int!) { | ||||
search(query: $query, first: $first) { | search(query: $query, first: $first) { | ||||
nodes { | nodes { | ||||
targetType | target { | ||||
type | |||||
} | |||||
} | } | ||||
pageInfo { | pageInfo { | ||||
hasNextPage | hasNextPage | ||||
endCursor | endCursor | ||||
} | } | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
data, _ = utils.get_query_response(client, query_str, query="missing-fox", first=1) | data, _ = utils.get_query_response(client, query_str, query="missing-fox", first=1) | ||||
assert len(data["search"]["nodes"]) == 0 | assert len(data["search"]["nodes"]) == 0 |