X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=test.py;h=bf679bfc8c2879f507bdfee64b57c09705619845;hb=3b60291066e5442ce2980a6c40ea10542f24a910;hp=a9a80c5714cda8e68312194e4e88a5dc50dd2f19;hpb=341a4b07e8c205711fff0e93dd3679708828a961;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git 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): 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 @@ -1181,9 +1197,12 @@ class MarketTest(WebMockTestCase): with self.subTest(quiet=False): m = market.Market(self.ccxt, self.market_args(quiet=False)) report_store.assert_called_with(m, verbose_print=True) + report_store().log_market.assert_called_once() + report_store.reset_mock() with self.subTest(quiet=True): m = market.Market(self.ccxt, self.market_args(quiet=True)) report_store.assert_called_with(m, verbose_print=False) + report_store().log_market.assert_called_once() @mock.patch("market.ccxt") def test_from_config(self, ccxt): @@ -4346,6 +4365,40 @@ 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) + class Args: + def __init__(self): + self.debug = True + self.quiet = False + + report_store.log_market(Args(), 4, 1, "report", True) + add_log.assert_called_once_with({ + "type": "market", + "commit": "$Format:%H$", + "args": { "debug": True, "quiet": False }, + "user_id": 4, + "market_id": 1, + "report_path": "report", + "debug": True + }) + @mock.patch.object(market.ReportStore, "print_log") @mock.patch.object(market.ReportStore, "add_log") def test_log_error(self, add_log, print_log):