本文整理汇总了Python中zato.server.service.reqresp.Request.payload方法的典型用法代码示例。如果您正苦于以下问题:Python Request.payload方法的具体用法?Python Request.payload怎么用?Python Request.payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zato.server.service.reqresp.Request
的用法示例。
在下文中一共展示了Request.payload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sio_list_data_type_input_xml
# 需要导入模块: from zato.server.service.reqresp import Request [as 别名]
# 或者: from zato.server.service.reqresp.Request import payload [as 别名]
def test_sio_list_data_type_input_xml(self):
cid = rand_string()
data_format = DATA_FORMAT.XML
transport = rand_string()
sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
service_sio = Bunch()
service_sio.input_required = ('first_name', 'last_name', List('emails'))
expected_first_name = faker.first_name()
expected_last_name = faker.last_name()
expected_emails = sorted([faker.email(), faker.email()])
r = Request(getLogger(__name__), sio_config)
r.payload = etree.fromstring("""<request>
<first_name>{}</first_name>
<last_name>{}</last_name>
<emails>
<item>{}</item>
<item>{}</item>
</emails>
</request>""".format(
expected_first_name, expected_last_name, expected_emails[0], expected_emails[1]))
r.init(True, cid, service_sio, data_format, transport, {})
eq_(r.input.first_name, expected_first_name)
eq_(r.input.last_name, expected_last_name)
eq_(r.input.emails, expected_emails)
示例2: test_sio_list_data_type_input_json
# 需要导入模块: from zato.server.service.reqresp import Request [as 别名]
# 或者: from zato.server.service.reqresp.Request import payload [as 别名]
def test_sio_list_data_type_input_json(self):
cid = rand_string()
data_format = DATA_FORMAT.JSON
transport = rand_string()
sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
service_sio = Bunch()
service_sio.input_required = ('first_name', 'last_name', List('emails'))
expected_first_name = faker.first_name()
expected_last_name = faker.last_name()
expected_emails = sorted([faker.email(), faker.email()])
r = Request(getLogger(__name__), sio_config)
r.payload = {
'first_name': expected_first_name,
'last_name': expected_last_name,
'emails': expected_emails,
}
r.init(True, cid, service_sio, data_format, transport, {})
eq_(r.input.first_name, expected_first_name)
eq_(r.input.last_name, expected_last_name)
eq_(r.input.emails, expected_emails)
示例3: test_init_sio
# 需要导入模块: from zato.server.service.reqresp import Request [as 别名]
# 或者: from zato.server.service.reqresp.Request import payload [as 别名]
def test_init_sio(self):
is_sio = True
cid = uuid4().hex
data_format = uuid4().hex
transport = uuid4().hex
io_default = {'dummy':'dummy'}
io_custom = Bunch({
'request_elem': uuid4().hex,
'input_required': ['a', 'b', 'c'],
'input_optional': ['d', 'e', 'f'],
'default_value': uuid4().hex,
'use_text': uuid4().hex,
})
wsgi_environ = {
'zato.http.GET': {uuid4().hex:uuid4().hex},
'zato.http.POST': {uuid4().hex:uuid4().hex},
'REQUEST_METHOD': uuid4().hex,
}
def _get_params(request_params, *ignored):
# 'g' is never overridden
if request_params is io_custom['input_required']:
return {'a':'a-req', 'b':'b-req', 'c':'c-req', 'g':'g-msg'}
else:
return {'d':'d-opt', 'e':'e-opt', 'f':'f-opt', 'g':'g-msg'}
request = Request(logger)
request.payload = None
request.raw_request = io_default
request.get_params = _get_params
request.channel_params['a'] = 'channel_param_a'
request.channel_params['b'] = 'channel_param_b'
request.channel_params['c'] = 'channel_param_c'
request.channel_params['d'] = 'channel_param_d'
request.channel_params['e'] = 'channel_param_e'
request.channel_params['f'] = 'channel_param_f'
request.channel_params['h'] = 'channel_param_h' # Never overridden
for io in(io_default, io_custom):
for params_priority in PARAMS_PRIORITY:
request.params_priority = params_priority
request.http.init(wsgi_environ)
request.payload = io
request.init(is_sio, cid, io, data_format, transport, wsgi_environ)
if io is io_default:
eq_(sorted(request.input.items()),
sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
'h':'channel_param_h'}.items()))
else:
if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
eq_(sorted(request.input.items()),
sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
'g': 'g-msg',
'h':'channel_param_h'}.items()))
else:
eq_(sorted(request.input.items()),
sorted({'a': 'a-req', 'b': 'b-req', 'c': 'c-req',
'd': 'd-opt', 'e': 'e-opt', 'f': 'f-opt',
'g': 'g-msg',
'h':'channel_param_h'}.items()))
示例4: test_init_sio
# 需要导入模块: from zato.server.service.reqresp import Request [as 别名]
# 或者: from zato.server.service.reqresp.Request import payload [as 别名]
def test_init_sio(self):
is_sio = True
cid = uuid4().hex
data_format = uuid4().hex
transport = uuid4().hex
io_default = {}
io_custom = Bunch(
{
"request_elem": uuid4().hex,
"input_required": ["a", "b", "c"],
"input_optional": ["d", "e", "f"],
"default_value": uuid4().hex,
"use_text": uuid4().hex,
}
)
wsgi_environ = {
"zato.http.GET": {uuid4().hex: uuid4().hex},
"zato.http.POST": {uuid4().hex: uuid4().hex},
"REQUEST_METHOD": uuid4().hex,
}
def _get_params(request_params, *ignored):
# 'g' is never overridden
if request_params is io_custom["input_required"]:
return {"a": "a-req", "b": "b-req", "c": "c-req", "g": "g-msg"}
else:
return {"d": "d-opt", "e": "e-opt", "f": "f-opt", "g": "g-msg"}
r = Request(None)
r.payload = None
r.get_params = _get_params
r.channel_params["a"] = "channel_param_a"
r.channel_params["b"] = "channel_param_b"
r.channel_params["c"] = "channel_param_c"
r.channel_params["d"] = "channel_param_d"
r.channel_params["e"] = "channel_param_e"
r.channel_params["f"] = "channel_param_f"
r.channel_params["h"] = "channel_param_h" # Never overridden
for io in (io_default, io_custom):
for params_priority in PARAMS_PRIORITY:
r.params_priority = params_priority
r.init(is_sio, cid, io, data_format, transport, wsgi_environ)
if io is io_default:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "channel_param_a",
"b": "channel_param_b",
"c": "channel_param_c",
"d": "channel_param_d",
"e": "channel_param_e",
"f": "channel_param_f",
"h": "channel_param_h",
}.items()
),
)
else:
if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "channel_param_a",
"b": "channel_param_b",
"c": "channel_param_c",
"d": "channel_param_d",
"e": "channel_param_e",
"f": "channel_param_f",
"g": "g-msg",
"h": "channel_param_h",
}.items()
),
)
else:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "a-req",
"b": "b-req",
"c": "c-req",
"d": "d-opt",
"e": "e-opt",
"f": "f-opt",
"g": "g-msg",
"h": "channel_param_h",
}.items()
),
)