Skip to content

Commit 866cfaf

Browse files
between test case added
1 parent 8891580 commit 866cfaf

File tree

1 file changed

+65
-29
lines changed

1 file changed

+65
-29
lines changed

test/test_sql_guard_modified_unit.py

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ def cnn(self):
270270
"INSERT INTO products1 VALUES (445, 'prod3', 'shipped', 'granted', '28-02-2025', 'c3')"
271271
)
272272

273-
274-
# Trying to do array_col
273+
# Trying to do array_col
275274
conn.execute(
276275
"""
277276
CREATE TABLE orders_db.products2 (
@@ -287,13 +286,23 @@ def cnn(self):
287286

288287
# Insert values into products1 table (JSON formatted array)
289288
conn.execute(
290-
"INSERT INTO products2 VALUES (324, 'prod1', 'delivered', 'granted', '27-02-2025', 'c1', '[""electronics"", ""fashion""]')"
289+
"INSERT INTO products2 VALUES (324, 'prod1', 'delivered', 'granted', '27-02-2025', 'c1', '["
290+
"electronics"
291+
", "
292+
"fashion"
293+
"]')"
291294
)
292295
conn.execute(
293-
"INSERT INTO products2 VALUES (435, 'prod2', 'delayed', 'pending', '02-03-2025', 'c2', '[""books""]')"
296+
"INSERT INTO products2 VALUES (435, 'prod2', 'delayed', 'pending', '02-03-2025', 'c2', '["
297+
"books"
298+
"]')"
294299
)
295300
conn.execute(
296-
"INSERT INTO products2 VALUES (445, 'prod3', 'shipped', 'granted', '28-02-2025', 'c3', '[""sports"", ""toys""]')"
301+
"INSERT INTO products2 VALUES (445, 'prod3', 'shipped', 'granted', '28-02-2025', 'c3', '["
302+
"sports"
303+
", "
304+
"toys"
305+
"]')"
297306
)
298307

299308
# Creating customers table
@@ -326,7 +335,11 @@ def config(self) -> dict:
326335
{
327336
"table_name": "products2",
328337
"database_name": "orders_db",
329-
"columns": ["id", "prod_name", "category"], # category stored as JSON
338+
"columns": [
339+
"id",
340+
"prod_name",
341+
"category",
342+
], # category stored as JSON
330343
"restrictions": [{"column": "id", "value": 324}],
331344
},
332345
{
@@ -338,8 +351,8 @@ def config(self) -> dict:
338351
{
339352
"table_name": "highlights",
340353
"database_name": "countdb",
341-
"columns": ["vals", "anomalies","id"],
342-
}
354+
"columns": ["vals", "anomalies", "id"],
355+
},
343356
]
344357
}
345358

@@ -485,7 +498,7 @@ def test_distinct_and_group_by_missing_restriction(self, config, cnn):
485498
data=[(1, "prod1")],
486499
)
487500

488-
def test_array_col(self,config,cnn):
501+
def test_array_col(self, config, cnn):
489502
sql = """
490503
SELECT id, prod_name FROM products2
491504
WHERE (category LIKE '%electronics%') AND id = 324
@@ -495,46 +508,69 @@ def test_array_col(self,config,cnn):
495508
print(cnn.execute(sql).fetchall())
496509
assert cnn.execute(sql).fetchall() == [(324, "prod1")]
497510

498-
def test_cross_join_alias(self,config,cnn):
511+
def test_cross_join_alias(self, config, cnn):
499512
sql = """SELECT p1.id, p2.id FROM products1 AS p1
500513
CROSS JOIN products1 AS p2 WHERE p1.id = 324 AND p2.id = 324"""
501-
res = verify_sql(sql,config)
514+
res = verify_sql(sql, config)
502515
assert res["allowed"] == True, res
503516
print(cnn.execute(sql).fetchall())
504517

505-
def test_self_join(self,config,cnn):
518+
def test_self_join(self, config, cnn):
506519
sql = """SELECT p1.id, p2.id from products1 as p1
507520
inner join products1 as p2 on p1.id = p2.id WHERE p1.id = 324 and p2.id = 324"""
508521
res = verify_sql(sql, config)
509522
assert res["allowed"] == True, res
510523
print(cnn.execute(sql).fetchall())
511524

512-
def test_customers_restriction(self,config):
525+
def test_customers_restriction(self, config):
513526
sql = "SELECT cust_id, cust_name FROM customers WHERE (cust_id = 'c1') AND access = 'restricted'"
514527
res = verify_sql(sql, config)
515528
assert res["allowed"] == True, res
516529

517-
def test_json_field_products1(self,config,cnn):
530+
def test_json_field_products1(self, config, cnn):
518531
sql = "SELECT json_extract(category, '$[0]') FROM products2 WHERE id = 324"
519532
res = verify_sql(sql, config)
520533
assert res["allowed"] == True, res
521534

522-
def test_unnest_using_trino_array_val_cross_join(self,config):
523-
verify_sql_test('''SELECT val FROM (VALUES (ARRAY[1, 2, 3]))
524-
AS highlights(vals) CROSS JOIN UNNEST(vals) AS t(val)''',
525-
config,dialect="trino")
535+
def test_unnest_using_trino_array_val_cross_join(self, config):
536+
verify_sql_test(
537+
"""SELECT val FROM (VALUES (ARRAY[1, 2, 3]))
538+
AS highlights(vals) CROSS JOIN UNNEST(vals) AS t(val)""",
539+
config,
540+
dialect="trino",
541+
)
542+
543+
def test_unnest_using_trino_insert(self, config):
544+
verify_sql_test(
545+
"INSERT INTO highlights VALUES (1, ARRAY[10, 20, 30])",
546+
config,
547+
dialect="trino",
548+
errors={"INSERT statement is not allowed"},
549+
)
526550

527-
def test_unnest_using_trino_insert(self,config):
528-
verify_sql_test("INSERT INTO highlights VALUES (1, ARRAY[10, 20, 30])",config,
529-
dialect="trino", errors={'INSERT statement is not allowed'})
551+
def test_unnest_using_trino_cross_join(self, config):
552+
verify_sql_test(
553+
"SELECT t.val FROM highlights CROSS JOIN UNNEST(vals) AS t(val)",
554+
config,
555+
dialect="trino",
556+
)
530557

531-
def test_unnest_using_trino_cross_join(self,config):
532-
verify_sql_test("SELECT t.val FROM highlights CROSS JOIN UNNEST(vals) AS t(val)",config
533-
,dialect="trino")
558+
def test_unnest_using_trino_multi_col_alias(self, config):
559+
verify_sql_test(
560+
"SELECT t.val, h.id FROM highlights AS h CROSS JOIN UNNEST(h.vals) AS t(val)",
561+
config,
562+
dialect="trino",
563+
)
534564

535-
def test_unnest_using_trino_multi_col_alias(self,config):
536-
verify_sql_test("SELECT t.val, h.id FROM highlights AS h CROSS JOIN UNNEST(h.vals) AS t(val)",
537-
config,dialect="trino")
565+
def test_unnest_using_trino_no_alias(self, config):
566+
verify_sql_test(
567+
"SELECT anomalies from highlights CROSS JOIN UNNEST(vals)",
568+
config,
569+
dialect="trino",
570+
)
538571

539-
def test_unnest_using_trino_no_alias(self,config):
540-
verify_sql_test("SELECT anomalies from highlights CROSS JOIN UNNEST(vals)",config,dialect="trino")
572+
def test_between_operation(self, config, cnn):
573+
sql = "SELECT id from products1 where date between '26-02-2025' and '28-02-2025' and id = 324"
574+
res = verify_sql(sql, config)
575+
assert res["allowed"] == True, res
576+
print(cnn.execute(sql).fetchall())

0 commit comments

Comments
 (0)