From e9dbf528d702b871ccb4ad777c945c3298af0abe Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 13:43:38 +0100 Subject: [PATCH] Query order history via the `db.session` The query then runs in the same transaction as the `db.session` For that, `addresses_mock` now replaces only `session.query()` instead of the whole `db.session`. --- src/velofy/forecasts/timify.py | 2 +- tests/forecasts/timify/test_aggregate_orders.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/velofy/forecasts/timify.py b/src/velofy/forecasts/timify.py index 7f53ef3..826afc6 100644 --- a/src/velofy/forecasts/timify.py +++ b/src/velofy/forecasts/timify.py @@ -141,7 +141,7 @@ class OrderHistory: start_at; """, # noqa:S608 ), - con=db.connection, + con=db.session.connection(), index_col=["pixel_id", "start_at"], ) diff --git a/tests/forecasts/timify/test_aggregate_orders.py b/tests/forecasts/timify/test_aggregate_orders.py index 6c60a06..2fb1db1 100644 --- a/tests/forecasts/timify/test_aggregate_orders.py +++ b/tests/forecasts/timify/test_aggregate_orders.py @@ -17,7 +17,7 @@ class TestAggregateOrders: """ @pytest.fixture - def addresses_mock(self, mocker, monkeypatch): + def addresses_mock(self, db_session, mocker, monkeypatch): """A `Mock` whose `.return_value` are to be set ... ... to the addresses that are gridified. The addresses are @@ -29,7 +29,7 @@ class TestAggregateOrders: query = ( mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 ) - monkeypatch.setattr(db, "session", mock) + monkeypatch.setattr(db_session, "query", mock.query) return query