@@ -148,7 +148,7 @@ def test_convert_one_column_no_rows():
148148@pytest .mark .skipif (
149149 graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
150150)
151- def test_convert_one_column_one_row ():
151+ def test_convert_one_column_one_row_one_column ():
152152 result = convert_graph_data (
153153 {
154154 "result" : {
@@ -217,6 +217,82 @@ def test_convert_nongraph_json():
217217 assert result ["response" ]["schema" ] is None
218218
219219
220+ @pytest .mark .skipif (
221+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
222+ )
223+ def test_convert_outer_key_not_string ():
224+ result = convert_graph_data (
225+ {
226+ 0 : {
227+ '0' : json .dumps ({"foo" : 1 , "bar" : 2 }),
228+ }
229+ })
230+ assert result == {"error" : "Expected outer key to be str, got <class 'int'>" }
231+
232+
233+ @pytest .mark .skipif (
234+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
235+ )
236+ def test_convert_outer_value_not_dict ():
237+ result = convert_graph_data (
238+ {
239+ 'result' : 0
240+ })
241+ assert result == {"error" : "Expected outer value to be dict, got <class 'int'>" }
242+
243+
244+ @pytest .mark .skipif (
245+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
246+ )
247+ def test_convert_inner_key_not_string ():
248+ result = convert_graph_data (
249+ {
250+ 'result' : {
251+ 0 : json .dumps ({"foo" : 1 , "bar" : 2 }),
252+ }
253+ })
254+ assert result == {"error" : "Expected inner key to be str, got <class 'int'>" }
255+
256+
257+ @pytest .mark .skipif (
258+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
259+ )
260+ def test_convert_inner_value_not_string ():
261+ result = convert_graph_data (
262+ {
263+ 'result' : {
264+ '0' : 1 ,
265+ }
266+ })
267+ assert result == {"error" : "Expected inner value to be str, got <class 'int'>" }
268+
269+
270+ @pytest .mark .skipif (
271+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
272+ )
273+ def test_convert_one_column_one_row_two_columns ():
274+ result = convert_graph_data (
275+ {
276+ "result1" : {
277+ "0" : json .dumps (row_alex_owns_account ),
278+ },
279+ "result2" : {
280+ "0" : json .dumps (row_alex_owns_account ),
281+ }
282+
283+ }
284+ )
285+ assert result == {"error" : "Query has multiple columns - graph visualization not supported" }
286+
287+
288+ @pytest .mark .skipif (
289+ graph_visualization is None , reason = "Requires `spanner-graph-notebook`"
290+ )
291+ def test_convert_empty_dict ():
292+ result = convert_graph_data ({})
293+ assert result == {"error" : "query result with no columns is not supported for graph visualization" }
294+
295+
220296class TestGraphServer (unittest .TestCase ):
221297 def setUp (self ):
222298 self .server_thread = GraphServer .init ()
0 commit comments