Skip to content

Commit faee3a0

Browse files
committed
Add real table lifecycle integration test
1 parent 075ce96 commit faee3a0

6 files changed

Lines changed: 71 additions & 3 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55
.mypy_cache/
66
.ruff_cache/
77
.venv/
8+
.idea/
89
build/
910
dist/
1011
release/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Windows 实机测试步骤、前置条件、测试场景和真实数据库地址
137137
集成测试覆盖:
138138

139139
- SQLAlchemy Core DDL、DML、查询
140+
- 真实表生命周期:建表、表存在性检查、插入、查询、更新、删除和清理
140141
- 事务回滚
141142
- 批量插入
142143
- ORM CRUD
65 Bytes
Binary file not shown.
333 Bytes
Binary file not shown.

docs/真实库测试说明.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pytest -m integration tests/test_integration_env.py -q
104104
验证内容:
105105

106106
- SQLAlchemy Core 建表、插入、查询。
107+
- 真实表生命周期:建表前存在性检查、建表后存在性检查、列反射、批量插入、条件查询、更新、删除、清理后存在性检查。
107108
- 事务回滚。
108109
- 批量插入。
109110
- ORM CRUD。
@@ -168,9 +169,9 @@ M 兼容: testm
168169

169170
```text
170171
本地单元测试: 43 passed, 19 skipped
171-
A 兼容 integration: 13 passed
172-
B 兼容 integration: 13 passed
173-
M 兼容 integration: 13 passed
172+
A 兼容 integration: 14 passed
173+
B 兼容 integration: 14 passed
174+
M 兼容 integration: 14 passed
174175
A/B/M 兼容场景测试: 18 passed
175176
```
176177

tests/test_integration_env.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,71 @@ def test_bulk_insert_against_gaussdb_url_from_env():
127127
_drop_table(conn, table_name)
128128

129129

130+
@pytest.mark.integration
131+
def test_real_table_lifecycle_crud_against_gaussdb_url_from_env():
132+
engine = _engine()
133+
table_name = _table_name("gdbdrv_lifecycle_ut")
134+
metadata = MetaData()
135+
table = Table(
136+
table_name,
137+
metadata,
138+
Column("id", Integer, primary_key=True),
139+
Column("name", String(32), nullable=False),
140+
Column("score", Integer, nullable=False),
141+
)
142+
143+
try:
144+
with engine.begin() as conn:
145+
_drop_table(conn, table_name)
146+
inspector = inspect(conn)
147+
assert inspector.has_table(table_name) is False
148+
149+
table.create(conn)
150+
inspector.clear_cache()
151+
assert inspector.has_table(table_name) is True
152+
153+
columns = {column["name"]: column for column in inspector.get_columns(table_name)}
154+
assert set(columns) == {"id", "name", "score"}
155+
assert columns["id"]["nullable"] is False
156+
assert columns["name"]["nullable"] is False
157+
assert columns["score"]["nullable"] is False
158+
159+
conn.execute(
160+
table.insert(),
161+
[
162+
{"id": 1, "name": "alice", "score": 90},
163+
{"id": 2, "name": "bob", "score": 80},
164+
{"id": 3, "name": "carol", "score": 70},
165+
],
166+
)
167+
168+
rows = conn.execute(
169+
select(table.c.id, table.c.name, table.c.score)
170+
.where(table.c.score >= 80)
171+
.order_by(table.c.id)
172+
).all()
173+
assert rows == [(1, "alice", 90), (2, "bob", 80)]
174+
175+
conn.execute(
176+
table.update().where(table.c.id == 2).values(score=85)
177+
)
178+
assert conn.execute(
179+
select(table.c.score).where(table.c.id == 2)
180+
).scalar_one() == 85
181+
182+
conn.execute(table.delete().where(table.c.score < 80))
183+
remaining = conn.execute(
184+
select(table.c.id, table.c.name, table.c.score).order_by(table.c.id)
185+
).all()
186+
assert remaining == [(1, "alice", 90), (2, "bob", 85)]
187+
finally:
188+
with engine.begin() as conn:
189+
_drop_table(conn, table_name)
190+
inspector = inspect(conn)
191+
inspector.clear_cache()
192+
assert inspector.has_table(table_name) is False
193+
194+
130195
@pytest.mark.integration
131196
def test_orm_crud_against_gaussdb_url_from_env():
132197
engine = _engine()

0 commit comments

Comments
 (0)