diff --git a/swh/graph/client.py b/swh/graph/client.py --- a/swh/graph/client.py +++ b/swh/graph/client.py @@ -30,6 +30,35 @@ def get_lines(self, endpoint, **kwargs): yield from self.raw_verb_lines("get", endpoint, **kwargs) + # Web API endpoints without arguments (bad request) + + def leaves_BR(self): + return self.get("leaves") + + def neighbors_BR(self): + return self.get("neighbors") + + def visit_nodes_BR(self): + return self.get("visit/nodes") + + def visit_edges_BR(self): + return self.get("visit/edges") + + def visit_paths_BR(self): + return self.get("visit/paths") + + def random_walk_BR(self): + return self.get("randomwalk") + + def count_leaves_BR(self): + return self.get("leaves/count") + + def count_neighbors_BR(self): + return self.get("neighbors/count") + + def count_visit_nodes_BR(self): + return self.get("visit/nodes/count") + # Web API endpoints def stats(self): diff --git a/swh/graph/server/app.py b/swh/graph/server/app.py --- a/swh/graph/server/app.py +++ b/swh/graph/server/app.py @@ -47,6 +47,10 @@ ) +async def argsMissing(request): + return aiohttp.web.HTTPBadRequest(text="argument(s) missing") + + class GraphView(aiohttp.web.View): """Base class for views working on the graph, with utility functions""" @@ -297,16 +301,26 @@ aiohttp.web.get("/", index), aiohttp.web.get("/graph", index), aiohttp.web.view("/graph/stats", StatsView), + aiohttp.web.view("/graph/leaves", argsMissing), aiohttp.web.view("/graph/leaves/{src}", LeavesView), + aiohttp.web.view("/graph/neighbors", argsMissing), aiohttp.web.view("/graph/neighbors/{src}", NeighborsView), + aiohttp.web.view("/graph/visit/nodes", argsMissing), aiohttp.web.view("/graph/visit/nodes/{src}", VisitNodesView), + aiohttp.web.view("/graph/visit/edges", argsMissing), aiohttp.web.view("/graph/visit/edges/{src}", VisitEdgesView), + aiohttp.web.view("/graph/visit/paths", argsMissing), aiohttp.web.view("/graph/visit/paths/{src}", VisitPathsView), # temporarily disabled in wait of a proper fix for T1969 # aiohttp.web.view("/graph/walk/{src}/{dst}", WalkView) + aiohttp.web.view("/graph/randomwalk", argsMissing), + aiohttp.web.view("/graph/randomwalk/{src}", argsMissing), aiohttp.web.view("/graph/randomwalk/{src}/{dst}", RandomWalkView), + aiohttp.web.view("/graph/neighbors/count", argsMissing), aiohttp.web.view("/graph/neighbors/count/{src}", CountNeighborsView), + aiohttp.web.view("/graph/leaves/count", argsMissing), aiohttp.web.view("/graph/leaves/count/{src}", CountLeavesView), + aiohttp.web.view("/graph/visit/nodes/count", argsMissing), aiohttp.web.view("/graph/visit/nodes/count/{src}", CountVisitNodesView), ] ) diff --git a/swh/graph/tests/test_api_client.py b/swh/graph/tests/test_api_client.py --- a/swh/graph/tests/test_api_client.py +++ b/swh/graph/tests/test_api_client.py @@ -33,6 +33,21 @@ assert isinstance(stats["outdegree"]["avg"], float) +def test_missing_args_endpoints(graph_client): + # just a few examples, not exhaustive + with raises(RemoteException) as exc_info: + list(graph_client.leaves_BR()) + assert exc_info.value.response.status_code == 400 + + with raises(RemoteException) as exc_info: + list(graph_client.neighbors_BR()) + assert exc_info.value.response.status_code == 400 + + with raises(RemoteException) as exc_info: + list(graph_client.random_walk_BR()) + assert exc_info.value.response.status_code == 400 + + def test_leaves(graph_client): actual = list( graph_client.leaves("swh:1:ori:0000000000000000000000000000000000000021")