aboutsummaryrefslogtreecommitdiff
path: root/tests/test_store.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_store.py')
-rw-r--r--tests/test_store.py133
1 files changed, 89 insertions, 44 deletions
diff --git a/tests/test_store.py b/tests/test_store.py
index df113b7..12999d3 100644
--- a/tests/test_store.py
+++ b/tests/test_store.py
@@ -369,17 +369,27 @@ class BalanceStoreTest(WebMockTestCase):
369 369
370 balance_store = market.BalanceStore(self.m) 370 balance_store = market.BalanceStore(self.m)
371 371
372 balance_store.fetch_balances() 372 with self.subTest(log_tickers=False):
373 self.assertNotIn("ETC", balance_store.currencies()) 373 balance_store.fetch_balances()
374 self.assertListEqual(["USDT", "XVG", "XMR"], list(balance_store.currencies())) 374 self.assertNotIn("ETC", balance_store.currencies())
375 375 self.assertListEqual(["USDT", "XVG", "XMR"], list(balance_store.currencies()))
376 balance_store.all["ETC"] = portfolio.Balance("ETC", { 376
377 "exchange_total": "1", "exchange_free": "0", 377 balance_store.all["ETC"] = portfolio.Balance("ETC", {
378 "exchange_used": "1" }) 378 "exchange_total": "1", "exchange_free": "0",
379 balance_store.fetch_balances(tag="foo") 379 "exchange_used": "1" })
380 self.assertEqual(0, balance_store.all["ETC"].total) 380 balance_store.fetch_balances(tag="foo")
381 self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies())) 381 self.assertEqual(0, balance_store.all["ETC"].total)
382 self.m.report.log_balances.assert_called_with(tag="foo") 382 self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies()))
383 self.m.report.log_balances.assert_called_with(tag="foo")
384
385 with self.subTest(log_tickers=True),\
386 mock.patch.object(balance_store, "in_currency") as in_currency:
387 in_currency.return_value = "tickers"
388 balance_store.fetch_balances(log_tickers=True, ticker_currency="FOO",
389 ticker_compute_value="compute", ticker_type="type")
390 self.m.report.log_balances.assert_called_with(compute_value='compute',
391 tag=None, ticker_currency='FOO', tickers='tickers',
392 type='type')
383 393
384 @mock.patch.object(market.Portfolio, "repartition") 394 @mock.patch.object(market.Portfolio, "repartition")
385 def test_dispatch_assets(self, repartition): 395 def test_dispatch_assets(self, repartition):
@@ -586,27 +596,77 @@ class ReportStoreTest(WebMockTestCase):
586 self.m.balances.as_json.return_value = "json" 596 self.m.balances.as_json.return_value = "json"
587 self.m.balances.all = { "FOO": "bar", "BAR": "baz" } 597 self.m.balances.all = { "FOO": "bar", "BAR": "baz" }
588 598
589 report_store.log_balances(tag="tag") 599 with self.subTest(tickers=None):
590 print_log.assert_has_calls([ 600 report_store.log_balances(tag="tag")
591 mock.call("[Balance]"), 601 print_log.assert_has_calls([
592 mock.call("\tbar"), 602 mock.call("[Balance]"),
593 mock.call("\tbaz"), 603 mock.call("\tbar"),
594 ]) 604 mock.call("\tbaz"),
595 add_log.assert_called_once_with({ 605 ])
596 'type': 'balance', 606 add_log.assert_called_once_with({
597 'balances': 'json', 607 'type': 'balance',
598 'tag': 'tag' 608 'balances': 'json',
599 }) 609 'tag': 'tag'
600 add_redis_status.assert_called_once_with({ 610 })
601 'type': 'balance', 611 add_redis_status.assert_called_once_with({
602 'balances': 'json', 612 'type': 'balance',
603 'tag': 'tag' 613 'balances': 'json',
604 }) 614 'tag': 'tag'
615 })
616 add_log.reset_mock()
617 add_redis_status.reset_mock()
618 with self.subTest(tickers="present"):
619 amounts = {
620 "BTC": portfolio.Amount("BTC", 10),
621 "ETH": portfolio.Amount("BTC", D("0.3"))
622 }
623 amounts["ETH"].rate = D("0.1")
624
625 report_store.log_balances(tag="tag", tickers=amounts,
626 ticker_currency="BTC", compute_value="default",
627 type="total")
628 add_log.assert_called_once_with({
629 'type': 'balance',
630 'balances': 'json',
631 'tag': 'tag',
632 'tickers': {
633 'compute_value': 'default',
634 'balance_type': 'total',
635 'currency': 'BTC',
636 'balances': {
637 'BTC': D('10'),
638 'ETH': D('0.3')
639 },
640 'rates': {
641 'BTC': None,
642 'ETH': D('0.1')
643 },
644 'total': D('10.3')
645 },
646 })
647 add_redis_status.assert_called_once_with({
648 'type': 'balance',
649 'balances': 'json',
650 'tag': 'tag',
651 'tickers': {
652 'compute_value': 'default',
653 'balance_type': 'total',
654 'currency': 'BTC',
655 'balances': {
656 'BTC': D('10'),
657 'ETH': D('0.3')
658 },
659 'rates': {
660 'BTC': None,
661 'ETH': D('0.1')
662 },
663 'total': D('10.3')
664 },
665 })
605 666
606 @mock.patch.object(market.ReportStore, "print_log") 667 @mock.patch.object(market.ReportStore, "print_log")
607 @mock.patch.object(market.ReportStore, "add_log") 668 @mock.patch.object(market.ReportStore, "add_log")
608 @mock.patch.object(market.ReportStore, "add_redis_status") 669 def test_log_tickers(self, add_log, print_log):
609 def test_log_tickers(self, add_redis_status, add_log, print_log):
610 report_store = market.ReportStore(self.m) 670 report_store = market.ReportStore(self.m)
611 amounts = { 671 amounts = {
612 "BTC": portfolio.Amount("BTC", 10), 672 "BTC": portfolio.Amount("BTC", 10),
@@ -631,21 +691,6 @@ class ReportStoreTest(WebMockTestCase):
631 }, 691 },
632 'total': D('10.3') 692 'total': D('10.3')
633 }) 693 })
634 add_redis_status.assert_called_once_with({
635 'type': 'tickers',
636 'compute_value': 'default',
637 'balance_type': 'total',
638 'currency': 'BTC',
639 'balances': {
640 'BTC': D('10'),
641 'ETH': D('0.3')
642 },
643 'rates': {
644 'BTC': None,
645 'ETH': D('0.1')
646 },
647 'total': D('10.3')
648 })
649 694
650 add_log.reset_mock() 695 add_log.reset_mock()
651 compute_value = lambda x: x["bid"] 696 compute_value = lambda x: x["bid"]