From d8e233ac11edac1481f0315e25f79b0390c45e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 4 Apr 2018 12:02:50 +0200 Subject: Log http requests exceptions --- test.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test.py') diff --git a/test.py b/test.py index 29403d4..bf679bf 100644 --- a/test.py +++ b/test.py @@ -71,7 +71,8 @@ class poloniexETest(unittest.TestCase): super().tearDown() def test__init(self): - with mock.patch("market.ccxt.poloniexE.session") as session: + with self.subTest("Nominal case"), \ + mock.patch("market.ccxt.poloniexE.session") as session: session.request.return_value = "response" ccxt = market.ccxt.poloniexE() ccxt._market = mock.Mock @@ -82,6 +83,21 @@ class poloniexETest(unittest.TestCase): ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data', 'headers', 'response') + with self.subTest("Raising"),\ + mock.patch("market.ccxt.poloniexE.session") as session: + session.request.side_effect = market.ccxt.RequestException("Boo") + + ccxt = market.ccxt.poloniexE() + ccxt._market = mock.Mock + ccxt._market.report = mock.Mock() + + with self.assertRaises(market.ccxt.RequestException, msg="Boo") as cm: + ccxt.session.request("GET", "URL", data="data", + headers="headers") + ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data', + 'headers', cm.exception) + + def test_nanoseconds(self): with mock.patch.object(market.ccxt.time, "time") as time: time.return_value = 123456.7890123456 @@ -4349,6 +4365,21 @@ class ReportStoreTest(WebMockTestCase): 'response': 'Hey' }) + add_log.reset_mock() + report_store.log_http_request("method", "url", "body", + "headers", ValueError("Foo")) + add_log.assert_called_once_with({ + 'type': 'http_request', + 'method': 'method', + 'url': 'url', + 'body': 'body', + 'headers': 'headers', + 'status': -1, + 'response': None, + 'error': 'ValueError', + 'error_message': 'Foo', + }) + @mock.patch.object(market.ReportStore, "add_log") def test_log_market(self, add_log): report_store = market.ReportStore(self.m) -- cgit v1.2.3