Fix a trailing slash bug for `RestController`s that have a `_lookup` method.
Change-Id: Ibd025fc52d37f58644de23cf283afd8d4d55e2d1 Closes-Bug: #1280003
This commit is contained in:
parent
1335f2c19d
commit
573846e012
|
@ -1,6 +1,7 @@
|
|||
from inspect import getargspec, ismethod
|
||||
|
||||
from webob import exc
|
||||
import six
|
||||
|
||||
from .core import abort, request
|
||||
from .decorators import expose
|
||||
|
@ -63,6 +64,9 @@ class RestController(object):
|
|||
try:
|
||||
result = handler(method, args)
|
||||
|
||||
# filter empty strings from the arg list
|
||||
args = list(six.moves.filter(bool, args))
|
||||
|
||||
#
|
||||
# If the signature of the handler does not match the number
|
||||
# of remaining positional arguments, attempt to handle
|
||||
|
|
|
@ -289,6 +289,45 @@ class TestRestController(PecanTestCase):
|
|||
assert r.status_int == 200
|
||||
assert r.body == b_(dumps(dict(items=ThingsController.data)))
|
||||
|
||||
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')
|
||||
|
||||
def test_simple_nested_rest(self):
|
||||
|
||||
class BarController(RestController):
|
||||
|
|
Loading…
Reference in New Issue