|
| 1 | +import unittest |
| 2 | + |
| 3 | +import irods.test.helpers as helpers |
| 4 | + |
| 5 | + |
| 6 | +class TestQuery2(unittest.TestCase): |
| 7 | + |
| 8 | + def setUp(self): |
| 9 | + self.sess = helpers.make_session() |
| 10 | + |
| 11 | + if self.sess.server_version < (4, 3, 2): |
| 12 | + self.skipTest( |
| 13 | + 'GenQuery2 is not available by default in iRODS before v4.3.2.') |
| 14 | + |
| 15 | + self.coll_path_a = '/{}/home/{}/test_query2_coll_a'.format( |
| 16 | + self.sess.zone, self.sess.username) |
| 17 | + self.coll_path_b = '/{}/home/{}/test_query2_coll_b'.format( |
| 18 | + self.sess.zone, self.sess.username) |
| 19 | + self.sess.collections.create(self.coll_path_a) |
| 20 | + self.sess.collections.create(self.coll_path_b) |
| 21 | + |
| 22 | + def test_select(self): |
| 23 | + query = "SELECT COLL_NAME WHERE COLL_NAME = '{}'".format( |
| 24 | + self.coll_path_a) |
| 25 | + q = self.sess.query2(self.sess.zone, query) |
| 26 | + query_result = q.execute() |
| 27 | + query_sql = q.get_sql() |
| 28 | + self.assertIn([self.coll_path_a], query_result) |
| 29 | + self.assertEqual(len(query_result), 1) |
| 30 | + 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") |
| 31 | + |
| 32 | + def test_select_or(self): |
| 33 | + query = "SELECT COLL_NAME WHERE COLL_NAME = '{}' OR COLL_NAME = '{}'".format( |
| 34 | + self.coll_path_a, self.coll_path_b) |
| 35 | + q = self.sess.query2(self.sess.zone, query) |
| 36 | + query_result = q.execute() |
| 37 | + query_sql = q.get_sql() |
| 38 | + self.assertIn([self.coll_path_a], query_result) |
| 39 | + self.assertIn([self.coll_path_b], query_result) |
| 40 | + self.assertEqual(len(query_result), 2) |
| 41 | + 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") |
| 42 | + |
| 43 | + def test_select_and(self): |
| 44 | + query = "SELECT COLL_NAME WHERE COLL_NAME LIKE '{}' AND COLL_NAME LIKE '{}'".format( |
| 45 | + "%test_query2_coll%", "%query2_coll_a%") |
| 46 | + q = self.sess.query2(self.sess.zone, query) |
| 47 | + query_result = q.execute() |
| 48 | + query_sql = q.get_sql() |
| 49 | + self.assertIn([self.coll_path_a], query_result) |
| 50 | + self.assertEqual(len(query_result), 1) |
| 51 | + 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") |
0 commit comments