Python six.moves.http_client.INTERNAL_SERVER_ERROR Examples
The following are 30
code examples of six.moves.http_client.INTERNAL_SERVER_ERROR().
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_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def test_empty_reply(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) def f(status=None, description=None): inject = dict(reply=suds.byte_str(), status=status, description=description) return client.service.f(__inject=inject) status, reason = f() assert status == http_client.OK assert reason is None status, reason = f(http_client.OK) assert status == http_client.OK assert reason is None status, reason = f(http_client.INTERNAL_SERVER_ERROR) assert status == http_client.INTERNAL_SERVER_ERROR assert reason == "injected reply" status, reason = f(http_client.FORBIDDEN) assert status == http_client.FORBIDDEN assert reason == "injected reply" status, reason = f(http_client.FORBIDDEN, "kwack") assert status == http_client.FORBIDDEN assert reason == "kwack"
Example #2
Source File: fault.py From karbor with Apache License 2.0 | 6 votes |
def _error(self, inner, req): LOG.error('Middleware error occurred: %s', inner.message) safe = getattr(inner, 'safe', False) headers = getattr(inner, 'headers', None) status = getattr(inner, 'code', http_client.INTERNAL_SERVER_ERROR) if status is None: status = http_client.INTERNAL_SERVER_ERROR msg_dict = dict(url=req.url, status=status) LOG.info("%(url)s returned with HTTP %(status)d", msg_dict) outer = self.status_to_type(status) if headers: outer.headers = headers if safe: msg = (inner.msg if isinstance(inner, exception.KarborException) else six.text_type(inner)) outer.explanation = msg return wsgi.Fault(outer)
Example #3
Source File: job.py From python-bigquery with Apache License 2.0 | 6 votes |
def _error_result_to_exception(error_result): """Maps BigQuery error reasons to an exception. The reasons and their matching HTTP status codes are documented on the `troubleshooting errors`_ page. .. _troubleshooting errors: https://cloud.google.com/bigquery\ /troubleshooting-errors Args: error_result (Mapping[str, str]): The error result from BigQuery. Returns: google.cloud.exceptions.GoogleCloudError: The mapped exception. """ reason = error_result.get("reason") status_code = _ERROR_REASON_TO_EXCEPTION.get( reason, http_client.INTERNAL_SERVER_ERROR ) return exceptions.from_http_status( status_code, error_result.get("message", ""), errors=[error_result] )
Example #4
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def test_reply_error_without_detail_with_fault(monkeypatch): monkeypatch.delitem(locals(), "e", False) client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True) for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR): inject = dict(reply=_fault_reply__without_detail, status=http_status) e = pytest.raises(suds.WebFault, client.service.f, __inject=inject) try: e = e.value _test_fault(e.fault, False) assert e.document.__class__ is suds.sax.document.Document assert str(e) == "Server raised fault: 'Dummy error.'" finally: del e # explicitly break circular reference chain in Python 3 inject = dict(reply=_fault_reply__with_detail, status=http_client.BAD_REQUEST, description="quack-quack") e = pytest.raises(Exception, client.service.f, __inject=inject).value try: assert e.__class__ is Exception assert e.args[0][0] == http_client.BAD_REQUEST assert e.args[0][1] == "quack-quack" finally: del e # explicitly break circular reference chain in Python 3
Example #5
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def test_reply_error_with_detail_without_fault(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR): status, fault = client.service.f(__inject=dict( reply=_fault_reply__with_detail, status=http_status)) assert status == http_client.INTERNAL_SERVER_ERROR _test_fault(fault, True) status, fault = client.service.f(__inject=dict( reply=_fault_reply__with_detail, status=http_client.BAD_REQUEST)) assert status == http_client.BAD_REQUEST assert fault == "injected reply" status, fault = client.service.f(__inject=dict( reply=_fault_reply__with_detail, status=http_client.BAD_REQUEST, description="haleluja")) assert status == http_client.BAD_REQUEST assert fault == "haleluja"
Example #6
Source File: restclient_test.py From treadmill with Apache License 2.0 | 5 votes |
def test_get_bad_json(self, resp_mock): """Test treadmill.restclient.get bad JSON""" resp_mock.return_value.status_code = http_client.INTERNAL_SERVER_ERROR resp_mock.return_value.text = '{"bad json"' resp_mock.return_value.json.side_effect = sjs.JSONDecodeError( 'Foo', '{"bad json"', 1 ) self.assertRaises( restclient.MaxRequestRetriesError, restclient.get, 'http://foo.com', '/', retries=1)
Example #7
Source File: inquiries.py From st2 with Apache License 2.0 | 5 votes |
def get_one(self, inquiry_id, requester_user=None): """Retrieve a single Inquiry Handles requests: GET /inquiries/<inquiry id> """ # Retrieve the inquiry by id. # (Passing permission_type here leverages inquiry service built-in RBAC assertions) try: inquiry = self._get_one_by_id( id=inquiry_id, requester_user=requester_user, permission_type=rbac_types.PermissionType.INQUIRY_VIEW ) except db_exceptions.StackStormDBObjectNotFoundError as e: LOG.exception('Unable to identify inquiry with id "%s".' % inquiry_id) api_router.abort(http_client.NOT_FOUND, six.text_type(e)) except rbac_exceptions.ResourceAccessDeniedError as e: LOG.exception('User is denied access to inquiry "%s".' % inquiry_id) api_router.abort(http_client.FORBIDDEN, six.text_type(e)) except Exception as e: LOG.exception('Unable to get record for inquiry "%s".' % inquiry_id) api_router.abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) try: inquiry_service.check_inquiry(inquiry) except Exception as e: api_router.abort(http_client.BAD_REQUEST, six.text_type(e)) return inqy_api_models.InquiryResponseAPI.from_inquiry_api(inquiry)
Example #8
Source File: restclient_test.py From treadmill with Apache License 2.0 | 5 votes |
def test_retry(self, resp_mock): """Tests retry logic.""" resp_mock.return_value.status_code = http_client.INTERNAL_SERVER_ERROR with self.assertRaises(restclient.MaxRequestRetriesError) as cm: restclient.get( ['http://foo.com', 'http://bar.com'], '/baz', retries=3 ) err = cm.exception self.assertEqual(len(err.attempts), 6) # Requests are done in order, by because other methods are being # called, to make test simpler, any_order is set to True so that # test will pass. requests.get.assert_has_calls([ mock.call('http://foo.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(.5, 10), stream=None, verify=True, allow_redirects=True), mock.call('http://bar.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(.5, 10), stream=None, verify=True, allow_redirects=True), mock.call('http://foo.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(1.5, 10), stream=None, verify=True, allow_redirects=True), mock.call('http://bar.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(1.5, 10), stream=None, verify=True, allow_redirects=True), mock.call('http://foo.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(2.5, 10), stream=None, verify=True, allow_redirects=True), mock.call('http://bar.com/baz', json=None, proxies=None, headers=None, auth=mock.ANY, timeout=(2.5, 10), stream=None, verify=True, allow_redirects=True), ], any_order=True) self.assertEqual(requests.get.call_count, 6)
Example #9
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_ACCEPTED_and_NO_CONTENT_status_reported_as_None_with_faults(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True) def f(reply, status): inject = {"reply": suds.byte_str(reply), "status": status} return client.service.f(__inject=inject) assert f("", None) is None pytest.raises(Exception, f, "", http_client.INTERNAL_SERVER_ERROR) assert f("", http_client.ACCEPTED) is None assert f("", http_client.NO_CONTENT) is None assert f("bla-bla", http_client.ACCEPTED) is None assert f("bla-bla", http_client.NO_CONTENT) is None
Example #10
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_ACCEPTED_and_NO_CONTENT_status_reported_as_None_without_faults(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) def f(reply, status): inject = {"reply": suds.byte_str(reply), "status": status} return client.service.f(__inject=inject) assert f("", None) is not None assert f("", http_client.INTERNAL_SERVER_ERROR) is not None assert f("", http_client.ACCEPTED) is None assert f("", http_client.NO_CONTENT) is None assert f("bla-bla", http_client.ACCEPTED) is None assert f("bla-bla", http_client.NO_CONTENT) is None
Example #11
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_fault_reply_with_unicode_faultstring(monkeypatch): monkeypatch.delitem(locals(), "e", False) unicode_string = u("\u20AC Jurko Gospodneti\u0107 " "\u010C\u0106\u017D\u0160\u0110" "\u010D\u0107\u017E\u0161\u0111") fault_xml = suds.byte_str(u("""\ <?xml version="1.0"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <env:Fault> <faultcode>env:Client</faultcode> <faultstring>%s</faultstring> </env:Fault> </env:Body> </env:Envelope> """) % (unicode_string,)) client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True) inject = dict(reply=fault_xml, status=http_client.INTERNAL_SERVER_ERROR) e = pytest.raises(suds.WebFault, client.service.f, __inject=inject).value try: assert e.fault.faultstring == unicode_string assert e.document.__class__ is suds.sax.document.Document finally: del e # explicitly break circular reference chain in Python 3 client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) status, fault = client.service.f(__inject=dict(reply=fault_xml, status=http_client.INTERNAL_SERVER_ERROR)) assert status == http_client.INTERNAL_SERVER_ERROR assert fault.faultstring == unicode_string
Example #12
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_invalid_fault_namespace(monkeypatch): monkeypatch.delitem(locals(), "e", False) fault_xml = suds.byte_str("""\ <?xml version="1.0"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p="x"> <env:Body> <p:Fault> <faultcode>env:Client</faultcode> <faultstring>Dummy error.</faultstring> <detail> <errorcode>ultimate</errorcode> </detail> </p:Fault> </env:Body> </env:Envelope> """) client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) inject = dict(reply=fault_xml, status=http_client.OK) e = pytest.raises(Exception, client.service.f, __inject=inject).value try: assert e.__class__ is Exception assert str(e) == "<faultcode/> not mapped to message part" finally: del e # explicitly break circular reference chain in Python 3 for http_status in (http_client.INTERNAL_SERVER_ERROR, http_client.PAYMENT_REQUIRED): status, reason = client.service.f(__inject=dict(reply=fault_xml, status=http_status, description="trla baba lan")) assert status == http_status assert reason == "trla baba lan"
Example #13
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_reply_error_without_detail_without_fault(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False) for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR): status, fault = client.service.f(__inject=dict( reply=_fault_reply__without_detail, status=http_status)) assert status == http_client.INTERNAL_SERVER_ERROR _test_fault(fault, False) status, fault = client.service.f(__inject=dict( reply=_fault_reply__without_detail, status=http_client.BAD_REQUEST, description="kung-fu-fui")) assert status == http_client.BAD_REQUEST assert fault == "kung-fu-fui"
Example #14
Source File: test_exception.py From karbor with Apache License 2.0 | 5 votes |
def test_error_msg_exception_with_kwargs(self): # NOTE(dprince): disable format errors for this test self.flags(fatal_exception_format_errors=False) class FakeKarborException(exception.KarborException): message = "default message: %(misspelled_code)s" exc = FakeKarborException(code=http_client.INTERNAL_SERVER_ERROR) self.assertEqual('default message: %(misspelled_code)s', six.text_type(exc))
Example #15
Source File: test_exception.py From karbor with Apache License 2.0 | 5 votes |
def test_error_code_from_kwarg(self): class FakeKarborException(exception.KarborException): code = http_client.INTERNAL_SERVER_ERROR exc = FakeKarborException(code=http_client.NOT_FOUND) self.assertEqual(http_client.NOT_FOUND, exc.kwargs['code'])
Example #16
Source File: test_exception.py From karbor with Apache License 2.0 | 5 votes |
def test_default_args(self): exc = exception.ConvertedException() self.assertNotEqual('', exc.title) self.assertEqual(http_client.INTERNAL_SERVER_ERROR, exc.code) self.assertEqual('', exc.explanation)
Example #17
Source File: test_lock_resources.py From rotest with MIT License | 5 votes |
def test_invalid_input(self): """Assert invalid request.""" # empty data response, _ = self.requester(json_data={}) self.assertEqual(response.status_code, http_client.INTERNAL_SERVER_ERROR)
Example #18
Source File: test_lock_resources.py From rotest with MIT License | 5 votes |
def test_invalid_content_type(self): """Assert invalid request content type.""" # invalid content type response, _ = self.requester(content_type="text/html") self.assertEqual(response.status_code, http_client.INTERNAL_SERVER_ERROR)
Example #19
Source File: test_exception.py From masakari with Apache License 2.0 | 5 votes |
def test_instantiate_without_title_known_code(self): exc = exception.ConvertedException(int(http.INTERNAL_SERVER_ERROR)) self.assertEqual(exc.title, status_reasons[http.INTERNAL_SERVER_ERROR])
Example #20
Source File: compliance.py From google-auth-library-python with Apache License 2.0 | 5 votes |
def test_request_error(self, server): request = self.make_request() response = request(url=server.url + "/server_error", method="GET") assert response.status == http_client.INTERNAL_SERVER_ERROR assert response.data == b"Error"
Example #21
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 #22
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 #23
Source File: main.py From python-docs-samples with Apache License 2.0 | 5 votes |
def unexpected_error(e): """Handle exceptions by returning swagger-compliant json.""" logging.exception('An error occured while processing the request.') response = jsonify({ 'code': http_client.INTERNAL_SERVER_ERROR, 'message': 'Exception: {}'.format(e)}) response.status_code = http_client.INTERNAL_SERVER_ERROR return response
Example #24
Source File: __init__.py From realms-wiki with GNU General Public License v2.0 | 5 votes |
def error_handler(e): try: if isinstance(e, HTTPException): status_code = e.code message = e.description if e.description != type(e).description else None tb = None else: status_code = httplib.INTERNAL_SERVER_ERROR message = None tb = traceback.format_exc() if current_user.admin else None if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']: response = { 'message': message, 'traceback': tb } else: response = render_template('errors/error.html', title=httplib.responses[status_code], status_code=status_code, message=message, traceback=tb) except HTTPException as e2: return error_handler(e2) return response, status_code
Example #25
Source File: test_exception.py From masakari with Apache License 2.0 | 5 votes |
def test_default_error_msg_with_kwargs(self): class FakeMasakariException(exception.MasakariException): msg_fmt = "default message: %(code)s" exc = FakeMasakariException(code=int(http.INTERNAL_SERVER_ERROR)) self.assertEqual('default message: 500', six.text_type(exc)) self.assertEqual('default message: 500', exc.message)
Example #26
Source File: test_exception.py From masakari with Apache License 2.0 | 5 votes |
def test_error_msg_exception_with_kwargs(self): class FakeMasakariException(exception.MasakariException): msg_fmt = "default message: %(misspelled_code)s" exc = FakeMasakariException(code=int(http.INTERNAL_SERVER_ERROR), misspelled_code='blah') self.assertEqual('default message: blah', six.text_type(exc)) self.assertEqual('default message: blah', exc.message)
Example #27
Source File: test_exception.py From masakari with Apache License 2.0 | 5 votes |
def test_error_code_from_kwarg(self): class FakeMasakariException(exception.MasakariException): code = http.INTERNAL_SERVER_ERROR exc = FakeMasakariException(code=http.NOT_FOUND) self.assertEqual(exc.kwargs['code'], http.NOT_FOUND)
Example #28
Source File: group_test.py From treadmill with Apache License 2.0 | 5 votes |
def test_authorization(self): """Test Unix group based authorization""" # successful authorization self.impl.authorize.return_value = (True, []) resp = self.client.post( '/foo/create/bar', data=json.dumps({}), content_type='application/json' ) self.impl.authorize.assert_called_once_with('foo', 'create', 'bar', {}) self.assertEqual(resp.status_code, http_client.OK) self.assertTrue(json.loads(resp.data.decode())['auth']) # permissoin denied self.impl.reset_mock() self.impl.authorize.return_value = (False, ["Denied"]) resp = self.client.post( '/foo/update/bar', data=json.dumps({'pk': 123}), content_type='application/json' ) self.impl.authorize.assert_called_once_with( 'foo', 'update', 'bar', {'pk': 123}, ) self.assertEqual(resp.status_code, http_client.OK) self.assertFalse(json.loads(resp.data.decode())['auth']) # unexpected internal error self.impl.reset_mock() self.impl.authorize.side_effect = TypeError("oops") resp = self.client.post( '/foo/delete/bar', data=json.dumps({'pk': 123, 'metadata': 'extra'}), content_type='application/json' ) self.impl.authorize.assert_called_once_with( 'foo', 'delete', 'bar', {'pk': 123, 'metadata': 'extra'}, ) self.assertEqual(resp.status_code, http_client.INTERNAL_SERVER_ERROR) self.assertFalse(json.loads(resp.data.decode())['auth'])
Example #29
Source File: test_exception.py From masakari with Apache License 2.0 | 5 votes |
def _raise_exc(exc): raise exc(int(http.INTERNAL_SERVER_ERROR))
Example #30
Source File: test_auth.py From masakari with Apache License 2.0 | 5 votes |
def test_invalid_service_catalog(self): self.request.headers['X_USER'] = 'testuser' self.request.headers['X_SERVICE_CATALOG'] = "bad json" response = self.request.get_response(self.middleware) self.assertEqual(response.status_int, http.INTERNAL_SERVER_ERROR)