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


Python falcon.HTTP_BAD_REQUEST屬性代碼示例

本文整理匯總了Python中falcon.HTTP_BAD_REQUEST屬性的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTP_BAD_REQUEST屬性的具體用法?Python falcon.HTTP_BAD_REQUEST怎麽用?Python falcon.HTTP_BAD_REQUEST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_BAD_REQUEST屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_both_schemas_validation_failure

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def test_both_schemas_validation_failure():
    with pytest.raises(HTTPError) as excinfo:
        Resource().both_validated(GoodData(), BadData())

    assert excinfo.value.title == falcon.HTTP_INTERNAL_SERVER_ERROR
    assert excinfo.value.description == "Response data failed validation"

    with pytest.raises(HTTPError) as excinfo:
        Resource().both_validated(BadData(), GoodData())

    msg = "Request data failed validation: data must contain ['message'] properties"
    assert excinfo.value.title == falcon.HTTP_BAD_REQUEST
    assert excinfo.value.description == msg

    client = testing.TestClient(falcon.API())
    client.app.add_route("/test", Resource())
    result = client.simulate_put("/test", json=BadData.media)
    assert result.status_code == 400 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:20,代碼來源:test_validators.py

示例2: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def on_post(self, req, resp):
        self.process_request(req, resp)

        password = req.context.get('_body', {}).get('password')
        if password is None:
            resp.status = falcon.HTTP_BAD_REQUEST
            return None

        result = self.parse_password(password)
        resp.body = json.dumps(result) 
開發者ID:PacktPublishing,項目名稱:Python-Journey-from-Novice-to-Expert,代碼行數:12,代碼來源:handlers.py

示例3: test_create_bulk_without_list_results_in_bad_request

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def test_create_bulk_without_list_results_in_bad_request(self):
        self.do_create_bulk(
            {'writable': 'changed', 'unsigned': 12}
        )
        assert self.srmock.status == falcon.HTTP_BAD_REQUEST


# actual test case classes here 
開發者ID:swistakm,項目名稱:graceful,代碼行數:10,代碼來源:test_generic.py

示例4: retrieve_obj

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def retrieve_obj(id_: str, mapper_: Mapper) -> Model:
    name = mapper_.__class__.__name__.lower().split("mapper")[0].capitalize()
    obj = mapper_.get(id_)

    if obj is None:
        raise HTTPError(falcon.HTTP_BAD_REQUEST, f"{name} not found")
    elif obj.deleted_at is not None:
        raise HTTPError(falcon.HTTP_GONE, f"{name} was deleted")

    return obj 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:12,代碼來源:util.py

示例5: _validate

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def _validate(req_schema: Dict = None, resp_schema: Dict = None):
    def decorator(func):
        @wraps(func)
        def wrapper(self, req, resp, *args, **kwargs):
            if req_schema is not None:
                try:
                    schema = fastjsonschema.compile(req_schema)
                    schema(req.media)
                except fastjsonschema.JsonSchemaException as e:
                    msg = "Request data failed validation: {}".format(e.message)
                    raise HTTPError(falcon.HTTP_BAD_REQUEST, msg)

            result = func(self, req, resp, *args, **kwargs)

            if resp_schema is not None:
                try:
                    schema = fastjsonschema.compile(resp_schema)
                    schema(resp.media)
                except fastjsonschema.JsonSchemaException:
                    raise HTTPError(
                        falcon.HTTP_INTERNAL_SERVER_ERROR,
                        "Response data failed validation",
                    )
                    # Do not return 'e.message' in the response to
                    # prevent info about possible internal response
                    # formatting bugs from leaking out to users.

            return result

        return wrapper

    return decorator 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:34,代碼來源:jsonschema.py

示例6: test_req_schema_validation_failure

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def test_req_schema_validation_failure():
    with pytest.raises(falcon.HTTPError) as excinfo:
        Resource().request_validated(BadData(), None)

    msg = "Request data failed validation: data must contain ['message'] properties"
    assert excinfo.value.title == falcon.HTTP_BAD_REQUEST
    assert excinfo.value.description == msg 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:9,代碼來源:test_validators.py

示例7: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_BAD_REQUEST [as 別名]
def on_post(self, req, resp):

        block_hash = None

        if req.media.get('block_id'):
            substrate = SubstrateInterface(SUBSTRATE_RPC_URL)
            block_hash = substrate.get_block_hash(req.media.get('block_id'))
        elif req.media.get('block_hash'):
            block_hash = req.media.get('block_hash')
        else:
            resp.status = falcon.HTTP_BAD_REQUEST
            resp.media = {'errors': ['Either block_hash or block_id should be supplied']}

        if block_hash:
            print('Processing {} ...'.format(block_hash))
            harvester = PolkascanHarvesterService(
                db_session=self.session,
                type_registry=TYPE_REGISTRY,
                type_registry_file=TYPE_REGISTRY_FILE
            )

            block = Block.query(self.session).filter(Block.hash == block_hash).first()

            if block:
                resp.status = falcon.HTTP_200
                resp.media = {'result': 'already exists', 'parentHash': block.parent_hash}
            else:

                amount = req.media.get('amount', 1)

                for nr in range(0, amount):
                    try:
                        block = harvester.add_block(block_hash)
                    except BlockAlreadyAdded as e:
                        print('Skipping {}'.format(block_hash))
                    block_hash = block.parent_hash
                    if block.id == 0:
                        break

                self.session.commit()

                resp.status = falcon.HTTP_201
                resp.media = {'result': 'added', 'parentHash': block.parent_hash}

        else:
            resp.status = falcon.HTTP_404
            resp.media = {'result': 'Block not found'} 
開發者ID:polkascan,項目名稱:polkascan-pre-harvester,代碼行數:49,代碼來源:harvester.py


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