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
|
|
@ -1,6 +1,7 @@
|
|||
"""Test the ORM's `Customer` model."""
|
||||
|
||||
import pytest
|
||||
import sqlalchemy as sa
|
||||
|
||||
from velofy import db
|
||||
|
||||
|
|
@ -26,9 +27,13 @@ class TestConstraints:
|
|||
|
||||
def test_insert_into_database(self, db_session, customer):
|
||||
"""Insert an instance into the (empty) database."""
|
||||
assert db_session.query(db.Customer).count() == 0
|
||||
assert (
|
||||
db_session.scalar(sa.select(sa.func.count()).select_from(db.Customer)) == 0
|
||||
)
|
||||
|
||||
db_session.add(customer)
|
||||
db_session.commit()
|
||||
|
||||
assert db_session.query(db.Customer).count() == 1
|
||||
assert (
|
||||
db_session.scalar(sa.select(sa.func.count()).select_from(db.Customer)) == 1
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue