本文整理汇总了Python中spyne.util.test.call_wsgi_app_kwargs函数的典型用法代码示例。如果您正苦于以下问题:Python call_wsgi_app_kwargs函数的具体用法?Python call_wsgi_app_kwargs怎么用?Python call_wsgi_app_kwargs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_wsgi_app_kwargs函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_before_first_root
def test_before_first_root(self):
class CM(ComplexModel):
i = Integer
s = String
class CCM(ComplexModel):
c = CM
i = Integer
s = String
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [CCM(c=ccm.c,i=ccm.i, s=ccm.s)] * 2
cb_called = [False]
def _cb(ctx, cls, inst, parent, name, **kwargs):
assert not cb_called[0]
cb_called[0] = True
app = Application([SomeService], 'tns',
in_protocol=HttpRpc(hier_delim='_'),
out_protocol=HtmlMicroFormat(
doctype=None, before_first_root=_cb))
server = WsgiApplication(app)
call_wsgi_app_kwargs(server,
ccm_c_s='abc', ccm_c_i=123, ccm_i=456, ccm_s='def')
assert cb_called[0]
开发者ID:JacekPliszka,项目名称:spyne,代码行数:30,代码来源:test_html_microformat.py
示例2: test_complex_array
def test_complex_array(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [ccm] * 5
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlTable(field_name_attr='class'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server,
ccm_i='456',
ccm_s='def',
ccm_c_i='123',
ccm_c_s='abc',
)
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
resp = elt.find_class('some_callResponse')
assert len(resp) == 1
for i in range(len(elt)):
row = elt[i]
if i == 0: # check for field names in table header
cell = row.findall('th[@class="i"]')
assert len(cell) == 1
assert cell[0].text == 'i'
cell = row.findall('th[@class="c_i"]')
assert len(cell) == 1
assert cell[0].text == 'c_i'
cell = row.findall('th[@class="c_s"]')
assert len(cell) == 1
assert cell[0].text == 'c_s'
cell = row.findall('th[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 's'
else: # check for field values in table body
cell = row.findall('td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == '456'
cell = row.findall('td[@class="c_i"]')
assert len(cell) == 1
assert cell[0].text == '123'
cell = row.findall('td[@class="c_s"]')
assert len(cell) == 1
assert cell[0].text == 'abc'
cell = row.findall('td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 'def'
开发者ID:Bernie,项目名称:spyne,代码行数:58,代码来源:test_html_table.py
示例3: test_complex_array
def test_complex_array(self):
class CM(ComplexModel):
i = Integer
s = String
class CCM(ComplexModel):
c = CM
i = Integer
s = String
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [CCM(c=ccm.c,i=ccm.i, s=ccm.s)] * 2
app = Application([SomeService], 'tns',
in_protocol=HttpRpc(hier_delim='_'),
out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server,
ccm_c_s='abc', ccm_c_i=123, ccm_i=456, ccm_s='def')
#
# Here's what this is supposed to return:
#
# <div class="some_callResponse"><div class="some_callResult">
# <div class="CCM">
# <div class="i">456</div>
# <div class="c">
# <div class="i">123</div>
# <div class="s">abc</div>
# </div>
# <div class="s">def</div>
# </div>
# <div class="CCM">
# <div class="i">456</div>
# <div class="c">
# <div class="i">123</div>
# <div class="s">abc</div>
# </div>
# <div class="s">def</div>
# </div>
# </div></div>
#
print(out_string)
elt = html.fromstring(out_string)
show(elt, "TestHtmlMicroFormat.test_complex_array")
resp = elt.find_class('some_callResponse')
assert len(resp) == 1
res = resp[0].find_class('some_callResult')
assert len(res) == 1
assert len(res[0].find_class("CCM")) == 2
开发者ID:1-bit,项目名称:spyne,代码行数:56,代码来源:test_html_microformat.py
示例4: test_complex
def test_complex(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=CCM)
def some_call(ccm):
return ccm
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlTable(field_name_attr='class', fields_as='rows'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server,
ccm_c_s='abc', ccm_c_i='123', ccm_i='456', ccm_s='def')
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
# Here's what this is supposed to return
"""
<table class="some_callResponse">
<tr>
<th class="i">i</th>
<td class="i">456</td>
</tr>
<tr>
<th class="c_i">c_i</th>
<td class="c_i">123</td>
</tr>
<tr>
<th class="c_s">c_s</th>
<td class="c_s">abc</td>
</tr>
<tr>
<th class="s">s</th>
<td class="s">def</td>
</tr>
</table>
"""
resp = elt.find_class('some_callResponse')
assert len(resp) == 1
assert elt.xpath('//th[@class="i"]/text()')[0] == 'i'
assert elt.xpath('//td[@class="i"]/text()')[0] == '456'
assert elt.xpath('//th[@class="c_i"]/text()')[0] == 'c_i'
assert elt.xpath('//td[@class="c_i"]/text()')[0] == '123'
assert elt.xpath('//th[@class="c_s"]/text()')[0] == 'c_s'
assert elt.xpath('//td[@class="c_s"]/text()')[0] == 'abc'
assert elt.xpath('//th[@class="s"]/text()')[0] == 's'
assert elt.xpath('//td[@class="s"]/text()')[0] == 'def'
开发者ID:Bernie,项目名称:spyne,代码行数:52,代码来源:test_html_table.py
示例5: test_complex_array
def test_complex_array(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [ccm] * 5
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlTable(field_name_attr='class'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server,
ccm_i='456',
ccm_s='def',
ccm_c_i='123',
ccm_c_s='abc',
)
from lxml import etree
elt = etree.fromstring(out_string)
print(etree.tostring(elt, pretty_print=True))
elt = html.fromstring(out_string)
resp = elt.find_class('some_callResponse')
assert len(resp) == 1
row, = elt[0] # thead
cell = row.findall('th[@class="i"]')
assert len(cell) == 1
assert cell[0].text == 'i'
cell = row.findall('th[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 's'
for row in elt[1]: # tbody
cell = row.xpath('td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == '456'
cell = row.xpath('td[@class="c"]//td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == '123'
cell = row.xpath('td[@class="c"]//td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 'abc'
cell = row.xpath('td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 'def'
开发者ID:jpunwin,项目名称:spyne,代码行数:50,代码来源:test_html_table.py
示例6: test_complex_array
def test_complex_array(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [ccm] * 5
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlColumnTable(field_type_name_attr=None))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server,
ccm_i='456',
ccm_s='def',
ccm_c_i='123',
ccm_c_s='abc',
)
elt = etree.fromstring(out_string)
show(elt, 'TestHtmlColumnTable.test_complex_array')
elt = html.fromstring(out_string)
row, = elt[0] # thead
cell = row.findall('th[@class="i"]')
assert len(cell) == 1
assert cell[0].text == 'i'
cell = row.findall('th[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 's'
for row in elt[1]: # tbody
cell = row.xpath('td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == '456'
cell = row.xpath('td[@class="c"]//td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == '123'
cell = row.xpath('td[@class="c"]//td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 'abc'
cell = row.xpath('td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == 'def'
开发者ID:ashleysommer,项目名称:spyne,代码行数:47,代码来源:test_html_table.py
示例7: test_complex_array
def test_complex_array(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=Array(CCM))
def some_call(ccm):
return [ccm] * 5
app = Application(
[SomeService], "tns", in_protocol=HttpRpc(), out_protocol=HtmlColumnTable(field_name_attr="class")
)
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server, ccm_i="456", ccm_s="def", ccm_c_i="123", ccm_c_s="abc")
elt = etree.fromstring(out_string)
show(elt, "TestHtmlColumnTable.test_complex_array")
elt = html.fromstring(out_string)
row, = elt[0] # thead
cell = row.findall('th[@class="i"]')
assert len(cell) == 1
assert cell[0].text == "i"
cell = row.findall('th[@class="s"]')
assert len(cell) == 1
assert cell[0].text == "s"
for row in elt[1]: # tbody
cell = row.xpath('td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == "456"
cell = row.xpath('td[@class="c"]//td[@class="i"]')
assert len(cell) == 1
assert cell[0].text == "123"
cell = row.xpath('td[@class="c"]//td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == "abc"
cell = row.xpath('td[@class="s"]')
assert len(cell) == 1
assert cell[0].text == "def"
开发者ID:sunpoet,项目名称:spyne,代码行数:43,代码来源:test_html_table.py
示例8: test_anyuri_string
def test_anyuri_string(self):
_link = "http://arskom.com.tr/"
class C(ComplexModel):
c = AnyUri
class SomeService(ServiceBase):
@srpc(_returns=C)
def some_call():
return C(c=_link)
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlTable(field_name_attr='class', fields_as='rows'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
开发者ID:jpunwin,项目名称:spyne,代码行数:21,代码来源:test_html_table.py
示例9: test_anyuri_string
def test_anyuri_string(self):
_link = "http://arskom.com.tr/"
class C(ComplexModel):
c = AnyUri
class SomeService(ServiceBase):
@srpc(_returns=Array(C))
def some_call():
return [C(c=_link)]
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlColumnTable(field_name_attr='class'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
elt = html.fromstring(out_string)
show(elt, "TestHtmlColumnTable.test_anyuri_string")
assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
开发者ID:pombreda,项目名称:spyne,代码行数:21,代码来源:test_html_table.py
示例10: test_column_href_string_with_substitution
def test_column_href_string_with_substitution(self):
_link = "http://arskom.com.tr/?spyne_test=%s"
class C(ComplexModel):
c = Unicode(pa={HtmlColumnTable: dict(href=_link)})
class SomeService(ServiceBase):
@srpc(_returns=C)
def some_call():
return C(c="hello")
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlColumnTable(field_name_attr='class'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link % "hello"
开发者ID:pombreda,项目名称:spyne,代码行数:21,代码来源:test_html_table.py
示例11: test_anyuri_uri_value
def test_anyuri_uri_value(self):
_link = "http://arskom.com.tr/"
_text = "Arskom"
class C(ComplexModel):
c = AnyUri
class SomeService(ServiceBase):
@srpc(_returns=Array(C))
def some_call():
return [C(c=AnyUri.Value(_link, text=_text))]
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlColumnTable(field_name_attr='class'))
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
assert elt.xpath('//td[@class="c"]')[0][0].text == _text
assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
开发者ID:pombreda,项目名称:spyne,代码行数:23,代码来源:test_html_table.py
示例12: test_row_subprot
def test_row_subprot(self):
from lxml.html.builder import E
from spyne.protocol.html import HtmlBase
from spyne.util.six.moves.urllib.parse import urlencode
from spyne.protocol.html import HtmlMicroFormat
class SearchProtocol(HtmlBase):
def to_parent(self, ctx, cls, inst, parent, name, **kwargs):
s = self.to_unicode(cls._type_info['query'], inst.query)
q = urlencode({"q": s})
parent.write(E.a("Search %s" % inst.query,
href="{}?{}".format(inst.uri, q)))
def column_table_gen_header(self, ctx, cls, parent, name):
parent.write(E.thead(E.th("Search",
**{'class': 'search-link'})))
def column_table_before_row(self, ctx, cls, inst, parent, name,**_):
ctxstack = getattr(ctx.protocol[self],
'array_subprot_ctxstack', [])
tr_ctx = parent.element('tr')
tr_ctx.__enter__()
ctxstack.append(tr_ctx)
td_ctx = parent.element('td', **{'class': "search-link"})
td_ctx.__enter__()
ctxstack.append(td_ctx)
ctx.protocol[self].array_subprot_ctxstack = ctxstack
def column_table_after_row(self, ctx, cls, inst, parent, name,
**kwargs):
ctxstack = ctx.protocol[self].array_subprot_ctxstack
for elt_ctx in reversed(ctxstack):
elt_ctx.__exit__(None, None, None)
del ctxstack[:]
class Search(ComplexModel):
query = Unicode
uri = Unicode
SearchTable = Array(
Search.customize(prot=SearchProtocol()),
prot=HtmlColumnTable(field_type_name_attr=None),
)
class SomeService(ServiceBase):
@srpc(_returns=SearchTable)
def some_call():
return [
Search(query='Arskom', uri='https://www.google.com/search'),
Search(query='Spyne', uri='https://www.bing.com/search'),
]
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
elt = html.fromstring(out_string)
print(html.tostring(elt, pretty_print=True))
assert elt.xpath('//td[@class="search-link"]/a/text()') == \
['Search Arskom', 'Search Spyne']
assert elt.xpath('//td[@class="search-link"]/a/@href') == [
'https://www.google.com/search?q=Arskom',
'https://www.bing.com/search?q=Spyne',
]
assert elt.xpath('//th[@class="search-link"]/text()') == ["Search"]
开发者ID:ashleysommer,项目名称:spyne,代码行数:76,代码来源:test_html_table.py
示例13: test_with_encoding
def test_with_encoding(self):
headers = {'CONTENT_TYPE':'text/plain; charset=utf8'}
ret = call_wsgi_app_kwargs(self.app, 'echo_string', headers, s="string")
assert ret == 'string'
开发者ID:mescam,项目名称:spyne,代码行数:4,代码来源:test_http.py
示例14: test_without_content_type
def test_without_content_type(self):
headers = None
ret = call_wsgi_app_kwargs(self.app, 'echo_string', headers, s="string")
assert ret == 'string'
开发者ID:mescam,项目名称:spyne,代码行数:4,代码来源:test_http.py
示例15: test_with_encoding
def test_with_encoding(self):
headers = {"CONTENT_TYPE": "text/plain; charset=utf8"}
ret = call_wsgi_app_kwargs(self.app, "echo_string", headers, s="string")
assert ret == b"string"
开发者ID:akash0675,项目名称:spyne,代码行数:4,代码来源:test_http.py
示例16: test_complex_array
def test_complex_array(self):
v = [
CM(i=1, s='a'),
CM(i=2, s='b'),
CM(i=3, s='c'),
CM(i=4, s='d'),
]
class SomeService(ServiceBase):
@srpc(_returns=Array(CM))
def some_call():
return v
app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
out_protocol=HtmlRowTable())
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server)
show(html.fromstring(out_string), 'TestHtmlRowTable.test_complex_array')
#FIXME: Needs a proper test with xpaths and all.
assert out_string == \
'<div xmlns="http://www.w3.org/1999/xhtml">' \
'<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
'<tbody>' \
'<tr>' \
'<th class="i">i</th>' \
'<td class="i">1</td>' \
'</tr>' \
'<tr>' \
'<th class="s">s</th>' \
'<td class="s">a</td>' \
'</tr>' \
'</tbody>' \
'</table>' \
'<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
'<tbody>' \
'<tr>' \
'<th class="i">i</th>' \
'<td class="i">2</td>' \
'</tr>' \
'<tr>' \
'<th class="s">s</th>' \
'<td class="s">b</td>' \
'</tr>' \
'</tbody>' \
'</table>' \
'<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
'<tbody>' \
'<tr>' \
'<th class="i">i</th>' \
'<td class="i">3</td>' \
'</tr>' \
'<tr>' \
'<th class="s">s</th>' \
'<td class="s">c</td>' \
'</tr>' \
'</tbody>' \
'</table>' \
'<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
'<tbody>' \
'<tr>' \
'<th class="i">i</th>' \
'<td class="i">4</td>' \
'</tr>' \
'<tr>' \
'<th class="s">s</th>' \
'<td class="s">d</td>' \
'</tr>' \
'</tbody>' \
'</table>' \
'</div>'
开发者ID:lanwan,项目名称:spyne,代码行数:70,代码来源:test_html_table.py
示例17: test_complex
def test_complex(self):
class SomeService(ServiceBase):
@srpc(CCM, _returns=CCM)
def some_call(ccm):
return ccm
app = Application(
[SomeService],
"tns",
in_protocol=HttpRpc(hier_delim="_"),
out_protocol=HtmlRowTable(field_name_attr="class"),
)
server = WsgiApplication(app)
out_string = call_wsgi_app_kwargs(server, "some_call", ccm_c_s="abc", ccm_c_i="123", ccm_i="456", ccm_s="def")
elt = html.fromstring(out_string)
show(elt, "TestHtmlRowTable.test_complex")
# Here's what this is supposed to return
"""
<table class="CCM">
<tbody>
<tr>
<th class="i">i</th>
<td class="i">456</td>
</tr>
<tr class="c">
<th class="c">c</th>
<td class="c">
<table class="c">
<tbody>
<tr>
<th class="i">i</th>
<td class="i">123</td>
</tr>
<tr>
<th class="s">s</th>
<td class="s">abc</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th class="s">s</th>
<td class="s">def</td>
</tr>
</tbody>
</table>
"""
print(html.tostring(elt, pretty_print=True))
resp = elt.find_class("CCM")
assert len(resp) == 1
assert elt.xpath('tbody/tr/th[@class="i"]/text()')[0] == "i"
assert elt.xpath('tbody/tr/td[@class="i"]/text()')[0] == "456"
assert elt.xpath('tbody/tr/td[@class="c"]//th[@class="i"]/text()')[0] == "i"
assert elt.xpath('tbody/tr/td[@class="c"]//td[@class="i"]/text()')[0] == "123"
assert elt.xpath('tbody/tr/td[@class="c"]//th[@class="s"]/text()')[0] == "s"
assert elt.xpath('tbody/tr/td[@class="c"]//td[@class="s"]/text()')[0] == "abc"
assert elt.xpath('tbody/tr/th[@class="s"]/text()')[0] == "s"
assert elt.xpath('tbody/tr/td[@class="s"]/text()')[0] == "def"
开发者ID:sunpoet,项目名称:spyne,代码行数:67,代码来源:test_html_table.py
注:本文中的spyne.util.test.call_wsgi_app_kwargs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论