本文整理匯總了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