X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ftest_market.py;h=e6e6f36f9459468dbcb9de4583cd3108f3c3d0d6;hb=a4bb44d8bc27af7c57f439ffd9edca51c2f0afb4;hp=07188aca1d7c7344d315d0501f1740fe0ed4511b;hpb=311608f375c267c1498c5a98d8f6a895cf147dd9;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/tests/test_market.py b/tests/test_market.py index 07188ac..e6e6f36 100644 --- a/tests/test_market.py +++ b/tests/test_market.py @@ -402,6 +402,40 @@ class MarketTest(WebMockTestCase): m.report.log_order.assert_called_with(order_mock2, 2, new_order=new_order_mock) new_order_mock.run.assert_called_once_with() + with self.subTest("disappearing order no action to do"), \ + mock.patch("market.ReportStore"): + all_orders.reset_mock() + m = market.Market(self.ccxt, self.market_args()) + + order_mock1 = mock.Mock() + order_mock2 = mock.Mock() + all_orders.side_effect = [ + [order_mock1, order_mock2], + [order_mock1, order_mock2], + + [order_mock1, order_mock2], + [order_mock1, order_mock2], + + [] + ] + + order_mock1.get_status.side_effect = ["open", "closed"] + order_mock2.get_status.side_effect = ["open", "error_disappeared"] + + order_mock1.trade = mock.Mock() + trade_mock = mock.Mock() + order_mock2.trade = trade_mock + + trade_mock.tick_actions_recreate.return_value = "tick1" + trade_mock.prepare_order.return_value = None + + m.follow_orders() + + trade_mock.tick_actions_recreate.assert_called_once_with(2) + trade_mock.prepare_order.assert_called_once_with(compute_value="tick1") + m.report.log_error.assert_called_once_with("follow_orders", message=mock.ANY) + m.report.log_order.assert_called_with(order_mock2, 2, finished=True) + @mock.patch.object(market.BalanceStore, "fetch_balances") def test_move_balance(self, fetch_balances): for debug in [True, False]: @@ -849,7 +883,7 @@ class MarketTest(WebMockTestCase): @mock.patch("market.ReportStore.log_error") @mock.patch("market.Market.store_report") def test_process(self, store_report, log_error, process): - m = market.Market(self.ccxt, self.market_args()) + m = market.Market(self.ccxt, self.market_args(), options={"foo": "bar"}) with self.subTest(actions=[], before=False, after=False): m.process([]) @@ -863,7 +897,7 @@ class MarketTest(WebMockTestCase): with self.subTest(before=True, after=False): m.process(["foo"], before=True) - process.assert_called_once_with("foo", steps="before") + process.assert_called_once_with("foo", options={"foo": "bar"}, steps="before") store_report.assert_called_once() log_error.assert_not_called() @@ -873,7 +907,7 @@ class MarketTest(WebMockTestCase): with self.subTest(before=False, after=True): m.process(["sell_all"], after=True) - process.assert_called_once_with("sell_all", steps="after") + process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="after") store_report.assert_called_once() log_error.assert_not_called() @@ -883,7 +917,7 @@ class MarketTest(WebMockTestCase): with self.subTest(before=False, after=False): m.process(["foo"]) - process.assert_called_once_with("foo", steps="all") + process.assert_called_once_with("foo", options={"foo": "bar"}, steps="all") store_report.assert_called_once() log_error.assert_not_called() @@ -893,7 +927,7 @@ class MarketTest(WebMockTestCase): with self.subTest(before=True, after=True): m.process(["sell_all"], before=True, after=True) - process.assert_called_once_with("sell_all", steps="all") + process.assert_called_once_with("sell_all", options={"foo": "bar"}, steps="all") store_report.assert_called_once() log_error.assert_not_called() @@ -976,7 +1010,7 @@ class ProcessorTest(WebMockTestCase): with self.subTest("nominal case"): processor = market.Processor(self.m) - processor.process("sell_all", foo="bar") + processor.process("sell_all", options="bar") self.assertEqual(3, process_step.call_count) steps = list(map(lambda x: x[1][1]["name"], process_step.mock_calls)) @@ -984,7 +1018,7 @@ class ProcessorTest(WebMockTestCase): kwargs = list(map(lambda x: x[1][2], process_step.mock_calls)) self.assertEqual(["all_sell", "wait", "all_buy"], steps) self.assertEqual(["sell_all", "sell_all", "sell_all"], scenario_names) - self.assertEqual([{"foo":"bar"}, {"foo":"bar"}, {"foo":"bar"}], kwargs) + self.assertEqual(["bar", "bar", "bar"], kwargs) process_step.reset_mock() @@ -999,7 +1033,7 @@ class ProcessorTest(WebMockTestCase): method, arguments = processor.method_arguments("wait_for_recent") self.assertEqual(market.Portfolio.wait_for_recent, method) - self.assertEqual(["delta", "poll"], arguments) + self.assertEqual(["delta"], arguments) method, arguments = processor.method_arguments("prepare_trades") self.assertEqual(m.prepare_trades, method)