本文整理汇总了Python中pecan.rest.RestController方法的典型用法代码示例。如果您正苦于以下问题:Python rest.RestController方法的具体用法?Python rest.RestController怎么用?Python rest.RestController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pecan.rest
的用法示例。
在下文中一共展示了rest.RestController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getall_with_trailing_slash
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_getall_with_trailing_slash(self):
class ThingsController(RestController):
data = ['zero', 'one', 'two', 'three']
@expose('json')
def get_all(self):
return dict(items=self.data)
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# test get_all
r = app.get('/things/')
assert r.status_int == 200
assert r.body == b_(dumps(dict(items=ThingsController.data)))
示例2: test_nested_rest_with_default
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_nested_rest_with_default(self):
class FooController(RestController):
@expose()
def _default(self, *remainder):
return "DEFAULT %s" % remainder
class RootController(RestController):
foo = FooController()
app = TestApp(make_app(RootController()))
r = app.get('/foo/missing')
assert r.status_int == 200
assert r.body == b_("DEFAULT missing")
示例3: test_rest_with_non_utf_8_body
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_rest_with_non_utf_8_body(self):
if PY3:
# webob+PY3 doesn't suffer from this bug; the POST parsing in PY3
# seems to more gracefully detect the bytestring
return
class FooController(RestController):
@expose()
def post(self):
return "POST"
class RootController(RestController):
foo = FooController()
app = TestApp(make_app(RootController()))
data = struct.pack('255h', *range(0, 255))
r = app.post('/foo/', data, expect_errors=True)
assert r.status_int == 400
示例4: test_405_with_lookup
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_405_with_lookup(self):
class LookupController(RestController):
def __init__(self, _id):
self._id = _id
@expose()
def get_all(self):
return 'ID: %s' % self._id
class ThingsController(RestController):
@expose()
def _lookup(self, _id, *remainder):
return LookupController(_id), remainder
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# these should 405
for path in ('/things', '/things/'):
r = app.get(path, expect_errors=True)
assert r.status_int == 405
r = app.get('/things/foo')
assert r.status_int == 200
assert r.body == b_('ID: foo')
示例5: test_getall_with_lookup
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_getall_with_lookup(self):
class LookupController(RestController):
def __init__(self, _id):
self._id = _id
@expose()
def get_all(self):
return 'ID: %s' % self._id
class ThingsController(RestController):
data = ['zero', 'one', 'two', 'three']
@expose()
def _lookup(self, _id, *remainder):
return LookupController(_id), remainder
@expose('json')
def get_all(self):
return dict(items=self.data)
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# test get_all
for path in ('/things', '/things/'):
r = app.get(path)
assert r.status_int == 200
assert r.body == b_(dumps(dict(items=ThingsController.data)))
r = app.get('/things/foo')
assert r.status_int == 200
assert r.body == b_('ID: foo')
示例6: test_get_with_var_args
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_get_with_var_args(self):
class OthersController(object):
@expose()
def index(self, one, two, three):
return 'NESTED: %s, %s, %s' % (one, two, three)
class ThingsController(RestController):
others = OthersController()
@expose()
def get_one(self, *args):
return ', '.join(args)
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# test get request
r = app.get('/things/one/two/three')
assert r.status_int == 200
assert r.body == b_('one, two, three')
# test nested get request
r = app.get('/things/one/two/three/others/')
assert r.status_int == 200
assert r.body == b_('NESTED: one, two, three')
示例7: test_sub_nested_rest
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_sub_nested_rest(self):
class BazsController(RestController):
data = [[['zero-zero-zero']]]
@expose()
def get_one(self, foo_id, bar_id, id):
return self.data[int(foo_id)][int(bar_id)][int(id)]
class BarsController(RestController):
data = [['zero-zero']]
bazs = BazsController()
@expose()
def get_one(self, foo_id, id):
return self.data[int(foo_id)][int(id)]
class FoosController(RestController):
data = ['zero']
bars = BarsController()
@expose()
def get_one(self, id):
return self.data[int(id)]
class RootController(object):
foos = FoosController()
# create the app
app = TestApp(make_app(RootController()))
# test sub-nested get_one
r = app.get('/foos/0/bars/0/bazs/0')
assert r.status_int == 200
assert r.body == b_('zero-zero-zero')
示例8: test_method_not_allowed_get
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_method_not_allowed_get(self):
class ThingsController(RestController):
@expose()
def put(self, id_, value):
response.status = 200
@expose()
def delete(self, id_):
response.status = 200
app = TestApp(make_app(ThingsController()))
r = app.get('/', status=405)
assert r.status_int == 405
assert r.headers['Allow'] == 'DELETE, PUT'
示例9: test_method_not_allowed_post
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_method_not_allowed_post(self):
class ThingsController(RestController):
@expose()
def get_one(self):
return dict()
app = TestApp(make_app(ThingsController()))
r = app.post('/', {'foo': 'bar'}, status=405)
assert r.status_int == 405
assert r.headers['Allow'] == 'GET'
示例10: test_method_not_allowed_put
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_method_not_allowed_put(self):
class ThingsController(RestController):
@expose()
def get_one(self):
return dict()
app = TestApp(make_app(ThingsController()))
r = app.put('/123', status=405)
assert r.status_int == 405
assert r.headers['Allow'] == 'GET'
示例11: test_proper_allow_header_multiple_gets
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_proper_allow_header_multiple_gets(self):
class ThingsController(RestController):
@expose()
def get_all(self):
return dict()
@expose()
def get(self):
return dict()
app = TestApp(make_app(ThingsController()))
r = app.put('/123', status=405)
assert r.status_int == 405
assert r.headers['Allow'] == 'GET'
示例12: test_alternate_route
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_alternate_route(self):
class RootController(RestController):
@expose(route='some-path')
def get_all(self):
return "Hello, World!"
self.assertRaises(
ValueError,
RootController
)
示例13: setUp
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def setUp(self):
super(TestRestControllerStateAccess, self).setUp()
self.args = None
class RootController(rest.RestController):
@expose()
def _default(self, _id, *args, **kw):
return 'Default'
@expose()
def get_all(self, **kw):
return 'All'
@expose()
def get_one(self, _id, *args, **kw):
return 'One'
@expose()
def post(self, *args, **kw):
return 'POST'
@expose()
def put(self, _id, *args, **kw):
return 'PUT'
@expose()
def delete(self, _id, *args, **kw):
return 'DELETE'
class SimpleHook(PecanHook):
def before(inself, state):
self.args = (state.controller, state.arguments)
self.root = RootController()
self.app = TestApp(make_app(self.root, hooks=[SimpleHook()]))
示例14: test_simple_nested_rest
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_simple_nested_rest(self):
class BarController(RestController):
@expose()
def post(self):
return "BAR-POST"
@expose()
def delete(self, id_):
return "BAR-%s" % id_
class FooController(RestController):
bar = BarController()
@expose()
def post(self):
return "FOO-POST"
@expose()
def delete(self, id_):
return "FOO-%s" % id_
class RootController(object):
foo = FooController()
# create the app
app = TestApp(make_app(RootController()))
r = app.post('/foo')
assert r.status_int == 200
assert r.body == b_("FOO-POST")
r = app.delete('/foo/1')
assert r.status_int == 200
assert r.body == b_("FOO-1")
r = app.post('/foo/bar')
assert r.status_int == 200
assert r.body == b_("BAR-POST")
r = app.delete('/foo/bar/2')
assert r.status_int == 200
assert r.body == b_("BAR-2")
示例15: test_nested_get_all
# 需要导入模块: from pecan import rest [as 别名]
# 或者: from pecan.rest import RestController [as 别名]
def test_nested_get_all(self):
class BarsController(RestController):
@expose()
def get_one(self, foo_id, id):
return '4'
@expose()
def get_all(self, foo_id):
return '3'
class FoosController(RestController):
bars = BarsController()
@expose()
def get_one(self, id):
return '2'
@expose()
def get_all(self):
return '1'
class RootController(object):
foos = FoosController()
# create the app
app = TestApp(make_app(RootController()))
r = app.get('/foos/')
assert r.status_int == 200
assert r.body == b_('1')
r = app.get('/foos/1/')
assert r.status_int == 200
assert r.body == b_('2')
r = app.get('/foos/1/bars/')
assert r.status_int == 200
assert r.body == b_('3')
r = app.get('/foos/1/bars/2/')
assert r.status_int == 200
assert r.body == b_('4')
r = app.get('/foos/bars/', status=404)
assert r.status_int == 404
r = app.get('/foos/bars/1', status=404)
assert r.status_int == 404