aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/test.py b/test.py
index a9a80c5..bf679bf 100644
--- a/test.py
+++ b/test.py
@@ -71,7 +71,8 @@ class poloniexETest(unittest.TestCase):
71 super().tearDown() 71 super().tearDown()
72 72
73 def test__init(self): 73 def test__init(self):
74 with mock.patch("market.ccxt.poloniexE.session") as session: 74 with self.subTest("Nominal case"), \
75 mock.patch("market.ccxt.poloniexE.session") as session:
75 session.request.return_value = "response" 76 session.request.return_value = "response"
76 ccxt = market.ccxt.poloniexE() 77 ccxt = market.ccxt.poloniexE()
77 ccxt._market = mock.Mock 78 ccxt._market = mock.Mock
@@ -82,6 +83,21 @@ class poloniexETest(unittest.TestCase):
82 ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data', 83 ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data',
83 'headers', 'response') 84 'headers', 'response')
84 85
86 with self.subTest("Raising"),\
87 mock.patch("market.ccxt.poloniexE.session") as session:
88 session.request.side_effect = market.ccxt.RequestException("Boo")
89
90 ccxt = market.ccxt.poloniexE()
91 ccxt._market = mock.Mock
92 ccxt._market.report = mock.Mock()
93
94 with self.assertRaises(market.ccxt.RequestException, msg="Boo") as cm:
95 ccxt.session.request("GET", "URL", data="data",
96 headers="headers")
97 ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data',
98 'headers', cm.exception)
99
100
85 def test_nanoseconds(self): 101 def test_nanoseconds(self):
86 with mock.patch.object(market.ccxt.time, "time") as time: 102 with mock.patch.object(market.ccxt.time, "time") as time:
87 time.return_value = 123456.7890123456 103 time.return_value = 123456.7890123456
@@ -1181,9 +1197,12 @@ class MarketTest(WebMockTestCase):
1181 with self.subTest(quiet=False): 1197 with self.subTest(quiet=False):
1182 m = market.Market(self.ccxt, self.market_args(quiet=False)) 1198 m = market.Market(self.ccxt, self.market_args(quiet=False))
1183 report_store.assert_called_with(m, verbose_print=True) 1199 report_store.assert_called_with(m, verbose_print=True)
1200 report_store().log_market.assert_called_once()
1201 report_store.reset_mock()
1184 with self.subTest(quiet=True): 1202 with self.subTest(quiet=True):
1185 m = market.Market(self.ccxt, self.market_args(quiet=True)) 1203 m = market.Market(self.ccxt, self.market_args(quiet=True))
1186 report_store.assert_called_with(m, verbose_print=False) 1204 report_store.assert_called_with(m, verbose_print=False)
1205 report_store().log_market.assert_called_once()
1187 1206
1188 @mock.patch("market.ccxt") 1207 @mock.patch("market.ccxt")
1189 def test_from_config(self, ccxt): 1208 def test_from_config(self, ccxt):
@@ -4346,6 +4365,40 @@ class ReportStoreTest(WebMockTestCase):
4346 'response': 'Hey' 4365 'response': 'Hey'
4347 }) 4366 })
4348 4367
4368 add_log.reset_mock()
4369 report_store.log_http_request("method", "url", "body",
4370 "headers", ValueError("Foo"))
4371 add_log.assert_called_once_with({
4372 'type': 'http_request',
4373 'method': 'method',
4374 'url': 'url',
4375 'body': 'body',
4376 'headers': 'headers',
4377 'status': -1,
4378 'response': None,
4379 'error': 'ValueError',
4380 'error_message': 'Foo',
4381 })
4382
4383 @mock.patch.object(market.ReportStore, "add_log")
4384 def test_log_market(self, add_log):
4385 report_store = market.ReportStore(self.m)
4386 class Args:
4387 def __init__(self):
4388 self.debug = True
4389 self.quiet = False
4390
4391 report_store.log_market(Args(), 4, 1, "report", True)
4392 add_log.assert_called_once_with({
4393 "type": "market",
4394 "commit": "$Format:%H$",
4395 "args": { "debug": True, "quiet": False },
4396 "user_id": 4,
4397 "market_id": 1,
4398 "report_path": "report",
4399 "debug": True
4400 })
4401
4349 @mock.patch.object(market.ReportStore, "print_log") 4402 @mock.patch.object(market.ReportStore, "print_log")
4350 @mock.patch.object(market.ReportStore, "add_log") 4403 @mock.patch.object(market.ReportStore, "add_log")
4351 def test_log_error(self, add_log, print_log): 4404 def test_log_error(self, add_log, print_log):