Merge pull request #86 from jd/jd/no-warning
routing: stop printing warning if the user passes a wrong URL
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import re
|
||||
import warnings
|
||||
from inspect import getmembers, ismethod
|
||||
@@ -12,6 +13,8 @@ __all__ = ['lookup_controller', 'find_object', 'route']
|
||||
__observed_controllers__ = set()
|
||||
__custom_routes__ = {}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def route(*args):
|
||||
"""
|
||||
@@ -170,18 +173,16 @@ def lookup_controller(obj, remainder, request=None):
|
||||
def handle_lookup_traversal(obj, args):
|
||||
try:
|
||||
result = obj(*args)
|
||||
except TypeError as te:
|
||||
logger.debug('Got exception calling lookup(): %s (%s)',
|
||||
te, te.args)
|
||||
else:
|
||||
if result:
|
||||
prev_obj = obj
|
||||
obj, remainder = result
|
||||
# crossing controller boundary
|
||||
cross_boundary(prev_obj, obj)
|
||||
return result
|
||||
except TypeError as te:
|
||||
msg = 'Got exception calling lookup(): %s (%s)'
|
||||
warnings.warn(
|
||||
msg % (te, te.args),
|
||||
RuntimeWarning
|
||||
)
|
||||
|
||||
|
||||
def find_object(obj, remainder, notfound_handlers, request):
|
||||
|
||||
@@ -339,11 +339,20 @@ class TestLookups(PecanTestCase):
|
||||
def _lookup(self, someID):
|
||||
return 'Bad arg spec' # pragma: nocover
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
app = TestApp(Pecan(RootController()))
|
||||
r = app.get('/foo/bar', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
app = TestApp(Pecan(RootController()))
|
||||
r = app.get('/foo/bar', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
|
||||
def test_lookup_with_wrong_return(self):
|
||||
class RootController(object):
|
||||
@expose()
|
||||
def _lookup(self, someID, *remainder):
|
||||
return 1
|
||||
|
||||
app = TestApp(Pecan(RootController()))
|
||||
self.assertRaises(TypeError,
|
||||
app.get,
|
||||
'/foo/bar', expect_errors=True)
|
||||
|
||||
|
||||
class TestCanonicalLookups(PecanTestCase):
|
||||
|
||||
Reference in New Issue
Block a user