本文整理匯總了Python中http.HTTPStatus.METHOD_NOT_ALLOWED屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.METHOD_NOT_ALLOWED屬性的具體用法?Python HTTPStatus.METHOD_NOT_ALLOWED怎麽用?Python HTTPStatus.METHOD_NOT_ALLOWED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類http.HTTPStatus
的用法示例。
在下文中一共展示了HTTPStatus.METHOD_NOT_ALLOWED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_delete_study_error
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_delete_study_error(httpserver, client, cache_dir):
study_instance_uid = '1.2.3'
httpserver.serve_content(
content='',
code=HTTPStatus.METHOD_NOT_ALLOWED,
headers=''
)
with pytest.raises(HTTPError):
client.delete_study(study_instance_uid=study_instance_uid)
assert len(httpserver.requests) == 1
request = httpserver.requests[0]
expected_path = (
'/studies/{study_instance_uid}'.format(
study_instance_uid=study_instance_uid)
)
assert request.path == expected_path
assert request.method == 'DELETE'
示例2: test_delete_series_error
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_delete_series_error(httpserver, client, cache_dir):
study_instance_uid = '1.2.3'
series_instance_uid = '1.2.4'
httpserver.serve_content(
content='',
code=HTTPStatus.METHOD_NOT_ALLOWED,
headers=''
)
with pytest.raises(HTTPError):
client.delete_series(study_instance_uid=study_instance_uid,
series_instance_uid=series_instance_uid)
assert len(httpserver.requests) == 1
request = httpserver.requests[0]
expected_path = (
'/studies/{study_instance_uid}/series/{series_instance_uid}'.format(
study_instance_uid=study_instance_uid,
series_instance_uid=series_instance_uid)
)
assert request.path == expected_path
assert request.method == 'DELETE'
示例3: test_delete_instance_error
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_delete_instance_error(httpserver, client, cache_dir):
study_instance_uid = '1.2.3'
series_instance_uid = '1.2.4'
sop_instance_uid = '1.2.5'
httpserver.serve_content(
content='',
code=HTTPStatus.METHOD_NOT_ALLOWED,
headers=''
)
with pytest.raises(HTTPError):
client.delete_instance(study_instance_uid=study_instance_uid,
series_instance_uid=series_instance_uid,
sop_instance_uid=sop_instance_uid)
assert len(httpserver.requests) == 1
request = httpserver.requests[0]
expected_path = (
'/studies/{study_instance_uid}/series/{series_instance_uid}/instances'
'/{sop_instance_uid}'.format(
study_instance_uid=study_instance_uid,
series_instance_uid=series_instance_uid,
sop_instance_uid=sop_instance_uid,)
)
assert request.path == expected_path
assert request.method == 'DELETE'
示例4: __init__
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def __init__(self, allowed_methods: Optional[Iterable[str]] = None) -> None:
super().__init__(HTTPStatus.METHOD_NOT_ALLOWED)
self.allowed_methods = allowed_methods
示例5: _send_405
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def _send_405(request):
raise ResponseError(status=HTTPStatus.METHOD_NOT_ALLOWED)
示例6: method_not_allowed
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def method_not_allowed(self) -> web.Response:
return web.json_response({
"error": "Method not allowed",
"errcode": "method_not_allowed",
}, status=HTTPStatus.METHOD_NOT_ALLOWED)
示例7: do_405
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def do_405(environ, start_response):
"""
Generic app to produce a 405
"""
urlpath = environ['SCRIPT_NAME'] + environ['PATH_INFO']
return send_simple_text(
environ, start_response, HTTPStatus.METHOD_NOT_ALLOWED,
"Method {} is not allowed on {}".format(
environ['REQUEST_METHOD'], urlpath,
),
)
示例8: test_logout_GET_returns_405
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_logout_GET_returns_405(self):
password = factory.make_string()
user = factory.make_User(password=password)
self.client.handler.enforce_csrf_checks = True
self.client.login(username=user.username, password=password)
self.client.handler.enforce_csrf_checks = False
response = self.client.get(reverse("logout"))
self.assertThat(
response, HasStatusCode(http.client.METHOD_NOT_ALLOWED)
)
示例9: test_rejects_GET
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_rejects_GET(self):
response = self.client.get(reverse("authenticate"))
self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED))
self.assertThat(response["Allow"], Equals("POST"))
示例10: test_method_not_allowed_on_get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_method_not_allowed_on_get(self):
response = self.client.get(reverse("csrf"))
self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED))
示例11: test_method_not_allowed_on_put
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_method_not_allowed_on_put(self):
response = self.client.put(reverse("csrf"))
self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED))
示例12: test_method_not_allowed_on_delete
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def test_method_not_allowed_on_delete(self):
response = self.client.delete(reverse("csrf"))
self.assertThat(response, HasStatusCode(HTTPStatus.METHOD_NOT_ALLOWED))
示例13: _http_delete
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def _http_delete(self, url: str):
'''Performs a HTTP DELETE request to the specified URL.
Parameters
----------
url: str
unique resource locator
Returns
-------
requests.models.Response
HTTP response message
'''
@retrying.retry(
retry_on_result=self._is_retriable_http_error,
wait_exponential_multiplier=self._wait_exponential_multiplier,
stop_max_attempt_number=self._max_attempts
)
def _invoke_delete_request(url: str) -> requests.models.Response:
return self._session.delete(url)
response = _invoke_delete_request(url)
if response.status_code == HTTPStatus.METHOD_NOT_ALLOWED:
logger.error(
'Resource could not be deleted. The origin server may not support'
'deletion or you may not have the necessary permissions.')
response.raise_for_status()
return response
示例14: get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def get(self, *args, **kwargs):
return Response(status=HTTPStatus.METHOD_NOT_ALLOWED)
示例15: post
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import METHOD_NOT_ALLOWED [as 別名]
def post(self, *args, **kwargs):
return Response(status=HTTPStatus.METHOD_NOT_ALLOWED)