本文整理汇总了Python中turbogears.testutil.createRequest函数的典型用法代码示例。如果您正苦于以下问题:Python createRequest函数的具体用法?Python createRequest怎么用?Python createRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flash_unicode
def test_flash_unicode(self):
"turbogears.flash with unicode objects should work"
testutil.createRequest("/flash_unicode?tg_format=json")
import simplejson
values = simplejson.loads(cherrypy.response.body[0])
assert values["tg_flash"]==u"\xfcnicode"
assert not cherrypy.response.simple_cookie.has_key("tg_flash")
示例2: test_rows_column_number
def test_rows_column_number(self):
#Control that the number of columns match the number of fields in the model
cherrypy.root.catwalk = CatWalk(browse)
testutil.createRequest("/catwalk/browse/?object_name=Artist&tg_format=json")
response = cherrypy.response.body[0]
values = simplejson.loads(response)
assert len(values['rows'][0]) == 4
示例3: test_recursiveErrorHandler
def test_recursiveErrorHandler(self):
""" Recursive error handler. """
testutil.createRequest("/recursiveerror?bar=abc")
self.failUnless("Recursive error handler" in cherrypy.response.body[0])
testutil.createRequest("/recursiveerror?bar=1")
self.failUnless("Recursive error provider" in
cherrypy.response.body[0])
示例4: test_jsonOutput
def test_jsonOutput(self):
testutil.createRequest("/test?tg_format=json")
import simplejson
values = simplejson.loads(cherrypy.response.body[0])
assert values == dict(title="Foobar", mybool=False, someval="niggles",
tg_flash=None)
assert cherrypy.response.headers["Content-Type"] == "text/javascript"
示例5: test_index_trailing_slash
def test_index_trailing_slash():
"If there is no trailing slash on an index method call, redirect"
cherrypy.root = SubApp()
cherrypy.root.foo = SubApp()
testutil.createRequest("/foo")
print cherrypy.response.status
assert cherrypy.response.status.startswith("302")
示例6: test_approotsWithPath
def test_approotsWithPath(self):
turbogears.config.update({"server.webpath" : "/coolsite/root"})
turbogears.startup.startTurboGears()
testutil.createRequest("/coolsite/root/subthing/")
print cherrypy.tree.mount_point()
self.failUnlessEqual("/coolsite/root/subthing/foo",
url("/foo"))
示例7: test_required_fields
def test_required_fields():
"""
Required field are automatically discovered from the form validator and marked
with the "requiredfield" css class.
"""
class MyFields(widgets.WidgetsList):
name = widgets.TextField(validator=validators.String())
comment = widgets.TextArea(validator=validators.String(not_empty=True))
form = widgets.TableForm(fields=MyFields())
class MyRoot(turbogears.controllers.RootController):
def test(self):
return dict(form=form)
test = turbogears.expose(template=".form")(test)
cherrypy.root = MyRoot()
testutil.createRequest("/test")
output = cherrypy.response.body[0].lower()
print output
name_p = 'name="comment"'
class_p = 'class="textarea requiredfield"'
assert (re.compile('.*'.join([class_p, name_p])).search(output) or
re.compile('.*'.join([name_p, class_p])).search(output)
)
name_p = 'name="name"'
class_p = 'class="textfield"'
assert (re.compile('.*'.join([class_p, name_p])).search(output) or
re.compile('.*'.join([name_p, class_p])).search(output)
)
示例8: test_flash_plain
def test_flash_plain(self):
"turbogears.flash with strings should work"
testutil.createRequest("/flash_plain?tg_format=json")
import simplejson
values = simplejson.loads(cherrypy.response.body[0])
assert values["tg_flash"]=="plain"
assert not cherrypy.response.simple_cookie.has_key("tg_flash")
示例9: test_runwithtrans
def test_runwithtrans(self):
"run_with_transaction is called only on topmost exposed method"
oldrwt = database.run_with_transaction
database.run_with_transaction = cherrypy.root.rwt
testutil.createRequest("/callsanother")
database.run_with_transaction = oldrwt
assert cherrypy.root.value
assert cherrypy.root.rwt_called == 1
示例10: test_defaultFormat
def test_defaultFormat(self):
"""The default format can be set via expose"""
testutil.createRequest("/returnjson")
firstline = cherrypy.response.body[0]
assert '"title": "Foobar"' in firstline
testutil.createRequest("/returnjson?tg_format=html")
firstline = cherrypy.response.body[0]
assert '"title": "Foobar"' not in firstline
示例11: test_include_widgets
def test_include_widgets():
"Any widget Can be included everywhere by setting tg.include_widgets"
root = cherrypy.root
turbogears.config.update({"global":{"tg.include_widgets" : ["turbogears.mochikit"]}})
testutil.createRequest("/")
turbogears.config.update({"global":{"tg.include_widgets" : None}})
print cherrypy.response.body[0]
assert "MochiKit.js" in cherrypy.response.body[0]
示例12: test_form_translation
def test_form_translation():
"Form input is translated into properly converted parameters"
root = MyRoot()
cherrypy.root = root
testutil.createRequest("/testform?name=ed&date=11/05/2005&age=5")
assert root.name == "ed"
print root.age
assert root.age == 5
示例13: test_mochikit_everywhere
def test_mochikit_everywhere():
"MochiKit can be included everywhere by setting tg.mochikit_all"
root = cherrypy.root
turbogears.config.update({"global":{"tg.mochikit_all" : True}})
testutil.createRequest("/")
turbogears.config.update({"global":{"tg.mochikit_all" : False}})
print cherrypy.response.body[0]
assert "MochiKit.js" in cherrypy.response.body[0]
示例14: test_implicitErrorHandler
def test_implicitErrorHandler(self):
""" Implicit error handling. """
testutil.createRequest("/impliciterror?bar=abc")
self.failUnless("Implicit error handler" in
cherrypy.response.body[0])
testutil.createRequest("/impliciterror?bar=1")
self.failUnless("Implicit error provider" in
cherrypy.response.body[0])
示例15: test_set_kid_outputformat_in_config
def test_set_kid_outputformat_in_config(self):
"the outputformat for kid can be set in the config"
turbogears.config.update({'kid.outputformat': 'xhtml'})
testutil.createRequest('/test')
assert '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ' in cherrypy.response.body[0]
turbogears.config.update({'kid.outputformat': 'html'})
testutil.createRequest('/test')
assert '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ' in cherrypy.response.body[0]