Skip to content

Commit 8b9b804

Browse files
committed
test for issue 20
1 parent a0a4e22 commit 8b9b804

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ engine = create_engine(DATABASE_URL, echo=False)
9595
metadata = MetaData()
9696

9797

98-
class Base(DeclarativeBase):
99-
pass
100-
101-
10298
def main():
10399
demo_table = Table(
104100
"demo_table",

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ pytest
55
# twine
66
alembic
77
testcontainers-iris
8-
pytest-github-actions-annotate-failures

tests/test_suite.py

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sqlalchemy.testing import config
1212
from sqlalchemy.orm import Session
1313
from sqlalchemy import testing
14-
from sqlalchemy import Table, Column, select, func
14+
from sqlalchemy import Table, Column, select, func, text
1515
from sqlalchemy.types import Integer
1616
from sqlalchemy.types import String
1717
from sqlalchemy.types import VARBINARY
@@ -516,6 +516,7 @@ def test_add_table_comment(self, connection):
516516
def test_drop_table_comment(self, connection):
517517
pass
518518

519+
519520
class IRISPaginationTest(fixtures.TablesTest):
520521

521522
@classmethod
@@ -538,14 +539,16 @@ def define_tables(cls, metadata):
538539
def insert_data(cls, connection):
539540
connection.execute(
540541
cls.tables.data.insert(),
541-
[
542-
{"id": i, "value": f"value_{i}"} for i in range(1, 21)
543-
],
542+
[{"id": i, "value": f"value_{i}"} for i in range(1, 21)],
544543
)
545544
connection.execute(
546545
cls.tables.users.insert(),
547546
[
548-
{"user_id": i, "username": f"user_{i}", "email": f"user_{i}@example.com"}
547+
{
548+
"user_id": i,
549+
"username": f"user_{i}",
550+
"email": f"user_{i}@example.com",
551+
}
549552
for i in range(1, 31)
550553
],
551554
)
@@ -605,12 +608,12 @@ def test_pagination_two_tables_join(self):
605608
select(
606609
self.tables.data.c.value,
607610
self.tables.users.c.username,
608-
self.tables.users.c.email
611+
self.tables.users.c.email,
609612
)
610613
.select_from(
611614
self.tables.data.join(
612615
self.tables.users,
613-
self.tables.data.c.id == self.tables.users.c.user_id
616+
self.tables.data.c.id == self.tables.users.c.user_id,
614617
)
615618
)
616619
.order_by(self.tables.data.c.id)
@@ -675,4 +678,49 @@ def test_pagination_count_total(self):
675678
.limit(page_size)
676679
.offset((total_pages_data - 1) * page_size)
677680
).fetchall()
678-
assert len(result) == 6 # Last page has 6 records (20 - 14)
681+
assert len(result) == 6 # Last page has 6 records (20 - 14)
682+
683+
684+
class Issue20Test(fixtures.TablesTest):
685+
686+
def test_with(self):
687+
sql = """
688+
WITH cte AS (
689+
SELECT 123 as n, :param as message
690+
),
691+
cte1 AS (
692+
SELECT 345 as n, :param1 as message
693+
),
694+
cte2 AS (
695+
SELECT *, :param2 as message2
696+
FROM cte
697+
)
698+
SELECT *, :global as test FROM %s;
699+
"""
700+
701+
params = {
702+
"param": "hello",
703+
"param2": "hello2",
704+
"param1": "hello1",
705+
"global": "global_value",
706+
}
707+
with config.db.connect() as conn:
708+
result = conn.execute(
709+
text(sql % "cte"),
710+
params,
711+
).fetchall()
712+
assert result == [(123, "hello", "global_value")]
713+
714+
with config.db.connect() as conn:
715+
result = conn.execute(
716+
text(sql % "cte1"),
717+
params,
718+
).fetchall()
719+
assert result == [(345, "hello1", "global_value")]
720+
721+
with config.db.connect() as conn:
722+
result = conn.execute(
723+
text(sql % "cte2"),
724+
params,
725+
).fetchall()
726+
assert result == [(123, "hello", "hello2", "global_value")]

0 commit comments

Comments
 (0)