From bb127bc87c2b2880469bfab230415c85e589421a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 5 May 2018 14:41:03 +0200 Subject: Add checkpoints when fetching balance --- tests/test_market.py | 32 +++++++++++++++++++++++++------- tests/test_store.py | 10 +++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/test_market.py b/tests/test_market.py index 46fad53..37c009b 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),\ @@ -964,7 +964,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 +1002,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,6 +1029,24 @@ 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, + 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() diff --git a/tests/test_store.py b/tests/test_store.py index ee7e063..58e76e0 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -380,7 +380,7 @@ class BalanceStoreTest(WebMockTestCase): balance_store.fetch_balances(tag="foo") self.assertEqual(0, balance_store.all["ETC"].total) self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies())) - self.m.report.log_balances.assert_called_with(tag="foo") + self.m.report.log_balances.assert_called_with(tag="foo", checkpoint=None) with self.subTest(log_tickers=True),\ mock.patch.object(balance_store, "in_currency") as in_currency: @@ -388,7 +388,7 @@ class BalanceStoreTest(WebMockTestCase): balance_store.fetch_balances(log_tickers=True, ticker_currency="FOO", ticker_compute_value="compute", ticker_type="type") self.m.report.log_balances.assert_called_with(compute_value='compute', - tag=None, ticker_currency='FOO', tickers='tickers', + tag=None, checkpoint=None, ticker_currency='FOO', tickers='tickers', type='type') balance_store = market.BalanceStore(self.m) @@ -425,7 +425,7 @@ class BalanceStoreTest(WebMockTestCase): self.assertEqual(D("2.6"), amounts["BTC"].value) self.assertEqual(D("7.5"), amounts["XEM"].value) self.assertEqual(D("-1.0"), amounts["DASH"].value) - self.m.report.log_balances.assert_called_with(tag=None) + self.m.report.log_balances.assert_called_with(tag=None, checkpoint=None) self.m.report.log_dispatch.assert_called_once_with(portfolio.Amount("BTC", "11.1"), amounts, "medium", repartition_hash) @@ -617,12 +617,14 @@ class ReportStoreTest(WebMockTestCase): ]) add_log.assert_called_once_with({ 'type': 'balance', + 'checkpoint': None, 'balances': 'json', 'tag': 'tag' }) add_redis_status.assert_called_once_with({ 'type': 'balance', 'balances': 'json', + 'checkpoint': None, 'tag': 'tag' }) add_log.reset_mock() @@ -639,6 +641,7 @@ class ReportStoreTest(WebMockTestCase): type="total") add_log.assert_called_once_with({ 'type': 'balance', + 'checkpoint': None, 'balances': 'json', 'tag': 'tag', 'tickers': { @@ -658,6 +661,7 @@ class ReportStoreTest(WebMockTestCase): }) add_redis_status.assert_called_once_with({ 'type': 'balance', + 'checkpoint': None, 'balances': 'json', 'tag': 'tag', 'tickers': { -- cgit v1.2.3