Skip to content

Commit 5cc45a4

Browse files
committed
Fix booking mock and ruff format drift exposed by PR #110 merge
test_spend_ceiling.py's budget-ceiling tests used a bare MagicMock client, which broke once DealBookingFlow's booking path (from the Meta integration work) started reading a real base_url and issuing HTTP calls via _book_via_seller_api. Mock that call the same way the rest of the suite does. Also applies a ruff-format-only fix to helpers.py that was already failing `ruff format --check` on main.
1 parent 8300386 commit 5cc45a4

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/ad_buyer/events/helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ def emit_event_sync(
193193
# writes the fallback record (best effort, logged if it fails).
194194
future = asyncio.ensure_future(bus.publish(event))
195195
if event_type in AUDIT_EVENT_TYPES:
196-
future.add_done_callback(
197-
lambda fut, ev=event: _audit_publish_done(fut, ev)
198-
)
196+
future.add_done_callback(lambda fut, ev=event: _audit_publish_done(fut, ev))
199197
else:
200198
loop.run_until_complete(bus.publish(event))
201199
except RuntimeError:

tests/unit/test_spend_ceiling.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
import logging
16-
from unittest.mock import AsyncMock, MagicMock
16+
from unittest.mock import AsyncMock, MagicMock, patch
1717

1818
import pytest
1919

@@ -250,7 +250,8 @@ def test_booking_at_budget_books(self):
250250
recs = [_make_recommendation("prod_a", "branding", 500000, 15.0)] # cost 7500
251251
flow = self._flow_with_approved(7500, recs)
252252

253-
result = flow._execute_bookings()
253+
with patch.object(flow, "_book_via_seller_api", return_value=("q", "d", "order_1")):
254+
result = flow._execute_bookings()
254255

255256
assert result["status"] == "success"
256257
assert result["booked"] == 1
@@ -264,7 +265,8 @@ def test_booking_under_budget_books(self):
264265
]
265266
flow = self._flow_with_approved(100000, recs)
266267

267-
result = flow._execute_bookings()
268+
with patch.object(flow, "_book_via_seller_api", return_value=("q", "d", "order_1")):
269+
result = flow._execute_bookings()
268270

269271
assert result["status"] == "success"
270272
assert result["booked"] == 2
@@ -275,7 +277,10 @@ def test_missing_budget_fails_open(self, caplog):
275277
recs = [_make_recommendation("prod_a", "branding", 500000, 15.0)]
276278
flow = self._flow_with_approved(None, recs)
277279

278-
with caplog.at_level(logging.WARNING):
280+
with (
281+
caplog.at_level(logging.WARNING),
282+
patch.object(flow, "_book_via_seller_api", return_value=("q", "d", "order_1")),
283+
):
279284
result = flow._execute_bookings()
280285

281286
assert result["status"] == "success"

0 commit comments

Comments
 (0)