aurweb.testing.setup_test_db: Expunge objects

This is needed to avoid redundant objects in SQLAlchemy's
IdentityMap, since we pass a direct .execute to delete
the tables passed in. Additionally, remove our engine.connect()
call in favor of relying on the already-established Session.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-05-31 22:41:06 -07:00
parent b692b11f62
commit 794868b20f

View file

@ -21,10 +21,12 @@ def setup_test_db(*args):
test_tables = ["Users", "Sessions"]; test_tables = ["Users", "Sessions"];
setup_test_db(*test_tables) setup_test_db(*test_tables)
""" """
engine = aurweb.db.get_engine() # Make sure that we've grabbed the engine before using the session.
conn = engine.connect() aurweb.db.get_engine()
tables = list(args) tables = list(args)
for table in tables: for table in tables:
conn.execute(f"DELETE FROM {table}") aurweb.db.session.execute(f"DELETE FROM {table}")
conn.close()
# Expunge all objects from SQLAlchemy's IdentityMap.
aurweb.db.session.expunge_all()