@@ -155,13 +155,37 @@ def test_09_csv_output_with_header(self):
155155
156156 @pystackql_test_setup ()
157157 def test_10_executeStmt (self ):
158+ okta_result_dict = self .stackql .executeStmt (registry_pull_okta_query )
159+ okta_result = okta_result_dict [0 ]["message" ]
160+ expected_pattern = registry_pull_resp_pattern ("okta" )
161+ self .assertTrue (re .search (expected_pattern , okta_result ), f"Expected pattern not found in result: { okta_result } " )
162+ github_result_dict = self .stackql .executeStmt (registry_pull_github_query )
163+ github_result = github_result_dict [0 ]["message" ]
164+ expected_pattern = registry_pull_resp_pattern ("github" )
165+ self .assertTrue (re .search (expected_pattern , github_result ), f"Expected pattern not found in result: { github_result } " )
166+ print_test_result (f"""Test executeStmt method\n RESULTS:\n { okta_result_dict } \n { github_result_dict } """ , True )
167+
168+ @pystackql_test_setup (output = "csv" )
169+ def test_10a_executeStmt_with_csv_output (self ):
158170 okta_result = self .stackql .executeStmt (registry_pull_okta_query )
159171 expected_pattern = registry_pull_resp_pattern ("okta" )
160172 self .assertTrue (re .search (expected_pattern , okta_result ), f"Expected pattern not found in result: { okta_result } " )
161173 github_result = self .stackql .executeStmt (registry_pull_github_query )
162174 expected_pattern = registry_pull_resp_pattern ("github" )
163175 self .assertTrue (re .search (expected_pattern , github_result ), f"Expected pattern not found in result: { github_result } " )
164- print_test_result (f"""Test executeStmt method\n RESULTS:\n { okta_result } { github_result } """ , True )
176+ print_test_result (f"""Test executeStmt method with csv output\n RESULTS:\n { okta_result } \n { github_result } """ , True )
177+
178+ @pystackql_test_setup (output = "pandas" )
179+ def test_10b_executeStmt_with_pandas_output (self ):
180+ okta_result_df = self .stackql .executeStmt (registry_pull_okta_query )
181+ okta_result = okta_result_df ['message' ].iloc [0 ]
182+ expected_pattern = registry_pull_resp_pattern ("okta" )
183+ self .assertTrue (re .search (expected_pattern , okta_result ), f"Expected pattern not found in result: { okta_result } " )
184+ github_result_df = self .stackql .executeStmt (registry_pull_github_query )
185+ github_result = github_result_df ['message' ].iloc [0 ]
186+ expected_pattern = registry_pull_resp_pattern ("github" )
187+ self .assertTrue (re .search (expected_pattern , github_result ), f"Expected pattern not found in result: { github_result } " )
188+ print_test_result (f"""Test executeStmt method with pandas output\n RESULTS:\n { okta_result_df } \n { github_result_df } """ , True )
165189
166190 @pystackql_test_setup ()
167191 def test_11_execute_with_defaults (self ):
@@ -232,13 +256,16 @@ def test_19_server_mode_connectivity(self):
232256 @pystackql_test_setup (server_mode = True )
233257 def test_20_executeStmt_server_mode (self ):
234258 result = self .stackql .executeStmt (registry_pull_google_query )
235- is_valid_json_string_of_empty_list = False
236- try :
237- parsed_result = json .loads (result )
238- is_valid_json_string_of_empty_list = isinstance (parsed_result , list ) and len (parsed_result ) == 0
239- except json .JSONDecodeError :
240- pass
241- print_test_result ("Test executeStmt in server mode" , is_valid_json_string_of_empty_list , True )
259+ # Checking if the result is a list containing a single dictionary with a key 'message' and value 'OK'
260+ is_valid_response = isinstance (result , list ) and len (result ) == 1 and result [0 ].get ('message' ) == 'OK'
261+ print_test_result (f"Test executeStmt in server mode\n { result } " , is_valid_response , True )
262+
263+ @pystackql_test_setup (server_mode = True , output = 'pandas' )
264+ def test_20a_executeStmt_server_mode_with_pandas_output (self ):
265+ result_df = self .stackql .executeStmt (registry_pull_google_query )
266+ # Verifying if the result is a dataframe with a column 'message' containing the value 'OK' in its first row
267+ is_valid_response = isinstance (result_df , pd .DataFrame ) and 'message' in result_df .columns and result_df ['message' ].iloc [0 ] == 'OK'
268+ print_test_result (f"Test executeStmt in server mode with pandas output\n { result_df } " , is_valid_response , True )
242269
243270 @pystackql_test_setup (server_mode = True )
244271 def test_21_execute_server_mode_default_output (self ):
@@ -288,6 +315,7 @@ def setUp(self):
288315 self .stackql_magic = self .MAGIC_CLASS (shell = self .shell )
289316 self .query = "SELECT 1 as fred"
290317 self .expected_result = pd .DataFrame ({"fred" : [1 ]})
318+ self .statement = "REGISTRY PULL github"
291319
292320 def print_test_result (self , test_name , * checks ):
293321 all_passed = all (checks )
@@ -320,6 +348,31 @@ def test_cell_magic_query_no_output(self):
320348 checks = self .run_magic_test (line = "--no-display" , cell = self .query , expect_none = True )
321349 self .print_test_result ("Cell magic test (with --no-display)" , * checks )
322350
351+ def run_magic_statement_test (self , line , cell , expect_none = False ):
352+ # Execute the magic with our statement.
353+ result = self .stackql_magic .stackql (line = line , cell = cell )
354+ # Validate the outcome.
355+ checks = []
356+ if expect_none :
357+ checks .append (result is None )
358+ else :
359+ # Check that the output contains expected content
360+ checks .append ("OK" in result ["message" ].iloc [0 ])
361+ checks .append ('stackql_df' in self .shell .user_ns )
362+ checks .append ("OK" in self .shell .user_ns ['stackql_df' ]["message" ].iloc [0 ])
363+ return checks
364+
365+ def test_line_magic_statement (self ):
366+ checks = self .run_magic_statement_test (line = self .statement , cell = None )
367+ self .print_test_result ("Line magic statement" , * checks )
368+
369+ def test_cell_magic_statement (self ):
370+ checks = self .run_magic_statement_test (line = "" , cell = self .statement )
371+ self .print_test_result ("Cell magic statement" , * checks )
372+
373+ def test_cell_magic_statement_no_output (self ):
374+ checks = self .run_magic_statement_test (line = "--no-display" , cell = self .statement , expect_none = True )
375+ self .print_test_result ("Cell magic statement (with --no-display)" , * checks )
323376
324377class StackQLMagicTests (BaseStackQLMagicTests , unittest .TestCase ):
325378
0 commit comments