aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_market.py34
-rw-r--r--tests/test_portfolio.py2
-rw-r--r--tests/test_store.py24
3 files changed, 43 insertions, 17 deletions
diff --git a/tests/test_market.py b/tests/test_market.py
index e6e6f36..9316480 100644
--- a/tests/test_market.py
+++ b/tests/test_market.py
@@ -1057,6 +1057,9 @@ class ProcessorTest(WebMockTestCase):
1057 method, arguments = processor.method_arguments("print_tickers") 1057 method, arguments = processor.method_arguments("print_tickers")
1058 self.assertEqual(m.print_tickers, method) 1058 self.assertEqual(m.print_tickers, method)
1059 1059
1060 method, arguments = processor.method_arguments("fetch_balances")
1061 self.assertEqual(m.balances.fetch_balances, method)
1062
1060 def test_process_step(self): 1063 def test_process_step(self):
1061 processor = market.Processor(self.m) 1064 processor = market.Processor(self.m)
1062 1065
@@ -1069,19 +1072,17 @@ class ProcessorTest(WebMockTestCase):
1069 mock.call("process_foo__2_sell_begin"), 1072 mock.call("process_foo__2_sell_begin"),
1070 mock.call("process_foo__2_sell_end"), 1073 mock.call("process_foo__2_sell_end"),
1071 ]) 1074 ])
1072 self.m.balances.fetch_balances.assert_has_calls([
1073 mock.call(tag="process_foo__2_sell_begin"),
1074 mock.call(tag="process_foo__2_sell_end"),
1075 ])
1076 1075
1077 self.assertEqual(5, run_action.call_count) 1076 self.assertEqual(7, run_action.call_count)
1078 1077
1079 run_action.assert_has_calls([ 1078 run_action.assert_has_calls([
1079 mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_begin'}),
1080 mock.call('prepare_trades', {}, {'foo': 'bar'}), 1080 mock.call('prepare_trades', {}, {'foo': 'bar'}),
1081 mock.call('prepare_orders', {'only': 'dispose', 'compute_value': 'average'}, {'foo': 'bar'}), 1081 mock.call('prepare_orders', {'only': 'dispose', 'compute_value': 'average'}, {'foo': 'bar'}),
1082 mock.call('run_orders', {}, {'foo': 'bar'}), 1082 mock.call('run_orders', {}, {'foo': 'bar'}),
1083 mock.call('follow_orders', {}, {'foo': 'bar'}), 1083 mock.call('follow_orders', {}, {'foo': 'bar'}),
1084 mock.call('close_trades', {}, {'foo': 'bar'}), 1084 mock.call('close_trades', {}, {'foo': 'bar'}),
1085 mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_end'}),
1085 ]) 1086 ])
1086 1087
1087 self.m.reset_mock() 1088 self.m.reset_mock()
@@ -1094,30 +1095,31 @@ class ProcessorTest(WebMockTestCase):
1094 mock.call("process_foo__0_print_balances_begin"), 1095 mock.call("process_foo__0_print_balances_begin"),
1095 mock.call("process_foo__0_print_balances_end"), 1096 mock.call("process_foo__0_print_balances_end"),
1096 ]) 1097 ])
1097 self.m.balances.fetch_balances.assert_has_calls([
1098 mock.call(add_portfolio=True, checkpoint='end',
1099 log_tickers=True,
1100 add_usdt=True,
1101 tag='process_foo__0_print_balances_begin')
1102 ])
1103 1098
1104 self.assertEqual(0, run_action.call_count) 1099 self.assertEqual(1, run_action.call_count)
1100 run_action.assert_has_calls([
1101 mock.call('fetch_balances',
1102 {'checkpoint': 'end', 'log_tickers': True, 'add_usdt': True, 'add_portfolio': True},
1103 {'foo': 'bar', 'tag': 'process_foo__0_print_balances_begin'}),
1104 ])
1105 1105
1106 self.m.reset_mock() 1106 self.m.reset_mock()
1107 with mock.patch.object(processor, "run_action") as run_action: 1107 with mock.patch.object(processor, "run_action") as run_action:
1108 step = processor.scenarios["sell_needed"][1] 1108 step = processor.scenarios["sell_needed"][1]
1109 1109
1110 processor.process_step("foo", step, {"foo":"bar"}) 1110 processor.process_step("foo", step, {"foo":"bar"})
1111 self.m.balances.fetch_balances.assert_not_called() 1111 self.assertEqual(1, run_action.call_count)
1112 1112
1113 self.m.reset_mock() 1113 self.m.reset_mock()
1114 with mock.patch.object(processor, "run_action") as run_action: 1114 with mock.patch.object(processor, "run_action") as run_action:
1115 step = processor.scenarios["print_balances"][0] 1115 step = processor.scenarios["print_balances"][0]
1116 1116
1117 processor.process_step("foo", step, {"foo":"bar"}) 1117 processor.process_step("foo", step, {"foo":"bar"})
1118 self.m.balances.fetch_balances.assert_called_once_with( 1118 run_action.assert_has_calls([
1119 add_portfolio=True, add_usdt=True, log_tickers=True, 1119 mock.call('fetch_balances',
1120 tag='process_foo__1_print_balances_begin') 1120 {'log_tickers': True, 'add_usdt': True, 'add_portfolio': True},
1121 {'foo': 'bar', 'tag': 'process_foo__1_print_balances_begin'}),
1122 ])
1121 1123
1122 def test_parse_args(self): 1124 def test_parse_args(self):
1123 processor = market.Processor(self.m) 1125 processor = market.Processor(self.m)
diff --git a/tests/test_portfolio.py b/tests/test_portfolio.py
index d4e5ab9..cad3095 100644
--- a/tests/test_portfolio.py
+++ b/tests/test_portfolio.py
@@ -1856,7 +1856,7 @@ class AmountTest(WebMockTestCase):
1856 with self.subTest(desc="no ticker for currency"): 1856 with self.subTest(desc="no ticker for currency"):
1857 self.m.get_ticker.return_value = None 1857 self.m.get_ticker.return_value = None
1858 1858
1859 self.assertRaises(Exception, amount.in_currency, "ETH", self.m) 1859 self.assertEqual(portfolio.Amount("ETH", 0), amount.in_currency("ETH", self.m))
1860 1860
1861 with self.subTest(desc="nominal case"): 1861 with self.subTest(desc="nominal case"):
1862 self.m.get_ticker.return_value = { 1862 self.m.get_ticker.return_value = {
diff --git a/tests/test_store.py b/tests/test_store.py
index 4ab9bdf..6f220c8 100644
--- a/tests/test_store.py
+++ b/tests/test_store.py
@@ -1379,11 +1379,19 @@ class PortfolioTest(WebMockTestCase):
1379 with self.subTest(worker=False): 1379 with self.subTest(worker=False):
1380 market.Portfolio.data = store.LockedVar(None) 1380 market.Portfolio.data = store.LockedVar(None)
1381 market.Portfolio.worker = mock.Mock() 1381 market.Portfolio.worker = mock.Mock()
1382 market.Portfolio.worker_started = True
1382 is_worker.return_value = False 1383 is_worker.return_value = False
1383 market.Portfolio.get_cryptoportfolio() 1384 market.Portfolio.get_cryptoportfolio()
1384 notify.assert_called_once_with() 1385 notify.assert_called_once_with()
1385 parse_cryptoportfolio.assert_not_called() 1386 parse_cryptoportfolio.assert_not_called()
1386 store_cryptoportfolio.assert_not_called() 1387 store_cryptoportfolio.assert_not_called()
1388 with self.subTest(worker_started=False):
1389 market.Portfolio.data = store.LockedVar(None)
1390 market.Portfolio.worker = mock.Mock()
1391 market.Portfolio.worker_started = False
1392 is_worker.return_value = False
1393 with self.assertRaises(Exception):
1394 market.Portfolio.get_cryptoportfolio()
1387 1395
1388 def test_parse_cryptoportfolio(self): 1396 def test_parse_cryptoportfolio(self):
1389 with self.subTest(description="Normal case"): 1397 with self.subTest(description="Normal case"):
@@ -1649,6 +1657,22 @@ class PortfolioTest(WebMockTestCase):
1649 store.Portfolio.worker.join() 1657 store.Portfolio.worker.join()
1650 self.assertFalse(store.Portfolio.worker.is_alive()) 1658 self.assertFalse(store.Portfolio.worker.is_alive())
1651 1659
1660 with self.subTest("overdue"),\
1661 mock.patch.object(store.Portfolio, "get_cryptoportfolio") as get,\
1662 mock.patch.object(store.Portfolio, "report") as report,\
1663 mock.patch.object(store.Portfolio, "next_wait_time") as wait,\
1664 mock.patch.object(store.time, "sleep") as sleep:
1665 wait.side_effect = Exception("Time over")
1666 store.Portfolio.start_worker()
1667
1668 store.Portfolio.worker_notify.set()
1669
1670 store.Portfolio.callback.wait()
1671
1672 report.print_log.assert_called_once_with("[Worker] Fetching cryptoportfolio")
1673 get.assert_called_once_with(refetch=True)
1674 self.assertFalse(store.Portfolio.worker.is_alive())
1675
1652 def test_notify_and_wait(self): 1676 def test_notify_and_wait(self):
1653 with mock.patch.object(store.Portfolio, "callback") as callback,\ 1677 with mock.patch.object(store.Portfolio, "callback") as callback,\
1654 mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: 1678 mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: