From 8e648fd5b8d10c8f68b30ee0c30f02d5b60a1b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 27 Aug 2018 11:19:55 +0200 Subject: Use market options for fetch balances --- tests/test_market.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'tests') 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): method, arguments = processor.method_arguments("print_tickers") self.assertEqual(m.print_tickers, method) + method, arguments = processor.method_arguments("fetch_balances") + self.assertEqual(m.balances.fetch_balances, method) + def test_process_step(self): processor = market.Processor(self.m) @@ -1069,19 +1072,17 @@ class ProcessorTest(WebMockTestCase): 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__2_sell_begin"), - mock.call(tag="process_foo__2_sell_end"), - ]) - self.assertEqual(5, run_action.call_count) + self.assertEqual(7, run_action.call_count) run_action.assert_has_calls([ + mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_begin'}), mock.call('prepare_trades', {}, {'foo': 'bar'}), mock.call('prepare_orders', {'only': 'dispose', 'compute_value': 'average'}, {'foo': 'bar'}), mock.call('run_orders', {}, {'foo': 'bar'}), mock.call('follow_orders', {}, {'foo': 'bar'}), mock.call('close_trades', {}, {'foo': 'bar'}), + mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_end'}), ]) self.m.reset_mock() @@ -1094,30 +1095,31 @@ class ProcessorTest(WebMockTestCase): 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.assertEqual(1, run_action.call_count) + run_action.assert_has_calls([ + mock.call('fetch_balances', + {'checkpoint': 'end', 'log_tickers': True, 'add_usdt': True, 'add_portfolio': True}, + {'foo': 'bar', 'tag': 'process_foo__0_print_balances_begin'}), + ]) 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.assertEqual(1, run_action.call_count) 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') + run_action.assert_has_calls([ + mock.call('fetch_balances', + {'log_tickers': True, 'add_usdt': True, 'add_portfolio': True}, + {'foo': 'bar', 'tag': 'process_foo__1_print_balances_begin'}), + ]) def test_parse_args(self): processor = market.Processor(self.m) -- cgit v1.2.3 From 6746607a578eca3383ade7fe7a88c39612f4d6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 27 Aug 2018 11:21:18 +0200 Subject: Stop when portfolio worker is down and data is not fetched --- tests/test_store.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') 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): with self.subTest(worker=False): market.Portfolio.data = store.LockedVar(None) market.Portfolio.worker = mock.Mock() + market.Portfolio.worker_started = True is_worker.return_value = False market.Portfolio.get_cryptoportfolio() notify.assert_called_once_with() parse_cryptoportfolio.assert_not_called() store_cryptoportfolio.assert_not_called() + with self.subTest(worker_started=False): + market.Portfolio.data = store.LockedVar(None) + market.Portfolio.worker = mock.Mock() + market.Portfolio.worker_started = False + is_worker.return_value = False + with self.assertRaises(Exception): + market.Portfolio.get_cryptoportfolio() def test_parse_cryptoportfolio(self): with self.subTest(description="Normal case"): @@ -1649,6 +1657,22 @@ class PortfolioTest(WebMockTestCase): store.Portfolio.worker.join() self.assertFalse(store.Portfolio.worker.is_alive()) + with self.subTest("overdue"),\ + mock.patch.object(store.Portfolio, "get_cryptoportfolio") as get,\ + mock.patch.object(store.Portfolio, "report") as report,\ + mock.patch.object(store.Portfolio, "next_wait_time") as wait,\ + mock.patch.object(store.time, "sleep") as sleep: + wait.side_effect = Exception("Time over") + store.Portfolio.start_worker() + + store.Portfolio.worker_notify.set() + + store.Portfolio.callback.wait() + + report.print_log.assert_called_once_with("[Worker] Fetching cryptoportfolio") + get.assert_called_once_with(refetch=True) + self.assertFalse(store.Portfolio.worker.is_alive()) + def test_notify_and_wait(self): with mock.patch.object(store.Portfolio, "callback") as callback,\ mock.patch.object(store.Portfolio, "worker_notify") as worker_notify: -- cgit v1.2.3 From 512972fa1df14df4e208a1182096b1c51b5d38d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 26 Sep 2018 11:51:14 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20raise=20when=20some=20market=20is=20dis?= =?UTF-8?q?abled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_portfolio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') 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): with self.subTest(desc="no ticker for currency"): self.m.get_ticker.return_value = None - self.assertRaises(Exception, amount.in_currency, "ETH", self.m) + self.assertEqual(portfolio.Amount("ETH", 0), amount.in_currency("ETH", self.m)) with self.subTest(desc="nominal case"): self.m.get_ticker.return_value = { -- cgit v1.2.3