Fix db.py connection handling and test isolation
db.py: - Add conn.isolation_level = None to get_conn() — fixes row_factory + autocommit conflict. row_factory disables implicit transactions, so we need explicit autocommit mode. - Remove all conn.commit() calls (unnecessary with autocommit) pyproject.toml: - Move pytest + pytest-asyncio to main dependencies (uv run pytest uses ephemeral env with main deps only) tests/test_db.py: - Fix test_upsert_user_updates_username to not chain upsert_user() calls in assert expressions (test isolation issue)
This commit is contained in:
@@ -15,9 +15,11 @@ class TestUsers:
|
||||
assert row["username"] == "alice"
|
||||
|
||||
def test_upsert_user_updates_username(self):
|
||||
_db.upsert_user(123, "alice")
|
||||
# Two upserts to the same telegram_user_id: second one updates the username.
|
||||
# Returns the same id both times (idempotent).
|
||||
uid1 = _db.upsert_user(123, "alice")
|
||||
uid2 = _db.upsert_user(123, "alice_updated")
|
||||
assert uid2 == _db.upsert_user(123, "alice") # same id
|
||||
assert uid1 == uid2
|
||||
row = _db.get_user_by_telegram_id(123)
|
||||
assert row["username"] == "alice_updated"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user