Skip to content

Commit 78557d9

Browse files
committed
[ 597] genquery2_test: Replace Postgres-specific assertions
Many of the tests in genquery2_tests.py include assertions on the specific SQL strings generated by GenQuery2. These assertions assume a Postgres database, causing the tests to fail on non-Postgres databases which are nonetheless supported by the iRODS server. These assertions have been replaced. This changes the Postgres-specific assertions in many of the genquery2_test tests to just assert that a table name is returned. We cannot assert the specific contents without reaching out to the server to detect the version and flavor of the database. Even then, the specific results may vary over time. Testing the generated SQL is more the responsibility of the GenQuery2 parser and API in the server anyway, so this test should just be asserting that a result that sort of looks like what we want is being returned by the library.
1 parent 01eca53 commit 78557d9

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

irods/test/genquery2_test.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
class TestGenQuery2(unittest.TestCase):
77

8-
def setUp(self):
8+
@classmethod
9+
def setUpClass(self):
910
self.sess = helpers.make_session()
1011

1112
if self.sess.server_version < (4, 3, 2):
@@ -19,71 +20,63 @@ def setUp(self):
1920
self.sess.collections.create(self.coll_path_a)
2021
self.sess.collections.create(self.coll_path_b)
2122

22-
def tearDown(self):
23+
@classmethod
24+
def tearDownClass(self):
2325
'''Remove test data and close connections
2426
'''
2527
self.sess.collections.remove(self.coll_path_a, force=True)
2628
self.sess.collections.remove(self.coll_path_b, force=True)
2729
self.sess.cleanup()
2830

2931
def test_select(self):
30-
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(
31-
self.coll_path_a)
32+
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(self.coll_path_a)
3233
q = self.sess.genquery2_object()
3334
query_result = q.execute(query)
34-
query_sql = q.get_sql(query)
3535
self.assertIn([self.coll_path_a], query_result)
3636
self.assertEqual(len(query_result), 1)
37-
# This assumes the iCAT database runs on PostgreSQL
38-
self.assertEqual(query_sql, "select distinct t0.coll_name from R_COLL_MAIN t0 inner join R_OBJT_ACCESS pcoa on t0.coll_id = pcoa.object_id inner join R_TOKN_MAIN pct on pcoa.access_type_id = pct.token_id inner join R_USER_MAIN pcu on pcoa.user_id = pcu.user_id where t0.coll_name = ? and pcoa.access_type_id >= 1000 fetch first 256 rows only")
37+
# Use upper() here in case GenQuery2 returns lowercase table names in a future implementation.
38+
self.assertIn('R_COLL_MAIN', q.get_sql(query).upper())
3939

4040
def test_select_with_explicit_zone(self):
41-
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(
42-
self.coll_path_a)
41+
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(self.coll_path_a)
4342
q = self.sess.genquery2_object()
4443
query_result = q.execute(query, zone=self.sess.zone)
45-
query_sql = q.get_sql(query, zone=self.sess.zone)
4644
self.assertIn([self.coll_path_a], query_result)
4745
self.assertEqual(len(query_result), 1)
48-
# This assumes the iCAT database runs on PostgreSQL
49-
self.assertEqual(query_sql, "select distinct t0.coll_name from R_COLL_MAIN t0 inner join R_OBJT_ACCESS pcoa on t0.coll_id = pcoa.object_id inner join R_TOKN_MAIN pct on pcoa.access_type_id = pct.token_id inner join R_USER_MAIN pcu on pcoa.user_id = pcu.user_id where t0.coll_name = ? and pcoa.access_type_id >= 1000 fetch first 256 rows only")
46+
# Use upper() here in case GenQuery2 returns lowercase table names in a future implementation.
47+
self.assertIn('R_COLL_MAIN', q.get_sql(query).upper())
5048

5149
def test_select_with_shorthand(self):
52-
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(
53-
self.coll_path_a)
50+
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(self.coll_path_a)
5451
query_result = self.sess.genquery2(query)
5552
self.assertIn([self.coll_path_a], query_result)
5653
self.assertEqual(len(query_result), 1)
5754

5855
def test_select_with_shorthand_and_explicit_zone(self):
59-
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(
60-
self.coll_path_a)
56+
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format(self.coll_path_a)
6157
query_result = self.sess.genquery2(query, zone=self.sess.zone)
6258
self.assertIn([self.coll_path_a], query_result)
6359
self.assertEqual(len(query_result), 1)
6460

6561
def test_select_or(self):
66-
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}' OR COLL_NAME = '{}'".format(
67-
self.coll_path_a, self.coll_path_b)
62+
query = "SELECT COLL_NAME WHERE COLL_NAME = '{}' OR COLL_NAME = '{}'".format(self.coll_path_a, self.coll_path_b)
6863
q = self.sess.genquery2_object()
6964
query_result = q.execute(query)
70-
query_sql = q.get_sql(query)
7165
self.assertIn([self.coll_path_a], query_result)
7266
self.assertIn([self.coll_path_b], query_result)
7367
self.assertEqual(len(query_result), 2)
74-
# This assumes the iCAT database runs on PostgreSQL
75-
self.assertEqual(query_sql, "select distinct t0.coll_name from R_COLL_MAIN t0 inner join R_OBJT_ACCESS pcoa on t0.coll_id = pcoa.object_id inner join R_TOKN_MAIN pct on pcoa.access_type_id = pct.token_id inner join R_USER_MAIN pcu on pcoa.user_id = pcu.user_id where t0.coll_name = ? or t0.coll_name = ? and pcoa.access_type_id >= 1000 fetch first 256 rows only")
68+
# Use upper() here in case GenQuery2 returns lowercase table names in a future implementation.
69+
self.assertIn('R_COLL_MAIN', q.get_sql(query).upper())
7670

7771
def test_select_and(self):
7872
query = "SELECT COLL_NAME WHERE COLL_NAME LIKE '{}' AND COLL_NAME LIKE '{}'".format(
7973
"%test_query2_coll%", "%query2_coll_a%")
8074
q = self.sess.genquery2_object()
8175
query_result = q.execute(query)
82-
query_sql = q.get_sql(query)
8376
self.assertIn([self.coll_path_a], query_result)
8477
self.assertEqual(len(query_result), 1)
85-
# This assumes the iCAT database runs on PostgreSQL
86-
self.assertEqual(query_sql, "select distinct t0.coll_name from R_COLL_MAIN t0 inner join R_OBJT_ACCESS pcoa on t0.coll_id = pcoa.object_id inner join R_TOKN_MAIN pct on pcoa.access_type_id = pct.token_id inner join R_USER_MAIN pcu on pcoa.user_id = pcu.user_id where t0.coll_name like ? and t0.coll_name like ? and pcoa.access_type_id >= 1000 fetch first 256 rows only")
78+
# Use upper() here in case GenQuery2 returns lowercase table names in a future implementation.
79+
self.assertIn('R_COLL_MAIN', q.get_sql(query).upper())
8780

8881
def test_column_mappings(self):
8982
q = self.sess.genquery2_object()

0 commit comments

Comments
 (0)