本文整理汇总了Python中testapi.request函数的典型用法代码示例。如果您正苦于以下问题:Python request函数的具体用法?Python request怎么用?Python request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rw_corrupt
def test_rw_corrupt(self):
testapi.request(1)
try:
repeating_widget.validate({"a": {"a": "b"}})
assert False
except twc.ValidationError:
pass
示例2: test_mime_type
def test_mime_type(self):
testapi.request(1, mw)
wa = twc.JSLink(modname='tw2.core', filename='test_templates/simple_genshi.html').req()
wa.prepare()
resp = tst_mw.get(wa.link)
assert(resp.content_type == 'text/html')
assert(resp.charset == 'UTF-8')
示例3: test_round_trip
def test_round_trip(self):
test = twc.CompoundWidget(
id="a",
children=[
twc.DisplayOnlyWidget(child=twc.RepeatingWidget(id="q", child=twc.Widget)),
twc.CompoundWidget(id="cc", children=[twc.Widget(id="d"), twc.Widget(id="e")]),
],
)
widgets = [
test.children[0].child.rwbc[0],
test.children[0].child.rwbc[1],
test.children.cc.children.d,
test.children.cc.children.e,
]
data = dict((w.compound_id, "test%d" % i) for i, w in enumerate(widgets))
testapi.request(1)
vdata = test.validate(data)
test = twc.core.request_local()["validated_widget"]
widgets = [
test.children[0].child.children[0],
test.children[0].child.children[1],
test.children.cc.children.d,
test.children.cc.children.e,
]
for i, w in enumerate(widgets):
eq_(w.value, "test%d" % i)
示例4: test_compound_corrupt
def test_compound_corrupt(self):
testapi.request(1)
try:
compound_widget.validate({'a':[]})
assert(False)
except twc.ValidationError:
pass
示例5: test_rw_propagate
def test_rw_propagate(self):
test = twc.RepeatingWidget(child=twc.Widget).req()
testapi.request(1)
test.value = ['a', 'b', 'c']
test.prepare()
assert(len(test.children) == 3)
assert([w.value for w in test.children] == ['a', 'b', 'c'])
示例6: test_rw_corrupt
def test_rw_corrupt(self):
testapi.request(1)
try:
repeating_widget.validate({'a':{'a':'b'}})
assert(False)
except twc.ValidationError:
pass
示例7: test_rw_child_fail
def test_rw_child_fail(self):
testapi.request(1)
try:
repeating_widget.validate({'a':['test', '']})
assert(False)
except twc.ValidationError, e:
pass
示例8: test_round_trip
def test_round_trip(self):
test = twc.CompoundWidget(id='a', children=[
twc.DisplayOnlyWidget(child=
twc.RepeatingWidget(id='q', child=twc.Widget)
),
twc.CompoundWidget(id='cc', children=[
twc.Widget(id='d'),
twc.Widget(id='e'),
])
])
widgets = [
test.children[0].child.rwbc[0],
test.children[0].child.rwbc[1],
test.children.cc.children.d,
test.children.cc.children.e,
]
data = dict((w.compound_id, 'test%d' % i) for i,w in enumerate(widgets))
testapi.request(1)
vdata = test.validate(data)
test = twc.core.request_local()['validated_widget']
widgets = [
test.children[0].child.children[0],
test.children[0].child.children[1],
test.children.cc.children.d,
test.children.cc.children.e,
]
for i,w in enumerate(widgets):
eq_(w.value, 'test%d' % i)
示例9: testTGStyleController
def testTGStyleController(self):
""" Test turbogears style dispatch """
from tw2.core.middleware import ControllersApp, TwMiddleware
from tw2.core.compat import TGStyleController
controller_response = Response("CONTROLLER")
class WidgetMock(TGStyleController):
id = "fake"
class Controller(object):
def foobar(self, request):
return controller_response
mock = WidgetMock()
mw = TwMiddleware(None, controller_prefix="goo")
testapi.request(1, mw)
ca = ControllersApp()
ca.register(mock)
res = ca(Request.blank("/%s/%s/foobar" % (mw.config.controller_prefix, mock.id)))
self.assert_(res.status_int == 200, res.status_int)
self.assert_(res.body == controller_response.body, res.body)
res = ca(Request.blank("/%s/404" % mw.config.controller_prefix))
self.assert_(res.status_int == 404, res.status_int)
res = ca(Request.blank("%s/404" % mw.config.controller_prefix))
self.assert_(res.status_int == 404, res.status_int)
示例10: testControllerAppWithId
def testControllerAppWithId(self):
"""
controllerapp should dispatch to an object having id, and a
request method taking a webob request based on path_info of
request.
"""
from tw2.core.middleware import ControllersApp, TwMiddleware
controller_response = Response("CONTROLLER")
class WidgetMock(object):
def __init__(self):
self.id = "fake"
def request(self, request):
return controller_response
mock = WidgetMock()
mw = TwMiddleware(None, controller_prefix="goo")
testapi.request(1, mw)
ca = ControllersApp()
ca.register(mock)
res = ca(Request.blank("/%s/%s" % (mw.config.controller_prefix, mock.id)))
self.assert_(res.status_int == 200, res.status_int)
self.assert_(res.body == controller_response.body, res.body)
res = ca(Request.blank("/%s/404" % mw.config.controller_prefix))
self.assert_(res.status_int == 404, res.status_int)
res = ca(Request.blank("%s/404" % mw.config.controller_prefix))
self.assert_(res.status_int == 404, res.status_int)
示例11: test_rw_propagate
def test_rw_propagate(self):
test = twc.RepeatingWidget(child=Child).req()
testapi.request(1)
test.value = ["a", "b", "c"]
test.prepare()
assert len(test.children) == 3
assert [w.value for w in test.children] == ["a", "b", "c"]
示例12: _check_render
def _check_render(self, template, data, expected, engine=None):
if engine:
mw = twc.make_middleware(None, preferred_rendering_engines=[engine])
testapi.request(1, mw)
out = twc.template.EngineManager().render(template, 'string', data)
assert(isinstance(out, unicode))
assert out == expected, out
示例13: test_rw_pass
def test_rw_pass(self):
testapi.request(1)
rep = repeating_widget.req()
inp = ["test", "test2"]
out = rep._validate(inp)
assert inp == out
assert rep.children[0].value == "test"
assert rep.children[1].value == "test2"
示例14: test_compound_pass
def test_compound_pass(self):
testapi.request(1)
inp = {"a": {"b": "test", "c": "test2"}}
out = compound_widget.validate(inp)
eq_(out, inp["a"])
cw = twc.core.request_local()["validated_widget"]
assert cw.children.b.value == "test"
assert cw.children.c.value == "test2"
示例15: test_rwb
def test_rwb(self):
test = twc.RepeatingWidget(child=twc.Widget).req()
testapi.request(1)
test.value = ['a', 'b', 'c']
test.prepare()
for i in range(4):
assert(test.children[i].repetition == i)
assert(test.children[0] is not test.children[1])