def test_no_retry_if_not_500_to_599_http_code(self): default_host = Defaults.get_rest_host(Options()) ably = AblyRest(token="foo") self.assertIn('http_max_retry_count', ably.http.CONNECTION_RETRY_DEFAULTS) default_url = "%s://%s:%d/" % ( ably.http.preferred_scheme, default_host, ably.http.preferred_port) def raise_ably_exception(*args, **kwagrs): raise AblyException(message="", status_code=600, code=50500) with mock.patch('requests.Request', wraps=requests.Request) as request_mock: with mock.patch('ably.util.exceptions.AblyException.raise_for_response', side_effect=raise_ably_exception) as send_mock: with self.assertRaises(AblyException): ably.http.make_request('GET', '/', skip_auth=True) self.assertEqual(send_mock.call_count, 1) self.assertEqual( request_mock.call_args, mock.call(mock.ANY, default_url, data=mock.ANY, headers=mock.ANY))
def test_no_retry_if_not_500_to_599_http_code(self): default_host = Defaults.get_rest_host(Options()) ably = AblyRest(token="foo") self.assertIn('http_max_retry_count', ably.http.CONNECTION_RETRY_DEFAULTS) default_url = "%s://%s:%d/" % (ably.http.preferred_scheme, default_host, ably.http.preferred_port) def raise_ably_exception(*args, **kwagrs): raise AblyException(message="", status_code=600, code=50500) with mock.patch('requests.Request', wraps=requests.Request) as request_mock: with mock.patch( 'ably.util.exceptions.AblyException.raise_for_response', side_effect=raise_ably_exception) as send_mock: with self.assertRaises(AblyException): ably.http.make_request('GET', '/', skip_auth=True) self.assertEqual(send_mock.call_count, 1) self.assertEqual( request_mock.call_args, mock.call(mock.ANY, default_url, data=mock.ANY, headers=mock.ANY))
def preferred_host(self): return Defaults.get_rest_host(self.options)