Python six.moves.http_client.SERVICE_UNAVAILABLE Examples
The following are 9
code examples of six.moves.http_client.SERVICE_UNAVAILABLE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.http_client
, or try the search function
.
Example #1
Source File: test__upload.py From google-resumable-media-python with Apache License 2.0 | 6 votes |
def test__process_response_bad_status(self): upload = _upload.UploadBase(SIMPLE_URL) _fix_up_virtual(upload) # Make sure **not finished** before. assert not upload.finished status_code = http_client.SERVICE_UNAVAILABLE response = _make_response(status_code=status_code) with pytest.raises(common.InvalidResponse) as exc_info: upload._process_response(response) error = exc_info.value assert error.response is response assert len(error.args) == 4 assert error.args[1] == status_code assert error.args[3] == http_client.OK # Make sure **finished** after (even in failure). assert upload.finished
Example #2
Source File: transfer_test.py From apitools with Apache License 2.0 | 6 votes |
def setUp(self): # Sample highly compressible data. self.sample_data = b'abc' * 200 # Stream of the sample data. self.sample_stream = six.BytesIO(self.sample_data) # Sample url_builder. self.url_builder = base_api._UrlBuilder('http://www.uploads.com') # Sample request. self.request = http_wrapper.Request( 'http://www.uploads.com', headers={'content-type': 'text/plain'}) # Sample successful response. self.response = http_wrapper.Response( info={'status': http_client.OK, 'location': 'http://www.uploads.com'}, content='', request_url='http://www.uploads.com',) # Sample failure response. self.fail_response = http_wrapper.Response( info={'status': http_client.SERVICE_UNAVAILABLE, 'location': 'http://www.uploads.com'}, content='', request_url='http://www.uploads.com',)
Example #3
Source File: swarm.py From deepWordBug with Apache License 2.0 | 5 votes |
def leave_swarm(self, force=False): """ Leave a swarm. Args: force (bool): Leave the swarm even if this node is a manager. Default: ``False`` Returns: ``True`` if the request went through. Raises: :py:class:`docker.errors.APIError` If the server returns an error. """ url = self._url('/swarm/leave') response = self._post(url, params={'force': force}) # Ignore "this node is not part of a swarm" error if force and response.status_code == http_client.NOT_ACCEPTABLE: return True # FIXME: Temporary workaround for 1.13.0-rc bug # https://github.com/docker/docker/issues/29192 if force and response.status_code == http_client.SERVICE_UNAVAILABLE: return True self._raise_for_status(response) return True
Example #4
Source File: test__helpers.py From google-resumable-media-python with Apache License 2.0 | 5 votes |
def test_success_with_retry(self, randint_mock, sleep_mock): randint_mock.side_effect = [125, 625, 375] status_codes = ( http_client.INTERNAL_SERVER_ERROR, http_client.BAD_GATEWAY, http_client.SERVICE_UNAVAILABLE, http_client.NOT_FOUND, ) responses = [_make_response(status_code) for status_code in status_codes] func = mock.Mock(side_effect=responses, spec=[]) retry_strategy = common.RetryStrategy() ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy) assert ret_val == responses[-1] assert status_codes[-1] not in _helpers.RETRYABLE assert func.call_count == 4 assert func.mock_calls == [mock.call()] * 4 assert randint_mock.call_count == 3 assert randint_mock.mock_calls == [mock.call(0, 1000)] * 3 assert sleep_mock.call_count == 3 sleep_mock.assert_any_call(1.125) sleep_mock.assert_any_call(2.625) sleep_mock.assert_any_call(4.375)
Example #5
Source File: test__helpers.py From google-resumable-media-python with Apache License 2.0 | 5 votes |
def test_retry_exceeds_max_cumulative(self, randint_mock, sleep_mock): randint_mock.side_effect = [875, 0, 375, 500, 500, 250, 125] status_codes = ( http_client.SERVICE_UNAVAILABLE, http_client.GATEWAY_TIMEOUT, common.TOO_MANY_REQUESTS, http_client.INTERNAL_SERVER_ERROR, http_client.SERVICE_UNAVAILABLE, http_client.BAD_GATEWAY, http_client.GATEWAY_TIMEOUT, common.TOO_MANY_REQUESTS, ) responses = [_make_response(status_code) for status_code in status_codes] func = mock.Mock(side_effect=responses, spec=[]) retry_strategy = common.RetryStrategy(max_cumulative_retry=100.0) ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy) assert ret_val == responses[-1] assert status_codes[-1] in _helpers.RETRYABLE assert func.call_count == 8 assert func.mock_calls == [mock.call()] * 8 assert randint_mock.call_count == 7 assert randint_mock.mock_calls == [mock.call(0, 1000)] * 7 assert sleep_mock.call_count == 7 sleep_mock.assert_any_call(1.875) sleep_mock.assert_any_call(2.0) sleep_mock.assert_any_call(4.375) sleep_mock.assert_any_call(8.5) sleep_mock.assert_any_call(16.5) sleep_mock.assert_any_call(32.25) sleep_mock.assert_any_call(64.125)
Example #6
Source File: test_blob.py From python-storage with Apache License 2.0 | 5 votes |
def test_create_resumable_upload_session_with_failure(self): from google.resumable_media import InvalidResponse from google.cloud import exceptions message = "5-oh-3 woe is me." response = self._mock_requests_response( status_code=http_client.SERVICE_UNAVAILABLE, headers={} ) side_effect = InvalidResponse(response, message) with self.assertRaises(exceptions.ServiceUnavailable) as exc_info: self._create_resumable_upload_session_helper(side_effect=side_effect) self.assertIn(message, exc_info.exception.message) self.assertEqual(exc_info.exception.errors, [])
Example #7
Source File: test_http_connect.py From impyla with Apache License 2.0 | 5 votes |
def test_http_interactions(self, http_503_server): """Test interactions with the http server when using hs2-http protocol. Check that there is an HttpError exception when the server returns a 503 error.""" con = connect("localhost", http_503_server.PORT, use_http_transport=True) try: con.cursor() assert False, "Should have got exception" except HttpError as e: assert str(e) == "HTTP code 503: Service Unavailable" assert e.code == http_client.SERVICE_UNAVAILABLE assert e.body.decode("utf-8") == "extra text"
Example #8
Source File: restclient_test.py From treadmill with Apache License 2.0 | 5 votes |
def test_retry_on_503(self, resp_mock): """Test retry for status code that should be retried (e.g. 503)""" resp_mock.return_value.status_code = http_client.SERVICE_UNAVAILABLE with self.assertRaises(restclient.MaxRequestRetriesError): restclient.get('http://foo.com', '/')
Example #9
Source File: test_http_connect.py From impyla with Apache License 2.0 | 4 votes |
def http_503_server(): class RequestHandler503(SimpleHTTPServer.SimpleHTTPRequestHandler): """A custom http handler that checks for duplicate 'Host' headers from the most recent http request, and always returns a 503 http code""" def do_POST(self): # Ensure that only one 'Host' header is contained in the request before responding. request_headers = None host_hdr_count = 0 if six.PY2: # The unfortunately named self.headers here is an instance of mimetools.Message that # contains the request headers. request_headers = self.headers.headers host_hdr_count = sum([header.startswith('Host:') for header in request_headers]) if six.PY3: # In Python3 self.Headers is an HTTPMessage. request_headers = self.headers host_hdr_count = sum([header[0] == 'Host' for header in request_headers.items()]) assert host_hdr_count == 1, "need single 'Host:' header in %s" % request_headers # Respond with 503. self.send_response(code=http_client.SERVICE_UNAVAILABLE, message="Service Unavailable") self.end_headers() self.wfile.write("extra text".encode('utf-8')) class TestHTTPServer503(object): def __init__(self): self.HOST = "localhost" self.PORT = get_unused_port() self.httpd = socketserver.TCPServer((self.HOST, self.PORT), RequestHandler503) self.http_server_thread = threading.Thread(target=self.httpd.serve_forever) self.http_server_thread.start() server = TestHTTPServer503() yield server # Cleanup after test. if server.httpd is not None: server.httpd.shutdown() if server.http_server_thread is not None: server.http_server_thread.join()