本文整理汇总了Python中six.moves.http_client.CONFLICT属性的典型用法代码示例。如果您正苦于以下问题:Python http_client.CONFLICT属性的具体用法?Python http_client.CONFLICT怎么用?Python http_client.CONFLICT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类six.moves.http_client
的用法示例。
在下文中一共展示了http_client.CONFLICT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_response_bad_stream
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_check_response_bad_stream(self, caplog, log_errors):
iterable = [b'iter', b'lines']
status_code = http_client.CONFLICT
response = Response(status_code, iterable=iterable)
if log_errors:
log_type = logging.ERROR
else:
log_type = logging.DEBUG
with pytest.raises(OsbsResponseException):
if log_errors:
check_response(response)
else:
check_response(response, log_level=log_type)
logged = [(l.getMessage(), l.levelno) for l in caplog.records]
assert len(logged) == 1
assert logged[0][0] == '[{code}] {message}'.format(code=status_code,
message=b'iterlines')
assert logged[0][1] == log_type
示例2: test_check_response_bad_nostream
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_check_response_bad_nostream(self, caplog, log_errors):
status_code = http_client.CONFLICT
content = b'content'
response = Response(status_code, content=content)
if log_errors:
log_type = logging.ERROR
else:
log_type = logging.DEBUG
with pytest.raises(OsbsResponseException):
if log_errors:
check_response(response)
else:
check_response(response, log_level=log_type)
logged = [(l.getMessage(), l.levelno) for l in caplog.records]
assert len(logged) == 1
assert logged[0][0] == '[{code}] {message}'.format(code=status_code,
message=content)
assert logged[0][1] == log_type
示例3: create_resource_quota
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def create_resource_quota(self, name, quota_json):
"""
Prevent builds being scheduled and wait for running builds to finish.
:return:
"""
url = self._build_k8s_url("resourcequotas/")
response = self._post(url, data=json.dumps(quota_json),
headers={"Content-Type": "application/json"})
if response.status_code == http_client.CONFLICT:
url = self._build_k8s_url("resourcequotas/%s" % name)
response = self._put(url, data=json.dumps(quota_json),
headers={"Content-Type": "application/json"})
check_response(response)
return response
示例4: test_upload_from_file_failure
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_upload_from_file_failure(self):
import requests
from google.resumable_media import InvalidResponse
from google.cloud import exceptions
message = "Someone is already in this spot."
response = requests.Response()
response.status_code = http_client.CONFLICT
response.request = requests.Request("POST", "http://example.com").prepare()
side_effect = InvalidResponse(response, message)
with self.assertRaises(exceptions.Conflict) as exc_info:
self._upload_from_file_helper(side_effect=side_effect)
self.assertIn(message, exc_info.exception.message)
self.assertEqual(exc_info.exception.errors, [])
示例5: test_instantiate_incorrect_task_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_instantiate_incorrect_task_state(self, mock_vnf_by_id):
vnf_instance = fakes.return_vnf_instance_model(
task_state=fields.VnfInstanceTaskState.INSTANTIATING)
mock_vnf_by_id.return_value = vnf_instance
body = {"flavourId": "simple"}
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
req.body = jsonutils.dump_as_bytes(body)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in task_state INSTANTIATING. Cannot "
"instantiate while the vnf instance is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例6: test_terminate_incorrect_instantiation_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_terminate_incorrect_instantiation_state(self, mock_vnf_by_id):
mock_vnf_by_id.return_value = fakes.return_vnf_instance()
body = {"terminationType": "FORCEFUL"}
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id)
req.body = jsonutils.dump_as_bytes(body)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in instantiation_state "
"NOT_INSTANTIATED. Cannot terminate while the vnf "
"instance is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例7: test_terminate_incorrect_task_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_terminate_incorrect_task_state(self, mock_vnf_by_id):
vnf_instance = fakes.return_vnf_instance(
instantiated_state=fields.VnfInstanceState.INSTANTIATED,
task_state=fields.VnfInstanceTaskState.TERMINATING)
mock_vnf_by_id.return_value = vnf_instance
body = {"terminationType": "FORCEFUL"}
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id)
req.body = jsonutils.dump_as_bytes(body)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in task_state TERMINATING. Cannot "
"terminate while the vnf instance is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例8: test_heal_incorrect_task_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_heal_incorrect_task_state(self, mock_vnf_by_id):
vnf_instance_obj = fakes.return_vnf_instance(
fields.VnfInstanceState.INSTANTIATED,
task_state=fields.VnfInstanceTaskState.HEALING)
mock_vnf_by_id.return_value = vnf_instance_obj
body = {}
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id)
req.body = jsonutils.dump_as_bytes(body)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in task_state "
"HEALING. Cannot heal while the vnf instance "
"is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例9: test_delete_with_incorrect_instantiation_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_delete_with_incorrect_instantiation_state(self, mock_vnf_by_id):
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
req.method = 'DELETE'
vnf_instance = fakes.return_vnf_instance(
fields.VnfInstanceState.INSTANTIATED)
mock_vnf_by_id.return_value = vnf_instance
# Call delete API
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in instantiation_state "
"INSTANTIATED. Cannot delete while the vnf instance "
"is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例10: test_delete_with_incorrect_task_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_delete_with_incorrect_task_state(self, mock_vnf_by_id):
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
req.method = 'DELETE'
vnf_instance = fakes.return_vnf_instance(
fields.VnfInstanceState.NOT_INSTANTIATED,
task_state=fields.VnfInstanceTaskState.ERROR)
mock_vnf_by_id.return_value = vnf_instance
# Call delete API
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
expected_msg = ("Vnf instance %s in task_state ERROR. "
"Cannot delete while the vnf instance "
"is in this state.")
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
resp.json['conflictingRequest']['message'])
示例11: _handle_error
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def _handle_error(url, response):
"""Handle response status codes."""
handlers = {
http_client.NOT_FOUND: NotFoundError(
'Resource not found: {}'.format(url)
),
# XXX: Correct code is CONFLICT. Support invalid FOUND during
# migration.
http_client.FOUND: AlreadyExistsError(
'Resource already exists: {}'.format(url)
),
http_client.CONFLICT: AlreadyExistsError(
'Resource already exists: {}'.format(url)
),
http_client.TOO_MANY_REQUESTS: TooManyRequestsError(response),
http_client.FAILED_DEPENDENCY: ValidationError(response),
# XXX: Correct code is FORBIDDEN. Support invalid UNAUTHORIZED during
# migration.
http_client.UNAUTHORIZED: NotAuthorizedError(response),
http_client.FORBIDDEN: NotAuthorizedError(response),
http_client.BAD_REQUEST: BadRequestError(response),
}
if response.status_code in handlers:
raise handlers[response.status_code]
示例12: retry_on_conflict
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def retry_on_conflict(func):
@wraps(func)
def retry(*args, **kwargs):
# Only retry when OsbsResponseException was raised due to a conflict
def should_retry_cb(ex):
return ex.status_code == http_client.CONFLICT
retry_func = RetryFunc(OsbsResponseException, should_retry_cb=should_retry_cb)
return retry_func.go(func, *args, **kwargs)
return retry
示例13: test_get_vnf_package_vnfd_failed_with_invalid_status
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_get_vnf_package_vnfd_failed_with_invalid_status(
self, mock_vnf_by_id):
vnf_package_updates = {
'onboarding_state': 'CREATED',
'operational_state': 'DISABLED'
}
mock_vnf_by_id.return_value = fakes.return_vnfpkg_obj(
vnf_package_updates=vnf_package_updates)
req = fake_request.HTTPRequest.blank(
'/vnf_packages/%s/vnfd'
% constants.UUID)
req.headers['Accept'] = 'application/zip'
req.method = 'GET'
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
示例14: test_instantiate_incorrect_instantiation_state
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_instantiate_incorrect_instantiation_state(self, mock_vnf_by_id):
vnf_instance = fakes.return_vnf_instance_model()
vnf_instance.instantiation_state = 'INSTANTIATED'
mock_vnf_by_id.return_value = vnf_instance
body = {"flavourId": "simple"}
req = fake_request.HTTPRequest.blank(
'/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
req.body = jsonutils.dump_as_bytes(body)
req.headers['Content-Type'] = 'application/json'
req.method = 'POST'
# Call Instantiate API
resp = req.get_response(self.app)
self.assertEqual(http_client.CONFLICT, resp.status_code)
示例15: test_post_duplicate
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import CONFLICT [as 别名]
def test_post_duplicate(self):
instance = self.__create_instance()
post_resp = self.__do_post(instance)
self.assertEqual(post_resp.status_int, http_client.CREATED)
post_dup_resp = self.__do_post(instance)
self.assertEqual(post_dup_resp.status_int, http_client.CONFLICT)
del_resp = self.__do_delete(self.__get_obj_id(post_resp))
self.assertEqual(del_resp.status_int, http_client.NO_CONTENT)