| self = <tests.test_option_sniper_service.TestEngineOrdering object at 0x129c04bc0>
|
| mock_factory = <MagicMock name='BrokerHandlerFactory' id='5018604448'>
|
| mock_time = <MagicMock name='time' id='5018434784'>
|
| mock_mongo = <Mock name='DBAccounting().__enter__().collection()' id='5018611696'>
|
|
|
| @patch("rtrader.services.option_sniper_service.time")
|
| @patch("rtrader.services.option_sniper_service.BrokerHandlerFactory")
|
| def test_ordering_max_price_breach_cancels(self, mock_factory, mock_time, mock_mongo):
|
| broker = Mock()
|
| broker.shares_long.return_value = 0
|
| broker.get_order_by_id.return_value = {"status": "open"}
|
| broker.get_option_quote.return_value = {
|
| "quotes": {
|
| "AAPL260307C00230000": {"bid_price": 3.15, "ask_price": 3.50}
|
| }
|
| }
|
| mock_factory.get_handler.return_value = broker
|
|
|
| repo = OptionSniperRepository()
|
| engine = OptionSniperEngine(repo)
|
| job = _make_job(
|
| status="ordering",
|
| current_order_id="order-old",
|
| current_limit_price=3.10,
|
| max_price=3.20,
|
| ladder_step=1, # step becomes 2 → 3.15 + 2*0.05 = 3.25 > 3.20
|
| )
|
|
|
| engine._handle_ordering(job)
|
|
|
| assert job.status == "monitoring"
|
| assert job.current_order_id is None
|
| > broker.cancel_orders.assert_called_with("AAPL260307C00230000")
|
|
|
| tests/test_option_sniper_service.py:431:
|
| _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|
|
|
| self = <Mock name='BrokerHandlerFactory.get_handler().cancel_orders' id='4880217536'>
|
| args = ('AAPL260307C00230000',), kwargs = {}
|
| expected = "cancel_orders('AAPL260307C00230000')", actual = 'not called.'
|
| error_message = "expected call not found.\nExpected: cancel_orders('AAPL260307C00230000')\n Actual: not called."
|
|
|
| def assert_called_with(self, /, *args, **kwargs):
|
| """assert that the last call was made with the specified arguments.
|
|
|
| Raises an AssertionError if the args and keyword args passed in are
|
| different to the last call to the mock."""
|
| if self.call_args is None:
|
| expected = self._format_mock_call_signature(args, kwargs)
|
| actual = 'not called.'
|
| error_message = ('expected call not found.\nExpected: %s\n Actual: %s'
|
| % (expected, actual))
|
| > raise AssertionError(error_message)
|
| E AssertionError: expected call not found.
|
| E Expected: cancel_orders('AAPL260307C00230000')
|
| E Actual: not called.
|
|
|
| ../.pyenv/versions/3.12.12/lib/python3.12/unittest/mock.py:940: AssertionError
|