import threading
import market, portfolio, store
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class NoopLockTest(unittest.TestCase):
def test_with(self):
noop_lock = store.NoopLock()
with noop_lock:
self.assertTrue(True)
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class LockedVarTest(unittest.TestCase):
def test_values(self):
thread3.join()
self.assertEqual("Bar", locked_var.get()[0:3])
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class TradeStoreTest(WebMockTestCase):
def test_compute_trades(self):
self.m.balances.currencies.return_value = ["XMR", "DASH", "XVG", "BTC", "ETH"]
self.assertEqual([trade_mock1, trade_mock2], trade_store.pending)
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class BalanceStoreTest(WebMockTestCase):
def setUp(self):
super().setUp()
self.assertEqual(1, as_json["BTC"])
self.assertEqual(2, as_json["ETH"])
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class ReportStoreTest(WebMockTestCase):
def test_add_log(self):
with self.subTest(market=self.m):
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" }
'balances': 'json',
'tag': 'tag'
})
+ add_redis_status.assert_called_once_with({
+ 'type': 'balance',
+ 'balances': 'json',
+ 'tag': 'tag'
+ })
@mock.patch.object(market.ReportStore, "print_log")
@mock.patch.object(market.ReportStore, "add_log")
- def test_log_tickers(self, add_log, print_log):
+ @mock.patch.object(market.ReportStore, "add_redis_status")
+ def test_log_tickers(self, add_redis_status, add_log, print_log):
report_store = market.ReportStore(self.m)
amounts = {
"BTC": portfolio.Amount("BTC", 10),
},
'total': D('10.3')
})
+ add_redis_status.assert_called_once_with({
+ 'type': '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_log.reset_mock()
compute_value = lambda x: x["bid"]
response = mock.Mock()
response.status_code = 200
response.text = "Hey"
+ response.elapsed.total_seconds.return_value = 120
report_store.log_http_request("method", "url", "body",
"headers", response)
'body': 'body',
'headers': 'headers',
'status': 200,
+ 'duration': 120,
'response': 'Hey',
'response_same_as': None,
})
'action': 'Hey'
})
+@unittest.skipUnless("unit" in limits, "Unit skipped")
class PortfolioTest(WebMockTestCase):
def setUp(self):
super().setUp()