+ def test_request(self):
+ with mock.patch.object(market.ccxt.poloniex, "request") as request,\
+ mock.patch("market.ccxt.retry_call") as retry_call:
+ with self.subTest(wrapped=True):
+ with self.subTest(desc="public"):
+ self.s.request("foo")
+ retry_call.assert_called_with(request,
+ delay=1, tries=10, fargs=["foo"],
+ fkwargs={'api': 'public', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
+ exceptions=(market.ccxt.RequestTimeout,))
+ request.assert_not_called()
+
+ with self.subTest(desc="private GET"):
+ self.s.request("foo", api="private")
+ retry_call.assert_called_with(request,
+ delay=1, tries=10, fargs=["foo"],
+ fkwargs={'api': 'private', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
+ exceptions=(market.ccxt.RequestTimeout,))
+ request.assert_not_called()
+
+ with self.subTest(desc="private POST regexp"):
+ self.s.request("returnFoo", api="private", method="POST")
+ retry_call.assert_called_with(request,
+ delay=1, tries=10, fargs=["returnFoo"],
+ fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
+ exceptions=(market.ccxt.RequestTimeout,))
+ request.assert_not_called()
+
+ with self.subTest(desc="private POST non-regexp"):
+ self.s.request("getMarginPosition", api="private", method="POST")
+ retry_call.assert_called_with(request,
+ delay=1, tries=10, fargs=["getMarginPosition"],
+ fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
+ exceptions=(market.ccxt.RequestTimeout,))
+ request.assert_not_called()
+ retry_call.reset_mock()
+ request.reset_mock()
+ with self.subTest(wrapped=False):
+ with self.subTest(desc="private POST non-matching regexp"):
+ self.s.request("marginBuy", api="private", method="POST")
+ request.assert_called_with("marginBuy",
+ api="private", method="POST", params={},
+ headers=None, body=None)
+ retry_call.assert_not_called()
+
+ with self.subTest(desc="private POST non-matching non-regexp"):
+ self.s.request("closeMarginPositionOther", api="private", method="POST")
+ request.assert_called_with("closeMarginPositionOther",
+ api="private", method="POST", params={},
+ headers=None, body=None)
+ retry_call.assert_not_called()
+