aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-24 16:07:11 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-24 16:07:11 +0100
commit45fffd4963005a1f3957868f9ddb1aa7ec66c0e3 (patch)
tree80b7ac28d5d2ed26a7c52ae02d3dc251396b92fb /test.py
parent472787b6360221588423d03fe3e73d92c09a7c9d (diff)
parent445b4a7712fb7fe45e17b6b76356dd3be42dd900 (diff)
downloadTrader-45fffd4963005a1f3957868f9ddb1aa7ec66c0e3.tar.gz
Trader-45fffd4963005a1f3957868f9ddb1aa7ec66c0e3.tar.zst
Trader-45fffd4963005a1f3957868f9ddb1aa7ec66c0e3.zip
Merge branch 'retry_timeout' into dev
Diffstat (limited to 'test.py')
-rw-r--r--test.py70
1 files changed, 64 insertions, 6 deletions
diff --git a/test.py b/test.py
index 637a305..18616c1 100644
--- a/test.py
+++ b/test.py
@@ -70,6 +70,18 @@ class poloniexETest(unittest.TestCase):
70 self.wm.stop() 70 self.wm.stop()
71 super(poloniexETest, self).tearDown() 71 super(poloniexETest, self).tearDown()
72 72
73 def test__init(self):
74 with mock.patch("market.ccxt.poloniexE.session") as session:
75 session.request.return_value = "response"
76 ccxt = market.ccxt.poloniexE()
77 ccxt._market = mock.Mock
78 ccxt._market.report = mock.Mock()
79
80 ccxt.session.request("GET", "URL", data="data",
81 headers="headers")
82 ccxt._market.report.log_http_request.assert_called_with('GET', 'URL', 'data',
83 'headers', 'response')
84
73 def test_nanoseconds(self): 85 def test_nanoseconds(self):
74 with mock.patch.object(market.ccxt.time, "time") as time: 86 with mock.patch.object(market.ccxt.time, "time") as time:
75 time.return_value = 123456.7890123456 87 time.return_value = 123456.7890123456
@@ -80,6 +92,58 @@ class poloniexETest(unittest.TestCase):
80 time.return_value = 123456.7890123456 92 time.return_value = 123456.7890123456
81 self.assertEqual(123456789012345, self.s.nonce()) 93 self.assertEqual(123456789012345, self.s.nonce())
82 94
95 def test_request(self):
96 with mock.patch.object(market.ccxt.poloniex, "request") as request,\
97 mock.patch("market.ccxt.retry_call") as retry_call:
98 with self.subTest(wrapped=True):
99 with self.subTest(desc="public"):
100 self.s.request("foo")
101 retry_call.assert_called_with(request,
102 delay=1, tries=10, fargs=["foo"],
103 fkwargs={'api': 'public', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
104 exceptions=(market.ccxt.RequestTimeout,))
105 request.assert_not_called()
106
107 with self.subTest(desc="private GET"):
108 self.s.request("foo", api="private")
109 retry_call.assert_called_with(request,
110 delay=1, tries=10, fargs=["foo"],
111 fkwargs={'api': 'private', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
112 exceptions=(market.ccxt.RequestTimeout,))
113 request.assert_not_called()
114
115 with self.subTest(desc="private POST regexp"):
116 self.s.request("returnFoo", api="private", method="POST")
117 retry_call.assert_called_with(request,
118 delay=1, tries=10, fargs=["returnFoo"],
119 fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
120 exceptions=(market.ccxt.RequestTimeout,))
121 request.assert_not_called()
122
123 with self.subTest(desc="private POST non-regexp"):
124 self.s.request("getMarginPosition", api="private", method="POST")
125 retry_call.assert_called_with(request,
126 delay=1, tries=10, fargs=["getMarginPosition"],
127 fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
128 exceptions=(market.ccxt.RequestTimeout,))
129 request.assert_not_called()
130 retry_call.reset_mock()
131 request.reset_mock()
132 with self.subTest(wrapped=False):
133 with self.subTest(desc="private POST non-matching regexp"):
134 self.s.request("marginBuy", api="private", method="POST")
135 request.assert_called_with("marginBuy",
136 api="private", method="POST", params={},
137 headers=None, body=None)
138 retry_call.assert_not_called()
139
140 with self.subTest(desc="private POST non-matching non-regexp"):
141 self.s.request("closeMarginPositionOther", api="private", method="POST")
142 request.assert_called_with("closeMarginPositionOther",
143 api="private", method="POST", params={},
144 headers=None, body=None)
145 retry_call.assert_not_called()
146
83 def test_order_precision(self): 147 def test_order_precision(self):
84 self.assertEqual(8, self.s.order_precision("FOO")) 148 self.assertEqual(8, self.s.order_precision("FOO"))
85 149
@@ -1125,17 +1189,11 @@ class MarketTest(WebMockTestCase):
1125 def test_from_config(self, ccxt): 1189 def test_from_config(self, ccxt):
1126 with mock.patch("market.ReportStore"): 1190 with mock.patch("market.ReportStore"):
1127 ccxt.poloniexE.return_value = self.ccxt 1191 ccxt.poloniexE.return_value = self.ccxt
1128 self.ccxt.session.request.return_value = "response"
1129 1192
1130 m = market.Market.from_config({"key": "key", "secred": "secret"}, self.market_args()) 1193 m = market.Market.from_config({"key": "key", "secred": "secret"}, self.market_args())
1131 1194
1132 self.assertEqual(self.ccxt, m.ccxt) 1195 self.assertEqual(self.ccxt, m.ccxt)
1133 1196
1134 self.ccxt.session.request("GET", "URL", data="data",
1135 headers="headers")
1136 m.report.log_http_request.assert_called_with('GET', 'URL', 'data',
1137 'headers', 'response')
1138
1139 m = market.Market.from_config({"key": "key", "secred": "secret"}, self.market_args(debug=True)) 1197 m = market.Market.from_config({"key": "key", "secred": "secret"}, self.market_args(debug=True))
1140 self.assertEqual(True, m.debug) 1198 self.assertEqual(True, m.debug)
1141 1199