def test_parse_target_exchange_parses_schemes_and_returns_correctly( self, url, expected_target): req = BitexRequest(url=url) # Assert the target exchange is parsed on __init__() assert req.exchange == expected_target # Assert the method itself returns correctly and the previously checked # attribute was not a default value. assert req.parse_target_exchange() == expected_target
def test_prepare_uses_custom_class_if_available(self, mock_prep_prepare): request = BitexRequest(url="test:instrument/ticker") custom_class = MagicMock(name="PseudoCustomClass") custom_class.return_value = custom_class assert request.exchange == "test" with patch.dict("bitex.request.PLUGINS", {"test": { "PreparedRequest": custom_class }}): assert request.prepare() == custom_class assert not mock_prep_prepare.called assert custom_class.called custom_class.assert_called_once_with("test")
def request( self, method, url, private=False, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None, ) -> BitexResponse: """Construct a :class:`BitexRequest`, prepare and send it. `url` may either be a URL starting with http/https, or a :mod:`bitex-framework` short-hand url in the format of `<exchange>:<instrument>/<data>/<action>`. """ # Create the Request. req = BitexRequest( method=method.upper(), url=url, headers=headers, files=files, data=data or {}, json=json, params=params or {}, auth=auth, cookies=cookies, hooks=hooks, private=private, ) prep = self.prepare_request(req) proxies = proxies or {} settings = self.merge_environment_settings(prep.url, proxies, stream, verify, cert) # Send the request. send_kwargs = {"timeout": timeout, "allow_redirects": allow_redirects} send_kwargs.update(settings) resp = self.send(prep, **send_kwargs) return resp
def test_prepare_defaults_to_bitex_prepared_request_if_no_custom_class_is_available( self, _): request = BitexRequest(url="test:instrument/endpoint") assert isinstance(request.prepare(), BitexPreparedRequest)