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

@ -60,12 +60,12 @@ class TestConstraints:
def test_insert_into_database(self, db_session, path):
"""Insert an instance into the (empty) database."""
assert db_session.query(db.Path).count() == 0
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 0
db_session.add(path)
db_session.commit()
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
def test_delete_a_referenced_first_address(self, db_session, path):
"""Remove a record that is referenced with a FK."""
@ -222,11 +222,11 @@ class TestFromAddresses:
another_address,
):
"""Test instantiation of a new `Path` instance."""
assert db_session.query(db.Path).count() == 0
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 0
db.Path.from_addresses(address, another_address)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
def test_make_the_same_path_instance_twice(
self,
@ -235,15 +235,15 @@ class TestFromAddresses:
another_address,
):
"""Test instantiation of a new `Path` instance."""
assert db_session.query(db.Path).count() == 0
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 0
db.Path.from_addresses(address, another_address)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
db.Path.from_addresses(another_address, address)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
def test_structure_of_return_value(self, address, another_address):
"""Test instantiation of a new `Path` instance."""
@ -323,11 +323,11 @@ class TestFromAddresses:
order,
):
"""Test instantiation of a new `Path` instance."""
assert db_session.query(db.Path).count() == 0
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 0
db.Path.from_order(order)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
def test_make_the_same_path_instance_from_order_twice(
self,
@ -335,15 +335,15 @@ class TestFromAddresses:
order,
):
"""Test instantiation of a new `Path` instance."""
assert db_session.query(db.Path).count() == 0
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 0
db.Path.from_order(order)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
db.Path.from_order(order)
assert db_session.query(db.Path).count() == 1
assert db_session.scalar(sa.select(sa.func.count()).select_from(db.Path)) == 1
def test_structure_of_return_value_from_order(self, order):
"""Test instantiation of a new `Path` instance."""