Count rows with select() in the tests

`Session.query()` is the legacy API in SQLAlchemy 2.x.
This commit is contained in:
Alexander Hess 2026-12-01 23:17:29 +01:00
commit c1f04c65aa
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -43,12 +43,22 @@ class TestConstraints:
def test_insert_into_database(self, db_session, assoc):
"""Insert an instance into the (empty) database."""
assert db_session.query(db.AddressPixelAssociation).count() == 0
assert (
db_session.scalar(
sa.select(sa.func.count()).select_from(db.AddressPixelAssociation),
)
== 0
)
db_session.add(assoc)
db_session.commit()
assert db_session.query(db.AddressPixelAssociation).count() == 1
assert (
db_session.scalar(
sa.select(sa.func.count()).select_from(db.AddressPixelAssociation),
)
== 1
)
def test_delete_a_referenced_address(self, db_session, assoc):
"""Remove a record that is referenced with a FK."""