diff options
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -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 |
@@ -4349,6 +4365,21 @@ class ReportStoreTest(WebMockTestCase): | |||
4349 | 'response': 'Hey' | 4365 | 'response': 'Hey' |
4350 | }) | 4366 | }) |
4351 | 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 | |||
4352 | @mock.patch.object(market.ReportStore, "add_log") | 4383 | @mock.patch.object(market.ReportStore, "add_log") |
4353 | def test_log_market(self, add_log): | 4384 | def test_log_market(self, add_log): |
4354 | report_store = market.ReportStore(self.m) | 4385 | report_store = market.ReportStore(self.m) |