diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-05-08 21:00:27 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-05-08 21:00:27 +0200 |
commit | 5321200c05b3b693581ec4238c74eb02e0b715d7 (patch) | |
tree | 893f0bd619deba53cd92895c97bd13e0a600feb9 | |
parent | 3a15ffc79ea84e5ec6200545bcbf11fc6c1c6564 (diff) | |
download | Trader-5321200c05b3b693581ec4238c74eb02e0b715d7.tar.gz Trader-5321200c05b3b693581ec4238c74eb02e0b715d7.tar.zst Trader-5321200c05b3b693581ec4238c74eb02e0b715d7.zip |
Check before processing that credentials are valid
-rw-r--r-- | market.py | 5 | ||||
-rw-r--r-- | tests/test_market.py | 11 |
2 files changed, 15 insertions, 1 deletions
@@ -1,4 +1,4 @@ | |||
1 | from ccxt import ExchangeError, NotSupported, RequestTimeout, InvalidNonce | 1 | from ccxt import AuthenticationError, ExchangeError, NotSupported, RequestTimeout, InvalidNonce |
2 | import ccxt_wrapper as ccxt | 2 | import ccxt_wrapper as ccxt |
3 | import time | 3 | import time |
4 | import dbs | 4 | import dbs |
@@ -88,6 +88,7 @@ class Market: | |||
88 | 88 | ||
89 | def process(self, actions, before=False, after=False): | 89 | def process(self, actions, before=False, after=False): |
90 | try: | 90 | try: |
91 | self.ccxt.check_required_credentials() | ||
91 | for action in actions: | 92 | for action in actions: |
92 | if bool(before) is bool(after): | 93 | if bool(before) is bool(after): |
93 | self.processor.process(action, steps="all") | 94 | self.processor.process(action, steps="all") |
@@ -95,6 +96,8 @@ class Market: | |||
95 | self.processor.process(action, steps="before") | 96 | self.processor.process(action, steps="before") |
96 | elif after: | 97 | elif after: |
97 | self.processor.process(action, steps="after") | 98 | self.processor.process(action, steps="after") |
99 | except AuthenticationError: | ||
100 | self.report.log_error("market_authentication", message="Impossible to authenticate to market") | ||
98 | except Exception as e: | 101 | except Exception as e: |
99 | import traceback | 102 | import traceback |
100 | self.report.log_error("market_process", exception=e, message=traceback.format_exc()) | 103 | self.report.log_error("market_process", exception=e, message=traceback.format_exc()) |
diff --git a/tests/test_market.py b/tests/test_market.py index 2c92655..c89025b 100644 --- a/tests/test_market.py +++ b/tests/test_market.py | |||
@@ -890,6 +890,17 @@ class MarketTest(WebMockTestCase): | |||
890 | process.reset_mock() | 890 | process.reset_mock() |
891 | log_error.reset_mock() | 891 | log_error.reset_mock() |
892 | store_report.reset_mock() | 892 | store_report.reset_mock() |
893 | with self.subTest(authentication_error=True): | ||
894 | m.ccxt.check_required_credentials.side_effect = market.ccxt.AuthenticationError | ||
895 | |||
896 | m.process(["some_action"], before=True) | ||
897 | log_error.assert_called_with("market_authentication", message="Impossible to authenticate to market") | ||
898 | store_report.assert_called_once() | ||
899 | |||
900 | m.ccxt.check_required_credentials.side_effect = True | ||
901 | process.reset_mock() | ||
902 | log_error.reset_mock() | ||
903 | store_report.reset_mock() | ||
893 | with self.subTest(unhandled_exception=True): | 904 | with self.subTest(unhandled_exception=True): |
894 | process.side_effect = Exception("bouh") | 905 | process.side_effect = Exception("bouh") |
895 | 906 | ||