本文整理汇总了Python中falcon.HTTP_200属性的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTP_200属性的具体用法?Python falcon.HTTP_200怎么用?Python falcon.HTTP_200使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类falcon
的用法示例。
在下文中一共展示了falcon.HTTP_200属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def on_get(self, req, resp):
"""Method handler for GET requests.
:param req: Falcon request object
:param resp: Falcon response object
"""
state = self.state_manager
try:
designs = list(state.designs.keys())
resp.body = json.dumps(designs)
resp.status = falcon.HTTP_200
except Exception as ex:
self.error(req.context, "Exception raised: %s" % str(ex))
self.return_error(
resp,
falcon.HTTP_500,
message="Error accessing design list",
retry=True)
示例2: on_get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def on_get(self, req, resp, hostname):
try:
latest = req.params.get('latest', 'false').upper()
latest = True if latest == 'TRUE' else False
node_bd = self.state_manager.get_build_data(
node_name=hostname, latest=latest)
if not node_bd:
self.return_error(
resp,
falcon.HTTP_404,
message="No build data found",
retry=False)
else:
node_bd = [bd.to_dict() for bd in node_bd]
resp.status = falcon.HTTP_200
resp.body = json.dumps(node_bd)
resp.content_type = falcon.MEDIA_JSON
except Exception as ex:
self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
self.return_error(
resp, falcon.HTTP_500, message="Unknown error", retry=False)
示例3: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def on_post(self, req, resp):
try:
json_data = self.req_json(req)
node_filter = json_data.get('node_filter', None)
design_ref = json_data.get('design_ref', None)
if design_ref is None:
self.info(req.context,
'Missing required input value: design_ref')
self.return_error(
resp,
falcon.HTTP_400,
message='Missing input required value: design_ref',
retry=False)
return
_, site_design = self.orchestrator.get_effective_site(design_ref)
nodes = self.orchestrator.process_node_filter(
node_filter=node_filter, site_design=site_design)
resp_list = [n.name for n in nodes if nodes]
resp.body = json.dumps(resp_list)
resp.status = falcon.HTTP_200
except Exception as ex:
self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
self.return_error(
resp, falcon.HTTP_500, message="Unknown error", retry=False)
示例4: test_read_builddata_all
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_read_builddata_all(self, falcontest, seeded_builddata):
"""Test that by default the API returns all build data for a node."""
url = '/api/v1.0/nodes/foo/builddata'
# Seed the database with build data
nodelist = ['foo']
count = 3
seeded_builddata(nodelist=nodelist, count=count)
# TODO(sh8121att) Make fixture for request header forging
hdr = {
'Content-Type': 'application/json',
'X-IDENTITY-STATUS': 'Confirmed',
'X-USER-NAME': 'Test',
'X-ROLES': 'admin'
}
resp = falcontest.simulate_get(url, headers=hdr)
assert resp.status == falcon.HTTP_200
resp_body = resp.json
assert len(resp_body) == count
示例5: test_get_tasks_id_resp
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_get_tasks_id_resp(self, falcontest):
url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111111'
hdr = self.get_standard_header()
result = falcontest.simulate_get(url, headers=hdr)
assert result.status == falcon.HTTP_200
response_json = json.loads(result.text)
assert response_json[
'task_id'] == '11111111-1111-1111-1111-111111111111'
try:
response_json['build_data']
key_error = False
except KeyError:
key_error = True
assert key_error
try:
response_json['subtask_errors']
key_error = False
except KeyError:
key_error = True
assert key_error
示例6: test_get_tasks_id_builddata_resp
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_get_tasks_id_builddata_resp(self, falcontest):
url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111111'
hdr = self.get_standard_header()
result = falcontest.simulate_get(
url, headers=hdr, query_string='builddata=true')
LOG.debug(result.text)
assert result.status == falcon.HTTP_200
response_json = json.loads(result.text)
assert response_json['build_data']
try:
response_json['subtask_errors']
key_error = False
except KeyError:
key_error = True
assert key_error
示例7: test_get_tasks_id_layers_resp
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_get_tasks_id_layers_resp(self, falcontest):
url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111113'
hdr = self.get_standard_header()
result = falcontest.simulate_get(
url, headers=hdr, query_string='layers=2')
LOG.debug(result.text)
assert result.status == falcon.HTTP_200
response_json = json.loads(result.text)
init_task_id = '11111111-1111-1111-1111-111111111113'
sub_task_id_1 = '11111111-1111-1111-1111-111111111114'
sub_task_id_2 = '11111111-1111-1111-1111-111111111115'
assert response_json['init_task_id'] == init_task_id
assert response_json[init_task_id]['task_id'] == init_task_id
assert response_json[sub_task_id_1]['task_id'] == sub_task_id_1
assert response_json[sub_task_id_2]['task_id'] == sub_task_id_2
try:
response_json['11111111-1111-1111-1111-111111111116']
key_error = False
except KeyError:
key_error = True
assert key_error
示例8: on_get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def on_get(self, req, resp, id):
"""
Handles GET requests for another test
---
tags:
- test
responses:
200:
schema:
type: string
security:
api_key: []
securityDefinitions:
api_key:
type: apiKey
in: Header
name: Authorization
"""
resp.status = falcon.HTTP_200 # This is the default status
resp.body = '\nHello world with {}\n\n'.format(id)
示例9: on_get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def on_get(self, req, resp, ical_key):
"""Access the oncall calendar identified by the key.
The response is in ical format and this url is intended to be
supplied to any calendar application that can subscribe to
calendars from the internet.
"""
try:
path = self.base_url + '/api/v0/ical/' + ical_key
if req.query_string:
path += '?%s' % req.query_string
result = self.oncall_client.get(path)
except MaxRetryError as ex:
logger.error(ex)
else:
if result.status_code == 200:
resp.status = falcon.HTTP_200
resp.content_type = result.headers['Content-Type']
resp.body = result.content
return
elif 400 <= result.status_code <= 499:
resp.status = falcon.HTTP_404
return
raise falcon.HTTPInternalServerError('Internal Server Error', 'Invalid response from API')
示例10: __call__
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def __call__(self, req, resp):
path = self.base_url + '/api/v0/' + '/'.join(req.path.split('/')[4:])
if req.query_string:
path += '?%s' % req.query_string
try:
if req.method == 'GET':
result = self.oncall_client.get(path)
elif req.method == 'OPTIONS':
return
else:
raise falcon.HTTPMethodNotAllowed(['GET', 'OPTIONS'])
except MaxRetryError as e:
logger.error(e.reason)
raise falcon.HTTPInternalServerError('Internal Server Error', 'Max retry error, api unavailable')
if result.status_code == 400:
raise falcon.HTTPBadRequest('Bad Request', '')
elif str(result.status_code)[0] != '2':
raise falcon.HTTPInternalServerError('Internal Server Error', 'Unknown response from the api')
else:
resp.status = falcon.HTTP_200
resp.content_type = result.headers['Content-Type']
resp.body = result.content
示例11: test_falcon_large_json_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_falcon_large_json_request(sentry_init, capture_events):
sentry_init(integrations=[FalconIntegration()])
data = {"foo": {"bar": "a" * 2000}}
class Resource:
def on_post(self, req, resp):
assert req.media == data
sentry_sdk.capture_message("hi")
resp.media = "ok"
app = falcon.API()
app.add_route("/", Resource())
events = capture_events()
client = falcon.testing.TestClient(app)
response = client.simulate_post("/", json=data)
assert response.status == falcon.HTTP_200
(event,) = events
assert event["_meta"]["request"]["data"]["foo"]["bar"] == {
"": {"len": 2000, "rem": [["!limit", "x", 509, 512]]}
}
assert len(event["request"]["data"]["foo"]["bar"]) == 512
示例12: test_falcon_empty_json_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_falcon_empty_json_request(sentry_init, capture_events, data):
sentry_init(integrations=[FalconIntegration()])
class Resource:
def on_post(self, req, resp):
assert req.media == data
sentry_sdk.capture_message("hi")
resp.media = "ok"
app = falcon.API()
app.add_route("/", Resource())
events = capture_events()
client = falcon.testing.TestClient(app)
response = client.simulate_post("/", json=data)
assert response.status == falcon.HTTP_200
(event,) = events
assert event["request"]["data"] == data
示例13: test_falcon_raw_data_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_falcon_raw_data_request(sentry_init, capture_events):
sentry_init(integrations=[FalconIntegration()])
class Resource:
def on_post(self, req, resp):
sentry_sdk.capture_message("hi")
resp.media = "ok"
app = falcon.API()
app.add_route("/", Resource())
events = capture_events()
client = falcon.testing.TestClient(app)
response = client.simulate_post("/", body="hi")
assert response.status == falcon.HTTP_200
(event,) = events
assert event["request"]["headers"]["Content-Length"] == "2"
assert event["request"]["data"] == ""
示例14: test_on_patch_ok_with_some_fields
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_on_patch_ok_with_some_fields(self):
new_version = random.randint(0, 99)
self.mock_db.update_job.return_value = new_version
patch_doc = {'some_field': 'some_value',
'because': 'size_matters',
'job_schedule': {}}
self.mock_req.stream.read.return_value = json.dumps(patch_doc)
expected_result = {'job_id': common.fake_job_0_job_id,
'version': new_version}
self.resource.update_actions_in_job = mock.Mock()
self.resource.on_patch(self.mock_req, self.mock_req,
common.fake_job_0_job_id)
self.mock_db.update_job.assert_called_with(
user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id,
patch_doc=patch_doc)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
result = self.mock_req.body
self.assertEqual(expected_result, result)
示例15: test_on_patch_ok_with_some_fields
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_200 [as 别名]
def test_on_patch_ok_with_some_fields(self):
new_version = random.randint(0, 99)
self.mock_db.update_action.return_value = new_version
patch_doc = {'some_field': 'some_value',
'because': 'size_matters'}
self.mock_json_body.return_value = patch_doc
patch_doc.copy()
expected_result = {'action_id': common.fake_action_0['action_id'],
'version': new_version}
self.resource.on_patch(self.mock_req, self.mock_req,
common.fake_action_0['action_id'])
self.mock_db.update_action.assert_called_with(
user_id=common.fake_action_0['user_id'],
action_id=common.fake_action_0['action_id'],
patch_doc=patch_doc)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
result = self.mock_req.body
self.assertEqual(expected_result, result)