Count rows with select() in the tests
`Session.query()` is the legacy API in SQLAlchemy 2.x.
This commit is contained in:
parent
455af6dfdb
commit
c1f04c65aa
1 changed files with 94 additions and 45 deletions
|
|
@ -31,12 +31,18 @@ class TestConstraints:
|
|||
|
||||
def test_insert_into_into_database(self, db_session, replayed_order):
|
||||
"""Insert an instance into the (empty) database."""
|
||||
assert db_session.query(db.ReplayedOrder).count() == 0
|
||||
assert (
|
||||
db_session.scalar(sa.select(sa.func.count()).select_from(db.ReplayedOrder))
|
||||
== 0
|
||||
)
|
||||
|
||||
db_session.add(replayed_order)
|
||||
db_session.commit()
|
||||
|
||||
assert db_session.query(db.ReplayedOrder).count() == 1
|
||||
assert (
|
||||
db_session.scalar(sa.select(sa.func.count()).select_from(db.ReplayedOrder))
|
||||
== 1
|
||||
)
|
||||
|
||||
def test_delete_a_referenced_simulation(self, db_session, replayed_order):
|
||||
"""Remove a record that is referenced with a FK."""
|
||||
|
|
@ -202,12 +208,12 @@ class TestConstraints:
|
|||
dispatch_at=scheduled_delivery_at + dt.timedelta(hours=1),
|
||||
)
|
||||
|
||||
assert db_session.query(db.Order).count() == 0
|
||||
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Order)) == 0
|
||||
|
||||
db_session.add(replay_pre_order)
|
||||
db_session.commit()
|
||||
|
||||
assert db_session.query(db.Order).count() == 1
|
||||
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Order)) == 1
|
||||
|
||||
def test_scheduled_order_too_late(self, db_session, make_replay_order):
|
||||
"""Insert an instance with invalid data."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue