def setUp(self): self.db_session = DBSession() self.connection = engine.connect() # # Configure Search DDL triggers. Base.metadata.drop_all(self.connection) Base.metadata.create_all(self.connection) self.client = TestClient(app)
async def create_admin(): """If admin account doesn't exist, create it.""" from app.database import DBSession from app.controllers.account import create_account from app.controllers.account import get_account_by_email db_session = DBSession() account_data = { "email": "*****@*****.**", "password": "******", "first_name": "Admin", "last_name": "Istrator", "is_system_admin": True, "is_active": True, } account_obj = get_account_by_email(db_session, email=account_data["email"]) if account_obj: return create_account(db_session, **account_data) db_session.close()
def get_db(): try: db_session = DBSession() yield db_session finally: db_session.close()
def add(instance): session = DBSession() session.add(instance) session.commit()
def query(cls): return DBSession().query(cls)
def delete(instance): session = DBSession() session.delete(instance) session.commit()