aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-05 14:41:03 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-05 14:41:03 +0200
commitbb127bc87c2b2880469bfab230415c85e589421a (patch)
tree90cce895ea70aa3127fe764ac4da7e1d510b1589 /tests
parent56c3a6078a2740d43072dfe30f07b17b442e3cc2 (diff)
downloadTrader-bb127bc87c2b2880469bfab230415c85e589421a.tar.gz
Trader-bb127bc87c2b2880469bfab230415c85e589421a.tar.zst
Trader-bb127bc87c2b2880469bfab230415c85e589421a.zip
Add checkpoints when fetching balance
Diffstat (limited to 'tests')
-rw-r--r--tests/test_market.py32
-rw-r--r--tests/test_store.py10
2 files changed, 32 insertions, 10 deletions
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):
174 base_currency='BTC', compute_value='average', 174 base_currency='BTC', compute_value='average',
175 available_balance_only=False, liquidity='medium', 175 available_balance_only=False, liquidity='medium',
176 only=None, repartition=None) 176 only=None, repartition=None)
177 m.report.log_balances.assert_called_once_with(tag="tag") 177 m.report.log_balances.assert_called_once_with(tag="tag", checkpoint=None)
178 178
179 compute_trades.reset_mock() 179 compute_trades.reset_mock()
180 with self.subTest(available_balance_only=True),\ 180 with self.subTest(available_balance_only=True),\
@@ -964,7 +964,7 @@ class ProcessorTest(WebMockTestCase):
964 process_step.reset_mock() 964 process_step.reset_mock()
965 965
966 processor.process("sell_needed", steps=["before", "after"]) 966 processor.process("sell_needed", steps=["before", "after"])
967 self.assertEqual(3, process_step.call_count) 967 self.assertEqual(4, process_step.call_count)
968 968
969 def test_method_arguments(self): 969 def test_method_arguments(self):
970 ccxt = mock.Mock(spec=market.ccxt.poloniexE) 970 ccxt = mock.Mock(spec=market.ccxt.poloniexE)
@@ -1002,17 +1002,17 @@ class ProcessorTest(WebMockTestCase):
1002 processor = market.Processor(self.m) 1002 processor = market.Processor(self.m)
1003 1003
1004 with mock.patch.object(processor, "run_action") as run_action: 1004 with mock.patch.object(processor, "run_action") as run_action:
1005 step = processor.scenarios["sell_needed"][1] 1005 step = processor.scenarios["sell_needed"][2]
1006 1006
1007 processor.process_step("foo", step, {"foo":"bar"}) 1007 processor.process_step("foo", step, {"foo":"bar"})
1008 1008
1009 self.m.report.log_stage.assert_has_calls([ 1009 self.m.report.log_stage.assert_has_calls([
1010 mock.call("process_foo__1_sell_begin"), 1010 mock.call("process_foo__2_sell_begin"),
1011 mock.call("process_foo__1_sell_end"), 1011 mock.call("process_foo__2_sell_end"),
1012 ]) 1012 ])
1013 self.m.balances.fetch_balances.assert_has_calls([ 1013 self.m.balances.fetch_balances.assert_has_calls([
1014 mock.call(tag="process_foo__1_sell_begin", log_tickers=True), 1014 mock.call(tag="process_foo__2_sell_begin"),
1015 mock.call(tag="process_foo__1_sell_end", log_tickers=True), 1015 mock.call(tag="process_foo__2_sell_end"),
1016 ]) 1016 ])
1017 1017
1018 self.assertEqual(5, run_action.call_count) 1018 self.assertEqual(5, run_action.call_count)
@@ -1030,6 +1030,24 @@ class ProcessorTest(WebMockTestCase):
1030 step = processor.scenarios["sell_needed"][0] 1030 step = processor.scenarios["sell_needed"][0]
1031 1031
1032 processor.process_step("foo", step, {"foo":"bar"}) 1032 processor.process_step("foo", step, {"foo":"bar"})
1033
1034 self.m.report.log_stage.assert_has_calls([
1035 mock.call("process_foo__0_print_balances_begin"),
1036 mock.call("process_foo__0_print_balances_end"),
1037 ])
1038 self.m.balances.fetch_balances.assert_has_calls([
1039 mock.call(add_portfolio=True, checkpoint='end',
1040 log_tickers=True,
1041 tag='process_foo__0_print_balances_begin')
1042 ])
1043
1044 self.assertEqual(0, run_action.call_count)
1045
1046 self.m.reset_mock()
1047 with mock.patch.object(processor, "run_action") as run_action:
1048 step = processor.scenarios["sell_needed"][1]
1049
1050 processor.process_step("foo", step, {"foo":"bar"})
1033 self.m.balances.fetch_balances.assert_not_called() 1051 self.m.balances.fetch_balances.assert_not_called()
1034 1052
1035 self.m.reset_mock() 1053 self.m.reset_mock()
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):
380 balance_store.fetch_balances(tag="foo") 380 balance_store.fetch_balances(tag="foo")
381 self.assertEqual(0, balance_store.all["ETC"].total) 381 self.assertEqual(0, balance_store.all["ETC"].total)
382 self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies())) 382 self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies()))
383 self.m.report.log_balances.assert_called_with(tag="foo") 383 self.m.report.log_balances.assert_called_with(tag="foo", checkpoint=None)
384 384
385 with self.subTest(log_tickers=True),\ 385 with self.subTest(log_tickers=True),\
386 mock.patch.object(balance_store, "in_currency") as in_currency: 386 mock.patch.object(balance_store, "in_currency") as in_currency:
@@ -388,7 +388,7 @@ class BalanceStoreTest(WebMockTestCase):
388 balance_store.fetch_balances(log_tickers=True, ticker_currency="FOO", 388 balance_store.fetch_balances(log_tickers=True, ticker_currency="FOO",
389 ticker_compute_value="compute", ticker_type="type") 389 ticker_compute_value="compute", ticker_type="type")
390 self.m.report.log_balances.assert_called_with(compute_value='compute', 390 self.m.report.log_balances.assert_called_with(compute_value='compute',
391 tag=None, ticker_currency='FOO', tickers='tickers', 391 tag=None, checkpoint=None, ticker_currency='FOO', tickers='tickers',
392 type='type') 392 type='type')
393 393
394 balance_store = market.BalanceStore(self.m) 394 balance_store = market.BalanceStore(self.m)
@@ -425,7 +425,7 @@ class BalanceStoreTest(WebMockTestCase):
425 self.assertEqual(D("2.6"), amounts["BTC"].value) 425 self.assertEqual(D("2.6"), amounts["BTC"].value)
426 self.assertEqual(D("7.5"), amounts["XEM"].value) 426 self.assertEqual(D("7.5"), amounts["XEM"].value)
427 self.assertEqual(D("-1.0"), amounts["DASH"].value) 427 self.assertEqual(D("-1.0"), amounts["DASH"].value)
428 self.m.report.log_balances.assert_called_with(tag=None) 428 self.m.report.log_balances.assert_called_with(tag=None, checkpoint=None)
429 self.m.report.log_dispatch.assert_called_once_with(portfolio.Amount("BTC", 429 self.m.report.log_dispatch.assert_called_once_with(portfolio.Amount("BTC",
430 "11.1"), amounts, "medium", repartition_hash) 430 "11.1"), amounts, "medium", repartition_hash)
431 431
@@ -617,12 +617,14 @@ class ReportStoreTest(WebMockTestCase):
617 ]) 617 ])
618 add_log.assert_called_once_with({ 618 add_log.assert_called_once_with({
619 'type': 'balance', 619 'type': 'balance',
620 'checkpoint': None,
620 'balances': 'json', 621 'balances': 'json',
621 'tag': 'tag' 622 'tag': 'tag'
622 }) 623 })
623 add_redis_status.assert_called_once_with({ 624 add_redis_status.assert_called_once_with({
624 'type': 'balance', 625 'type': 'balance',
625 'balances': 'json', 626 'balances': 'json',
627 'checkpoint': None,
626 'tag': 'tag' 628 'tag': 'tag'
627 }) 629 })
628 add_log.reset_mock() 630 add_log.reset_mock()
@@ -639,6 +641,7 @@ class ReportStoreTest(WebMockTestCase):
639 type="total") 641 type="total")
640 add_log.assert_called_once_with({ 642 add_log.assert_called_once_with({
641 'type': 'balance', 643 'type': 'balance',
644 'checkpoint': None,
642 'balances': 'json', 645 'balances': 'json',
643 'tag': 'tag', 646 'tag': 'tag',
644 'tickers': { 647 'tickers': {
@@ -658,6 +661,7 @@ class ReportStoreTest(WebMockTestCase):
658 }) 661 })
659 add_redis_status.assert_called_once_with({ 662 add_redis_status.assert_called_once_with({
660 'type': 'balance', 663 'type': 'balance',
664 'checkpoint': None,
661 'balances': 'json', 665 'balances': 'json',
662 'tag': 'tag', 666 'tag': 'tag',
663 'tickers': { 667 'tickers': {