當前位置: 首頁>>代碼示例>>Python>>正文


Python http_client.CONFLICT屬性代碼示例

本文整理匯總了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 
開發者ID:containerbuildsystem,項目名稱:osbs-client,代碼行數:22,代碼來源:test_core.py

示例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 
開發者ID:containerbuildsystem,項目名稱:osbs-client,代碼行數:22,代碼來源:test_core.py

示例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 
開發者ID:containerbuildsystem,項目名稱:osbs-client,代碼行數:19,代碼來源:core.py

示例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, []) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:19,代碼來源:test_blob.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:21,代碼來源:test_controller.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:19,代碼來源:test_controller.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:22,代碼來源:test_controller.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:22,代碼來源:test_controller.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:20,代碼來源:test_controller.py

示例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']) 
開發者ID:openstack,項目名稱:tacker,代碼行數:21,代碼來源:test_controller.py

示例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] 
開發者ID:Morgan-Stanley,項目名稱:treadmill,代碼行數:27,代碼來源:restclient.py

示例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 
開發者ID:containerbuildsystem,項目名稱:osbs-client,代碼行數:13,代碼來源:__init__.py

示例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) 
開發者ID:openstack,項目名稱:tacker,代碼行數:17,代碼來源:test_controller.py

示例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) 
開發者ID:openstack,項目名稱:tacker,代碼行數:17,代碼來源:test_controller.py

示例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) 
開發者ID:StackStorm,項目名稱:st2,代碼行數:13,代碼來源:test_policies.py


注:本文中的six.moves.http_client.CONFLICT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。