本文整理汇总了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'
示例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()
示例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'
示例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'
示例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})
示例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}})
示例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}})
示例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
示例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()
示例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()
示例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()
示例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()
示例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
示例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
示例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