-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor database session management and enhance test structure
- Loading branch information
Showing
5 changed files
with
46 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
from dsst_etl import get_db_engine | ||
from dsst_etl.db import get_db_session_new, init_db | ||
|
||
class BaseTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.engine = get_db_engine(is_test=True) | ||
init_db(self.engine) | ||
|
||
# Start a transaction at the connection level | ||
self.connection = self.engine.connect() | ||
self.trans = self.connection.begin() | ||
|
||
# Create session bound to this connection | ||
self.session = get_db_session_new(bind=self.connection) | ||
|
||
def tearDown(self): | ||
if self.session.is_active: | ||
self.session.close() | ||
|
||
# Roll back the transaction | ||
if self.trans.is_active: | ||
self.trans.rollback() | ||
|
||
# Close the connection | ||
self.connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters