Skip to content

Commit 5f90f71

Browse files
committed
fix(test): wrap handler construction in RequestDTOFactory patch
ListRequestsHandler now eagerly instantiates RequestDTOFactory in __init__ (factory hoist). The previous test patched the factory after the handler was already constructed, so the patch had no effect and the real factory accessed attributes the SimpleNamespace mock did not define (e.g. last_status_check). Move the construction inside the patch context and re-target the patch at the import site.
1 parent db88b2f commit 5f90f71

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

tests/unit/application/queries/test_list_requests_filter_by_type.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,24 @@ def _run_handler_with_requests(all_requests, query):
8282
mock_uow_factory = MagicMock()
8383
mock_uow_factory.create_unit_of_work.return_value = mock_uow
8484

85-
handler = ListRequestsHandler(
86-
uow_factory=mock_uow_factory,
87-
logger=mock_logger,
88-
error_handler=mock_error_handler,
89-
generic_filter_service=mock_filter_service,
90-
)
91-
92-
# Patch RequestDTOFactory so we don't need full domain wiring
93-
with patch("orb.application.factories.request_dto_factory.RequestDTOFactory") as MockFactory:
85+
# Patch RequestDTOFactory at the import site so we don't need full domain wiring.
86+
# Patch must wrap handler construction because the handler eagerly instantiates
87+
# self._dto_factory = RequestDTOFactory() in __init__.
88+
with patch("orb.application.queries.request_query_handlers.RequestDTOFactory") as MockFactory:
9489
mock_dto_factory = MagicMock()
9590
MockFactory.return_value = mock_dto_factory
9691
mock_dto_factory.create_from_domain.side_effect = lambda req, machines: SimpleNamespace(
9792
request_id=str(req.request_id.value),
9893
request_type=req.request_type.value,
9994
)
10095

96+
handler = ListRequestsHandler(
97+
uow_factory=mock_uow_factory,
98+
logger=mock_logger,
99+
error_handler=mock_error_handler,
100+
generic_filter_service=mock_filter_service,
101+
)
102+
101103
import asyncio
102104

103105
return asyncio.run(handler.execute_query(query))

0 commit comments

Comments
 (0)