mirror of
https://github.com/corazoncp/zoom-sched-poc.git
synced 2026-12-01 04:50:31 +00:00
test(CR-16): wrap sqlite3.connect calls in contextlib.closing
- Import closing from contextlib in tests/test_app.py - Wrap direct sqlite3.connect(db_file) calls in with closing(...) for deterministic connection cleanup
This commit is contained in:
1 parent
423cbabc1c
commit
ebe21ecf15
1 file changed
+4
-3
+4
-3
@@ -1,3 +1,4 @@
|
|||||||
|
from contextlib import closing
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -177,7 +178,8 @@ def test_booking_flow_never_persists_zoom_credentials(client, monkeypatch):
|
|||||||
json={"credentials": SAMPLE_CREDS},
|
json={"credentials": SAMPLE_CREDS},
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_db_text = sqlite3.connect(db_file).execute("SELECT * FROM appointments").fetchall()
|
with closing(sqlite3.connect(db_file)) as conn:
|
||||||
|
raw_db_text = conn.execute("SELECT * FROM appointments").fetchall()
|
||||||
serialized = str(raw_db_text)
|
serialized = str(raw_db_text)
|
||||||
assert "super_secret_value" not in serialized
|
assert "super_secret_value" not in serialized
|
||||||
assert "cli_test_1234" not in serialized
|
assert "cli_test_1234" not in serialized
|
||||||
@@ -488,9 +490,8 @@ def test_db_init_sets_wal_once_not_on_every_connection(tmp_path: Path):
|
|||||||
mode = conn.execute("PRAGMA journal_mode;").fetchone()[0]
|
mode = conn.execute("PRAGMA journal_mode;").fetchone()[0]
|
||||||
assert mode.lower() == "wal"
|
assert mode.lower() == "wal"
|
||||||
|
|
||||||
raw_conn = sqlite3.connect(db_file)
|
with closing(sqlite3.connect(db_file)) as raw_conn:
|
||||||
raw_conn.execute("PRAGMA journal_mode=DELETE;")
|
raw_conn.execute("PRAGMA journal_mode=DELETE;")
|
||||||
raw_conn.close()
|
|
||||||
|
|
||||||
with db.get_connection(db_file) as conn:
|
with db.get_connection(db_file) as conn:
|
||||||
mode_after = conn.execute("PRAGMA journal_mode;").fetchone()[0]
|
mode_after = conn.execute("PRAGMA journal_mode;").fetchone()[0]
|
||||||
|
|||||||
Reference in new issue
Block a user