本文整理汇总了Python中falcon.HTTP_204属性的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTP_204属性的具体用法?Python falcon.HTTP_204怎么用?Python falcon.HTTP_204使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类falcon
的用法示例。
在下文中一共展示了falcon.HTTP_204属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def on_get(self, req, resp):
token = req.get_param('token', True)
data = {}
for key in self.data_keys:
data[key] = req.get_param(key, True)
if not self.validate_token(token, data):
raise falcon.HTTPForbidden('Invalid token for these given values', '')
endpoint = self.config['iris']['hook']['gmail_one_click']
try:
result = self.iclient.post(endpoint, data)
except MaxRetryError:
logger.exception('Hitting iris-api failed for gmail oneclick')
else:
if result.status == 204:
resp.status = falcon.HTTP_204
return
else:
logger.error('Unexpected status code from api %s for gmail oneclick', result.status)
raise falcon.HTTPInternalServerError('Internal Server Error', 'Invalid response from API')
示例2: test_send_metrics
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_send_metrics(self):
request_body = {
"name": "mon.fake_metric",
"dimensions": {
"hostname": "host0",
"db": "vegeta"
},
"timestamp": 1405630174123,
"value": 1.0,
"value_meta": {
"key1": "value1",
"key2": "value2"
}}
response = self.simulate_request(path='/v2.0/metrics',
headers={'X-Roles':
CONF.security.default_authorized_roles[0],
'X-Tenant-Id': TENANT_ID,
'Content-Type': 'application/json'},
body=json.dumps(request_body),
method='POST')
self.assertEqual(falcon.HTTP_204, response.status)
示例3: test_should_pass_cross_tenant_id
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_cross_tenant_id(self, bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
body, logs = _generate_payload(1)
payload = json.dumps(body)
content_length = len(payload)
response = self.simulate_request(
path='/logs',
method='POST',
query_string='tenant_id=1',
headers={
'X_ROLES': ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, response.status)
logs_resource._processor.send_message.assert_called_with(
logs=logs,
global_dimensions=body['dimensions'],
log_tenant_id='1')
示例4: test_should_pass_empty_cross_tenant_id_wrong_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
body, _ = _generate_payload(1)
payload = json.dumps(body)
content_length = len(payload)
response = self.simulate_request(
path='/logs',
method='POST',
headers={
'X-Roles': ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, response.status)
self.assertEqual(1, bulk_processor.send_message.call_count)
示例5: test_should_pass_empty_cross_tenant_id_ok_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_ok_role(self,
bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
body, _ = _generate_payload(1)
payload = json.dumps(body)
content_length = len(payload)
response = self.simulate_request(
path='/logs',
method='POST',
headers={
'X-Roles': ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, response.status)
self.assertEqual(1, bulk_processor.send_message.call_count)
示例6: test_should_send_unicode_messages
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_send_unicode_messages(self, _):
_init_resource(self)
messages = [m['input'] for m in base.UNICODE_MESSAGES]
body, _ = _generate_payload(messages=messages)
payload = json.dumps(body, ensure_ascii=False)
response = self.simulate_request(
path='/logs',
method='POST',
headers={
'X-Roles': ROLES,
'Content-Type': 'application/json'
},
body=payload
)
self.assertEqual(falcon.HTTP_204, response.status)
示例7: test_should_pass_cross_tenant_id
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_cross_tenant_id(self, bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
v3_body, v3_logs = _generate_v3_payload(1)
payload = json.dumps(v3_body)
content_length = len(payload)
res = self.simulate_request(
path='/logs',
method='POST',
query_string='tenant_id=1',
headers={
headers.X_ROLES.name: ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, res.status)
logs_resource._processor.send_message.assert_called_with(
logs=v3_logs,
global_dimensions=v3_body['dimensions'],
log_tenant_id='1')
示例8: test_should_pass_empty_cross_tenant_id_wrong_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
v3_body, _ = _generate_v3_payload(1)
payload = json.dumps(v3_body)
content_length = len(payload)
res = self.simulate_request(
path='/logs',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, res.status)
self.assertEqual(1, bulk_processor.send_message.call_count)
示例9: test_should_pass_empty_cross_tenant_id_ok_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_ok_role(self,
bulk_processor):
logs_resource = _init_resource(self)
logs_resource._processor = bulk_processor
v3_body, _ = _generate_v3_payload(1)
payload = json.dumps(v3_body)
content_length = len(payload)
res = self.simulate_request(
path='/logs',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, res.status)
self.assertEqual(1, bulk_processor.send_message.call_count)
示例10: test_should_send_unicode_messages
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_send_unicode_messages(self, _):
_init_resource(self)
messages = [m['input'] for m in base.UNICODE_MESSAGES]
v3_body, _ = _generate_v3_payload(messages=messages)
payload = json.dumps(v3_body, ensure_ascii=False)
content_length = len(payload.encode('utf8') if PY3 else payload)
res = self.simulate_request(
path='/logs',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=payload
)
self.assertEqual(falcon.HTTP_204, res.status)
示例11: test_should_pass_empty_cross_tenant_id_wrong_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
log_creator,
kafka_publisher):
logs_resource = _init_resource(self)
logs_resource._log_creator = log_creator
logs_resource._kafka_publisher = kafka_publisher
res = self.simulate_request(
path='/log/single',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
headers.X_DIMENSIONS.name: 'a:1',
'Content-Type': 'application/json',
'Content-Length': '0'
}
)
self.assertEqual(falcon.HTTP_204, res.status)
self.assertEqual(1, kafka_publisher.send_message.call_count)
self.assertEqual(1, log_creator.new_log.call_count)
self.assertEqual(1, log_creator.new_log_envelope.call_count)
示例12: test_should_pass_empty_cross_tenant_id_ok_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_empty_cross_tenant_id_ok_role(self,
log_creator,
kafka_publisher):
logs_resource = _init_resource(self)
logs_resource._log_creator = log_creator
logs_resource._kafka_publisher = kafka_publisher
res = self.simulate_request(
path='/log/single',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
headers.X_DIMENSIONS.name: 'a:1',
'Content-Type': 'application/json',
'Content-Length': '0'
}
)
self.assertEqual(falcon.HTTP_204, res.status)
self.assertEqual(1, kafka_publisher.send_message.call_count)
self.assertEqual(1, log_creator.new_log.call_count)
self.assertEqual(1, log_creator.new_log_envelope.call_count)
示例13: test_should_pass_delegate_cross_tenant_id_ok_role
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_delegate_cross_tenant_id_ok_role(self,
log_creator,
log_publisher):
resource = _init_resource(self)
resource._log_creator = log_creator
resource._kafka_publisher = log_publisher
res = self.simulate_request(
path='/log/single',
method='POST',
query_string='tenant_id=1',
headers={
headers.X_ROLES.name: ROLES,
headers.X_DIMENSIONS.name: 'a:1',
'Content-Type': 'application/json',
'Content-Length': '0'
}
)
self.assertEqual(falcon.HTTP_204, res.status)
self.assertEqual(1, log_publisher.send_message.call_count)
self.assertEqual(1, log_creator.new_log.call_count)
self.assertEqual(1, log_creator.new_log_envelope.call_count)
示例14: test_should_pass_payload_size_not_exceeded
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def test_should_pass_payload_size_not_exceeded(self, _, __):
_init_resource(self)
max_log_size = 1000
body = json.dumps({
'message': 't' * (max_log_size - 100)
})
content_length = len(body)
self.conf_override(max_log_size=max_log_size, group='service')
res = self.simulate_request(
path='/log/single',
method='POST',
headers={
headers.X_ROLES.name: ROLES,
headers.X_DIMENSIONS.name: '',
'Content-Type': 'application/json',
'Content-Length': str(content_length)
},
body=body
)
self.assertEqual(falcon.HTTP_204, res.status)
示例15: get
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_204 [as 别名]
def get(self, req, resp):
"""
Returns updated response with body if extended.
"""
health_check = HealthCheck()
# Test database connection
try:
now = self.state_manager.get_now()
if now is None:
raise Exception('None received from database for now()')
except Exception:
hcm = HealthCheckMessage(
msg='Unable to connect to database', error=True)
health_check.add_detail_msg(msg=hcm)
# Test MaaS connection
try:
task = self.orchestrator.create_task(
action=hd_fields.OrchestratorAction.Noop)
maas_validation = ValidateNodeServices(task, self.orchestrator,
self.state_manager)
maas_validation.start()
if maas_validation.task.get_status() == ActionResult.Failure:
raise Exception('MaaS task failure')
except Exception:
hcm = HealthCheckMessage(
msg='Unable to connect to MaaS', error=True)
health_check.add_detail_msg(msg=hcm)
if self.extended:
resp.body = json.dumps(health_check.to_dict())
if health_check.is_healthy() and self.extended:
resp.status = falcon.HTTP_200
elif health_check.is_healthy():
resp.status = falcon.HTTP_204
else:
resp.status = falcon.HTTP_503