Skip to content

Commit 8f3100f

Browse files
committed
Add more tests.
1 parent b112cff commit 8f3100f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

bigquery_magics/graph_server.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,10 @@ def get_ping():
174174
route = GraphServer.build_route(GraphServer.endpoints["get_ping"])
175175
response = requests.get(route)
176176

177-
if response.status_code == 200:
178-
return response.json()
179-
else:
180-
print(f"Request failed with status code {response.status_code}")
181-
return False
177+
assert (
178+
response.status_code == 200
179+
) # Guaranteed by GraphServerHandler implementation
180+
return response.json()
182181

183182
@staticmethod
184183
def post_ping(data):

tests/unit/test_graph_server.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,22 @@ def test_convert_empty_dict():
296296
}
297297

298298

299+
@pytest.mark.skipif(
300+
graph_visualization is None, reason="Requires `spanner-graph-notebook`"
301+
)
302+
def test_convert_wrong_row_index():
303+
result = convert_graph_data(
304+
{
305+
"result": {
306+
# Missing "0" key
307+
"1": json.dumps(row_alex_owns_account),
308+
}
309+
}
310+
)
311+
312+
assert result == {"error": "Unexpected row index; expected 0, got 1"}
313+
314+
299315
class TestGraphServer(unittest.TestCase):
300316
def setUp(self):
301317
self.server_thread = GraphServer.init()
@@ -313,3 +329,7 @@ def test_ping(self):
313329
request = {"data": "ping"}
314330
response = GraphServer.post_ping(request)
315331
self.assertEqual(response, {"your_request": request})
332+
333+
334+
def test_stop_server_never_started():
335+
GraphServer.stop_server()

0 commit comments

Comments
 (0)