X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ftest_market.py;h=c89025be021383625a810a5eb8e33efb82bed6dd;hb=e24df7cffc01937a211db2d29f44bccc3d740bd5;hp=ab3cd5e0aebe83cbacacb822d29b439564ff70d1;hpb=30700830b6c0aaaa59c148ebd8edb6931040ed13;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/tests/test_market.py b/tests/test_market.py index ab3cd5e..c89025b 100644 --- a/tests/test_market.py +++ b/tests/test_market.py @@ -174,7 +174,7 @@ class MarketTest(WebMockTestCase): base_currency='BTC', compute_value='average', available_balance_only=False, liquidity='medium', only=None, repartition=None) - m.report.log_balances.assert_called_once_with(tag="tag") + m.report.log_balances.assert_called_once_with(tag="tag", checkpoint=None) compute_trades.reset_mock() with self.subTest(available_balance_only=True),\ @@ -381,12 +381,16 @@ class MarketTest(WebMockTestCase): order_mock2.trade = trade_mock trade_mock.tick_actions_recreate.return_value = "tick1" + new_order_mock = mock.Mock() + trade_mock.prepare_order.return_value = new_order_mock 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, new_order=new_order_mock) + new_order_mock.run.assert_called_once_with() @mock.patch.object(market.BalanceStore, "fetch_balances") def test_move_balance(self, fetch_balances): @@ -883,6 +887,17 @@ class MarketTest(WebMockTestCase): store_report.assert_called_once() log_error.assert_not_called() + process.reset_mock() + log_error.reset_mock() + store_report.reset_mock() + with self.subTest(authentication_error=True): + m.ccxt.check_required_credentials.side_effect = market.ccxt.AuthenticationError + + m.process(["some_action"], before=True) + log_error.assert_called_with("market_authentication", message="Impossible to authenticate to market") + store_report.assert_called_once() + + m.ccxt.check_required_credentials.side_effect = True process.reset_mock() log_error.reset_mock() store_report.reset_mock() @@ -890,7 +905,7 @@ class MarketTest(WebMockTestCase): process.side_effect = Exception("bouh") m.process(["some_action"], before=True) - log_error.assert_called_with("market_process", exception=mock.ANY) + log_error.assert_called_with("market_process", exception=mock.ANY, message=mock.ANY) store_report.assert_called_once() @@ -964,7 +979,7 @@ class ProcessorTest(WebMockTestCase): process_step.reset_mock() processor.process("sell_needed", steps=["before", "after"]) - self.assertEqual(3, process_step.call_count) + self.assertEqual(4, process_step.call_count) def test_method_arguments(self): ccxt = mock.Mock(spec=market.ccxt.poloniexE) @@ -1002,17 +1017,17 @@ class ProcessorTest(WebMockTestCase): processor = market.Processor(self.m) with mock.patch.object(processor, "run_action") as run_action: - step = processor.scenarios["sell_needed"][1] + step = processor.scenarios["sell_needed"][2] processor.process_step("foo", step, {"foo":"bar"}) self.m.report.log_stage.assert_has_calls([ - mock.call("process_foo__1_sell_begin"), - mock.call("process_foo__1_sell_end"), + mock.call("process_foo__2_sell_begin"), + mock.call("process_foo__2_sell_end"), ]) self.m.balances.fetch_balances.assert_has_calls([ - mock.call(tag="process_foo__1_sell_begin", log_tickers=True), - mock.call(tag="process_foo__1_sell_end", log_tickers=True), + mock.call(tag="process_foo__2_sell_begin"), + mock.call(tag="process_foo__2_sell_end"), ]) self.assertEqual(5, run_action.call_count) @@ -1029,9 +1044,37 @@ class ProcessorTest(WebMockTestCase): with mock.patch.object(processor, "run_action") as run_action: step = processor.scenarios["sell_needed"][0] + processor.process_step("foo", step, {"foo":"bar"}) + + self.m.report.log_stage.assert_has_calls([ + mock.call("process_foo__0_print_balances_begin"), + mock.call("process_foo__0_print_balances_end"), + ]) + self.m.balances.fetch_balances.assert_has_calls([ + mock.call(add_portfolio=True, checkpoint='end', + log_tickers=True, + add_usdt=True, + tag='process_foo__0_print_balances_begin') + ]) + + self.assertEqual(0, run_action.call_count) + + self.m.reset_mock() + with mock.patch.object(processor, "run_action") as run_action: + step = processor.scenarios["sell_needed"][1] + processor.process_step("foo", step, {"foo":"bar"}) self.m.balances.fetch_balances.assert_not_called() + self.m.reset_mock() + with mock.patch.object(processor, "run_action") as run_action: + step = processor.scenarios["print_balances"][0] + + processor.process_step("foo", step, {"foo":"bar"}) + self.m.balances.fetch_balances.assert_called_once_with( + add_portfolio=True, add_usdt=True, log_tickers=True, + tag='process_foo__1_print_balances_begin') + def test_parse_args(self): processor = market.Processor(self.m)