Пример #1
0
def test_startup():
    from fastapi_sqla import _Session, startup

    startup()

    session = _Session()

    assert session.execute(text("SELECT 1")).scalar() == 1
Пример #2
0
def test_all_opened_sessions_are_within_the_same_transaction(
    sqla_connection, session, singer_cls
):
    from fastapi_sqla import _Session

    session.add(singer_cls(id=1, name="Bob Marley", country="Jamaica"))
    session.commit()

    other_session = _Session()
    assert other_session.query(singer_cls).get(1)
Пример #3
0
def session(sqla_transaction, sqla_connection):
    """Sqla session to use when creating db fixtures.

    While it does not write any record in DB, the application will still be able to
    access any record committed with that session.
    """
    import fastapi_sqla

    session = fastapi_sqla._Session(bind=sqla_connection)
    yield session
    session.close()
Пример #4
0
def test_startup_reflect_test_table():
    from fastapi_sqla import Base, _Session, startup

    class TestTable(Base):
        __tablename__ = "test_table"

    startup()

    session = _Session()
    session.add(TestTable(id=1))
    session.add(TestTable(id=2))

    assert session.query(TestTable).count() == 2
Пример #5
0
 def now():
     session = _Session()
     result = session.execute(text("SELECT 1")).scalar()
     session.close()
     return result