Skip to content

Commit 858e72b

Browse files
committed
Add unit test coverage for the GraphServer object.
1 parent bf82c60 commit 858e72b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

bigquery_magics/graph_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def init():
162162
def stop_server():
163163
if GraphServer._server:
164164
GraphServer._server.shutdown()
165-
print("Spanner Graph Notebook shutting down...")
165+
print("BigQuery-magics graph server shutting down...")
166166

167167
@staticmethod
168168
def get_ping():

tests/unit/test_graph_server.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
# limitations under the License.
1414

1515
import json
16-
1716
import pytest
17+
import unittest
1818

1919
try:
2020
import spanner_graphs.graph_visualization as graph_visualization
2121
except ImportError:
2222
graph_visualization = None
2323

24-
from bigquery_magics.graph_server import convert_graph_data
24+
from bigquery_magics.graph_server import convert_graph_data, GraphServer
2525

2626
alex_properties = {
2727
"birthday": "1991-12-21T08:00:00Z",
@@ -214,3 +214,22 @@ def test_convert_nongraph_json():
214214
assert result["response"]["query_result"] == {"result": [{"foo": 1, "bar": 2}]}
215215
assert result["response"]["rows"] == [[{"foo": 1, "bar": 2}]]
216216
assert result["response"]["schema"] is None
217+
218+
219+
class TestGraphServer(unittest.TestCase):
220+
def setUp(self):
221+
self.server_thread = GraphServer.init()
222+
223+
def tearDown(self):
224+
GraphServer.stop_server() # Stop the server after each test
225+
self.server_thread.join() # Wait for the thread to finish
226+
227+
def test_ping(self):
228+
self.assertTrue(self.server_thread.is_alive())
229+
230+
response = GraphServer.get_ping()
231+
self.assertEqual(response, {"message": "pong"})
232+
233+
request = {"data": "ping"}
234+
response = GraphServer.post_ping(request)
235+
self.assertEqual(response, {"your_request": request})

0 commit comments

Comments
 (0)