balance_store = market.BalanceStore(self.m)
- balance_store.fetch_balances()
- self.assertNotIn("ETC", balance_store.currencies())
- self.assertListEqual(["USDT", "XVG", "XMR"], list(balance_store.currencies()))
-
- balance_store.all["ETC"] = portfolio.Balance("ETC", {
- "exchange_total": "1", "exchange_free": "0",
- "exchange_used": "1" })
- 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")
+ with self.subTest(log_tickers=False):
+ balance_store.fetch_balances()
+ self.assertNotIn("ETC", balance_store.currencies())
+ self.assertListEqual(["USDT", "XVG", "XMR"], list(balance_store.currencies()))
+
+ balance_store.all["ETC"] = portfolio.Balance("ETC", {
+ "exchange_total": "1", "exchange_free": "0",
+ "exchange_used": "1" })
+ 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")
+
+ with self.subTest(log_tickers=True),\
+ mock.patch.object(balance_store, "in_currency") as in_currency:
+ in_currency.return_value = "tickers"
+ 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',
+ type='type')
@mock.patch.object(market.Portfolio, "repartition")
def test_dispatch_assets(self, repartition):
self.assertEqual({"foo": "bar", "date": mock.ANY, "user_id": None, "market_id": None}, result)
+ def test_add_redis_status(self):
+ report_store = market.ReportStore(self.m)
+ result = report_store.add_redis_status({"foo": "bar"})
+
+ self.assertEqual({"foo": "bar"}, result)
+ self.assertEqual(result, report_store.redis_status[0])
+
def test_set_verbose(self):
report_store = market.ReportStore(self.m)
with self.subTest(verbose=True):
self.assertEqual(("date1", "type1", '{\n "foo": "bar",\n "bla": "bla"\n}'), logs[0])
self.assertEqual(("date2", "type2", '{\n "foo": "bar",\n "bla": "bla"\n}'), logs[1])
+ def test_to_json_redis(self):
+ report_store = market.ReportStore(self.m)
+ report_store.redis_status.append({
+ "type": "type1", "foo": "bar", "bla": "bla"
+ })
+ report_store.redis_status.append({
+ "type": "type2", "foo": "bar", "bla": "bla"
+ })
+ logs = list(report_store.to_json_redis())
+
+ self.assertEqual(2, len(logs))
+ self.assertEqual(("type1", '{"foo": "bar", "bla": "bla"}'), logs[0])
+ self.assertEqual(("type2", '{"foo": "bar", "bla": "bla"}'), logs[1])
+
@mock.patch.object(market.ReportStore, "print_log")
@mock.patch.object(market.ReportStore, "add_log")
def test_log_stage(self, add_log, print_log):
@mock.patch.object(market.ReportStore, "print_log")
@mock.patch.object(market.ReportStore, "add_log")
- def test_log_balances(self, add_log, print_log):
+ @mock.patch.object(market.ReportStore, "add_redis_status")
+ def test_log_balances(self, add_redis_status, add_log, print_log):
report_store = market.ReportStore(self.m)
self.m.balances.as_json.return_value = "json"
self.m.balances.all = { "FOO": "bar", "BAR": "baz" }
- report_store.log_balances(tag="tag")
- print_log.assert_has_calls([
- mock.call("[Balance]"),
- mock.call("\tbar"),
- mock.call("\tbaz"),
- ])
- add_log.assert_called_once_with({
- 'type': 'balance',
- 'balances': 'json',
- 'tag': 'tag'
- })
+ with self.subTest(tickers=None):
+ report_store.log_balances(tag="tag")
+ print_log.assert_has_calls([
+ mock.call("[Balance]"),
+ mock.call("\tbar"),
+ mock.call("\tbaz"),
+ ])
+ add_log.assert_called_once_with({
+ 'type': 'balance',
+ 'balances': 'json',
+ 'tag': 'tag'
+ })
+ add_redis_status.assert_called_once_with({
+ 'type': 'balance',
+ 'balances': 'json',
+ 'tag': 'tag'
+ })
+ add_log.reset_mock()
+ add_redis_status.reset_mock()
+ with self.subTest(tickers="present"):
+ amounts = {
+ "BTC": portfolio.Amount("BTC", 10),
+ "ETH": portfolio.Amount("BTC", D("0.3"))
+ }
+ amounts["ETH"].rate = D("0.1")
+
+ report_store.log_balances(tag="tag", tickers=amounts,
+ ticker_currency="BTC", compute_value="default",
+ type="total")
+ add_log.assert_called_once_with({
+ 'type': 'balance',
+ 'balances': 'json',
+ 'tag': 'tag',
+ 'tickers': {
+ 'compute_value': 'default',
+ 'balance_type': 'total',
+ 'currency': 'BTC',
+ 'balances': {
+ 'BTC': D('10'),
+ 'ETH': D('0.3')
+ },
+ 'rates': {
+ 'BTC': None,
+ 'ETH': D('0.1')
+ },
+ 'total': D('10.3')
+ },
+ })
+ add_redis_status.assert_called_once_with({
+ 'type': 'balance',
+ 'balances': 'json',
+ 'tag': 'tag',
+ 'tickers': {
+ 'compute_value': 'default',
+ 'balance_type': 'total',
+ 'currency': 'BTC',
+ 'balances': {
+ 'BTC': D('10'),
+ 'ETH': D('0.3')
+ },
+ 'rates': {
+ 'BTC': None,
+ 'ETH': D('0.1')
+ },
+ 'total': D('10.3')
+ },
+ })
@mock.patch.object(market.ReportStore, "print_log")
@mock.patch.object(market.ReportStore, "add_log")