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


Python falcon.HTTP_OK屬性代碼示例

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


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

示例1: test_parse_form_as_params

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_parse_form_as_params(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('simple') == 'ok'
            assert req.get_param('afile').file.read() == b'filecontent'
            assert req.get_param('afile').filename == 'afile.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
開發者ID:yohanboniface,項目名稱:falcon-multipart,代碼行數:19,代碼來源:test_middleware.py

示例2: test_with_binary_file

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_with_binary_file(client):
    here = os.path.dirname(os.path.realpath(__file__))
    filepath = os.path.join(here, 'image.jpg')
    image = open(filepath, 'rb')

    class Resource:

        def on_post(self, req, resp, **kwargs):
            resp.data = req.get_param('afile').file.read()
            resp.content_type = 'image/jpg'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': image})
    assert resp.status == falcon.HTTP_OK
    image.seek(0)
    assert resp.body == image.read() 
開發者ID:yohanboniface,項目名稱:falcon-multipart,代碼行數:20,代碼來源:test_middleware.py

示例3: test_parse_non_ascii_filename_in_headers

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_parse_non_ascii_filename_in_headers(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('afile').file.read() == b'name,code\nnom,2\n'
            assert req.get_param('afile').filename == 'Na%C3%AFve%20file.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    # Simulate browser sending non ascii filename.
    body = ('--boundary\r\nContent-Disposition: '
            'form-data; name="afile"; filename*=utf-8\'\'Na%C3%AFve%20file.txt'
            '\r\nContent-Type: text/csv\r\n\r\nname,code\nnom,2\n\r\n'
            '--boundary--\r\n')
    headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
    resp = client.post('/route', body=body, headers=headers)
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
開發者ID:yohanboniface,項目名稱:falcon-multipart,代碼行數:23,代碼來源:test_middleware.py

示例4: test_parse_multiple_values

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_parse_multiple_values(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param_as_list('multi') == ['1', '2']
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'multi': ['1', '2']},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
開發者ID:yohanboniface,項目名稱:falcon-multipart,代碼行數:17,代碼來源:test_middleware.py

示例5: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def on_get(self, req, resp):
        response = list_servings(req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'OK', 'data': response}) 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:6,代碼來源:servings.py

示例6: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def on_get(self, req, resp, tenant_name):
        namespace = tenant_name
        response = list_models(namespace, req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'OK', 'data': {'models': response}}) 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:7,代碼來源:models.py

示例7: on_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def on_delete(self, req, resp, tenant_name):
        """Handles DELETE requests"""
        namespace = tenant_name
        body = req.media
        response = delete_model(body, namespace, req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'DELETED', 'data': {'model_path': response}}) 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:9,代碼來源:models.py

示例8: test_token_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_token_post(mocker, client, body, expected_status):
    get_token_mock = mocker.patch('management_api.authenticate.authenticate.get_token')
    get_token_mock.return_value = "test"
    result = client.simulate_request(method='POST', json=body, path='/authenticate/token')
    assert expected_status == result.status
    if expected_status is falcon.HTTP_OK:
        get_token_mock.assert_called_once()
        assert 'token' in result.text 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:10,代碼來源:test_authenticate.py

示例9: test_models_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_models_delete(mocker, client):
    delete_model_mock = mocker.patch('management_api.models.models.delete_model')
    delete_model_mock.return_value = 'test'
    body = {'modelName': 'test', 'modelVersion': 1}
    expected_status = falcon.HTTP_OK

    result = client.simulate_request(method='DELETE', path='/tenants/default/models',
                                     headers={},
                                     json=body)

    assert expected_status == result.status
    delete_model_mock.assert_called_once() 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:14,代碼來源:test_models.py

示例10: test_endpoints_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_endpoints_post(mocker, client, body, expected_message, expected_status,
                        model_availability):
    create_endpoint_mock = mocker.patch('management_api.endpoints.endpoints.create_endpoint')
    create_endpoint_mock.return_value = "test"
    check_model_mock = mocker.patch('management_api.endpoints.endpoints.check_endpoint_model')
    check_model_mock.return_value = model_availability

    result = client.simulate_request(method='POST', path='/tenants/default/endpoints', headers={},
                                     json=body)
    assert expected_status == result.status
    assert expected_message in result.text
    if not model_availability:
        assert "test model is not available on the platform" in result.text
    if result.status == falcon.HTTP_OK:
        create_endpoint_mock.assert_called_once() 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:17,代碼來源:test_endpoints.py

示例11: test_endpoints_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_endpoints_delete(mocker, client):
    delete_endpoint_mock = mocker.patch('management_api.endpoints.endpoints.delete_endpoint')
    delete_endpoint_mock.return_value = "test"
    expected_status = falcon.HTTP_OK
    expected_message = {"status": "DELETED", "data": {"url": "test"}}
    body = {'endpointName': 'test'}

    result = client.simulate_request(method='DELETE', path='/tenants/default/endpoints', headers={},
                                     json=body)
    assert expected_status == result.status
    assert expected_message == json.loads(result.text)
    delete_endpoint_mock.assert_called_once() 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:14,代碼來源:test_endpoints.py

示例12: test_endpoints_patch

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_endpoints_patch(mocker, client, functionality, method_name, body, expected_message,
                         expected_status):
    method_mock = mocker.patch('management_api.endpoints.endpoints.' + method_name)
    method_mock.return_value = "test"

    result = client.simulate_request(method='PATCH', path=f'/tenants/default/endpoints/test/'
                                                          f'{functionality}',
                                     headers={}, json=body)
    assert expected_status == result.status
    assert expected_message in result.text
    if result.status == falcon.HTTP_OK:
        method_mock.assert_called_once() 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:14,代碼來源:test_endpoints.py

示例13: test_get_welcome_message

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_get_welcome_message(client):
    doc = {"message": "Hello, World!"}
    result = client.simulate_get("/")

    assert result.status == falcon.HTTP_OK
    assert result.json == doc 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:8,代碼來源:test_root.py

示例14: test_get_returns_hello_name

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_get_returns_hello_name(client):
    doc = {"message": "Hello, Bob!"}
    result = client.simulate_get("/hello/bob")

    assert result.status == falcon.HTTP_OK
    assert result.json == doc 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:8,代碼來源:test_hello.py

示例15: test_get_users

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_OK [as 別名]
def test_get_users(client):
    with patch.object(UserMapper, "get_all", return_value=[user1(), user2()]):
        result = client.simulate_get("/users")

        assert result.status == falcon.HTTP_OK
        assert len(result.json["users"]) == 2 
開發者ID:alexferl,項目名稱:falcon-boilerplate,代碼行數:8,代碼來源:test_users.py


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