Skip to content

Commit 3b4903f

Browse files
committed
Add test for invalid node expansion request
1 parent 2d899b4 commit 3b4903f

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

bigquery_magics/graph_server.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,16 @@ def handle_post_node_expansion(self):
220220
- params: A JSON string containing connection parameters (project, instance, database, graph)
221221
- request: A dictionary with node details (uid, node_labels, node_properties, direction, edge_label)
222222
"""
223-
try:
224-
data = self.parse_post_data()
225-
226-
# Execute node expansion with:
227-
# - params_str: JSON string with connection parameters (project, instance, database, graph)
228-
# - request: Dict with node details (uid, node_labels, node_properties, direction, edge_label)
229-
self.do_data_response(
230-
execute_node_expansion(
231-
params=data.get("params"), request=data.get("request")
232-
)
223+
data = self.parse_post_data()
224+
225+
# Execute node expansion with:
226+
# - params_str: JSON string with connection parameters (project, instance, database, graph)
227+
# - request: Dict with node details (uid, node_labels, node_properties, direction, edge_label)
228+
self.do_data_response(
229+
execute_node_expansion(
230+
params=data.get("params"), request=data.get("request")
233231
)
234-
except BaseException as e:
235-
self.do_error_response(e)
236-
return
232+
)
237233

238234
def do_GET(self):
239235
assert self.path == GraphServer.endpoints["get_ping"]

tests/unit/test_graph_server.py

+16
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,21 @@ def test_post_node_expansion(self):
441441
)
442442

443443

444+
@pytest.mark.skipif(
445+
graph_visualization is None, reason="Requires `spanner-graph-notebook`"
446+
)
447+
def test_post_node_expansion_invalid_request(self):
448+
self.assertTrue(self.server_thread.is_alive())
449+
route = graph_server.graph_server.build_route(
450+
graph_server.GraphServer.endpoints["post_node_expansion"]
451+
)
452+
request = {}
453+
response = requests.post(route, json={"params": json.dumps(request)})
454+
self.assertEqual(response.status_code, 200)
455+
self.assertEqual(
456+
response.json(), {"error": "Node expansion not yet implemented"}
457+
)
458+
459+
444460
def test_stop_server_never_started():
445461
graph_server.graph_server.stop_server()

0 commit comments

Comments
 (0)