Skip to content

Commit

Permalink
[irods#7795] iquery: Add test for query tab in where clause
Browse files Browse the repository at this point in the history
  • Loading branch information
alanking committed Feb 13, 2025
1 parent d49877c commit 9b6ce07
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/irods/test/test_iquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,25 @@ def test_genquery2_maps_genquery_user_zone_columns_to_correct_database_columns__
query_string = f"select DATA_ACCESS_USER_NAME, DATA_ACCESS_USER_ZONE, count(DATA_ID) where DATA_NAME = '{data_name}' group by DATA_ACCESS_USER_NAME, DATA_ACCESS_USER_ZONE"
json_string = json.dumps([[self.user.username, self.user.zone_name, '1']], separators=(',', ':'))
self.user.assert_icommand(['iquery', query_string], 'STDOUT', [json_string])

def test_iquery_correctly_parses_queries_with_tabs_in_the_where_clause__issue_7795(self):
# Run a basic query to get the expected output.
query_string = f"select USER_ID where USER_NAME = '{self.user.username}'"
expected_output = self.user.assert_icommand(["iquery", query_string], "STDOUT")[1].strip()
expected_user_id = json.loads(expected_output)[0][0]

# Now construct a query that should return the same results, but with a tab in the where clause.
query_string_with_tab_in_where_clause = query_string + "\tand USER_TYPE = 'rodsuser'"

# iquest will fail because there is a tab in the where clause.
self.user.assert_icommand(
["iquest", "%s", query_string_with_tab_in_where_clause],
"STDOUT",
"CAT_NO_ROWS_FOUND: Nothing was found matching your query")

# iquery will succeed because it uses a real parser.
output = self.user.assert_icommand(["iquery", query_string_with_tab_in_where_clause], "STDOUT")[1].strip()
user_id = json.loads(output)[0][0]

# ...should match.
self.assertEqual(user_id, expected_user_id)

0 comments on commit 9b6ce07

Please sign in to comment.