def test_get_sleeps_correctly_on_403(self): _request_and_assert( lambda: requests_with_backoff.get( 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg'), call('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg'), 403)
def test_get_does_not_sleep_on_404(self, mock_sleep, mock_request): not_found_response = requests.Response() not_found_response.status_code = 404 mock_request.return_value = not_found_response with assert_raises(requests.HTTPError) as e: requests_with_backoff.get('http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg') assert_equal(e.exception.response.status_code, 404) assert_equal([], mock_sleep.call_args_list) mock_request.assert_called_with('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg')
def test_get_sleeps_correctly_on_403(self): _request_and_assert( lambda: requests_with_backoff.get('http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg'), call('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg'), 403)
def _make_request(self, path, url_params=None): if url_params is None: url_params = {} response = requests_with_backoff.get(url=self.API_LOCATION + path, auth=(self.user, self.password), headers={"App-Key": self.app_key}, params=url_params) response.raise_for_status() return response.json()
def _make_request(self, path, url_params={}): response = requests_with_backoff.get( url=self.API_LOCATION + path, auth=(self.user, self.password), headers={ "App-Key": self.app_key }, params=url_params ) return response
def test_get_raises_error_after_5_retries(self, mock_sleep, mock_request): service_unavailable_response = requests.Response() service_unavailable_response.status_code = 503 mock_request.return_value = service_unavailable_response with assert_raises(requests.HTTPError) as e: requests_with_backoff.get('http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg') assert_equal(e.exception.response.status_code, 503) assert_equal( [call(10), call(20), call(40), call(80), call(160)], mock_sleep.call_args_list) mock_request.assert_called_with('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg')
def _make_request(self, start_at_for_webtrends, end_at_for_webtrends): return requests_with_backoff.get( url="{base_url}{report_id}".format( base_url=self.base_url, report_id=self.report_id), auth=(self.user, self.password), params={ 'start_period': start_at_for_webtrends, 'end_period': end_at_for_webtrends, 'format': self.query_format } )
def _make_request(self, start_at_for_webtrends, end_at_for_webtrends): return requests_with_backoff.get( url="{base_url}".format( base_url=self.base_url), auth=(self.user, self.password), params={ 'start_period': start_at_for_webtrends, 'end_period': end_at_for_webtrends, 'format': self.query_format, "userealtime": True } )
def test_get_proxies_requests_get(self, mock_request): good_response = _make_good_response() mock_request.return_value = good_response response = requests_with_backoff.get('http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg') assert_is(response, good_response) mock_request.assert_called_with('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg')
def test_get_does_not_sleep_on_404(self, mock_sleep, mock_request): not_found_response = requests.Response() not_found_response.status_code = 404 mock_request.return_value = not_found_response with assert_raises(requests.HTTPError) as e: requests_with_backoff.get('http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg') assert_equal(e.exception.response.status_code, 404) assert_equal( [], mock_sleep.call_args_list) mock_request.assert_called_with('GET', 'http://fake.com', kwarg1='a kwarg', kwarg2='another kwarg')
def _make_request(self, path, url_params=None): if url_params is None: url_params = {} response = requests_with_backoff.get( url=self.API_LOCATION + path, auth=(self.user, self.password), headers={ "App-Key": self.app_key }, params=url_params ) response.raise_for_status() return response.json()
def _send_authenticated_pingdom_request(path, user, password, app_key, url_params): response = requests_with_backoff.get( url="https://api.pingdom.com/api/2.0/" + path, auth=(user, password), headers={ 'App-key': app_key }, params=url_params ) response.raise_for_status() return response.json()
def _make_request(self): return requests_with_backoff.get( url="{url}?module=API".format(url=self.url), params=self._request_params() )
def _make_request(self): return requests_with_backoff.get( url="{url}?module=API".format(url=self.url), params=self._request_params())