Ejemplo n.º 1
0
class TestBase(TestCase):
    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)

    def tearDown(self):
        self.db_session.rollback()
        self.db_session.close()

    def create_system_admin(self, *args, **kwargs):
        from app.controllers.account import create_account
        from app.schemas.account import AccountCreate

        return create_account(
            self.db_session,
            first_name="Admin",
            last_name="Istrator",
            email="*****@*****.**",
            password="******",
            is_system_admin=True,
            is_active=True,
            send_registration_email=False,
        )

    def auth_headers(self, email="*****@*****.**", password="******"):
        payload = {"username": email, "password": password}
        resp = self.client.post("/auth/token", data=payload)
        return {"Authorization": "Bearer " + resp.json().get("access_token")}
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
def get_db():
    try:
        db_session = DBSession()
        yield db_session
    finally:
        db_session.close()