Permalink
Browse files

- When there is a predicate mismatch exception (seen when no view mat…

…ches for

  a given request due to predicates not working), the exception now contains
  a textual description of the predicate which didn't match.

- Fixes issue #502 and issue #519.
  • Loading branch information...
1 parent 8e45c9d commit 61a57eaaa82c3e001ee3b0102e7a1b6cdb42532d @mcdonc mcdonc committed Jul 29, 2012
Showing with 33 additions and 2 deletions.
  1. +4 −0 CHANGES.txt
  2. +29 −2 pyramid/tests/test_config/test_views.py
View
@@ -54,3 +54,7 @@ Features
result for the view being called. The uri format using an asset spec is
package:path/to/template#defname.mako. The old way of returning a tuple
from the view is supported for backward compatibility, ('defname', {}).
+
+- When there is a predicate mismatch exception (seen when no view matches for
+ a given request due to predicates not working), the exception now contains
+ a textual description of the predicate which didn't match.
@@ -2905,14 +2905,16 @@ def test_predicate_mismatch_view_has_no_name(self):
view = lambda *arg: response
def predicate1(context, request):
return False
+ predicate1.__text__ = 'text'
deriver = self._makeOne(predicates=[predicate1])
result = deriver(view)
request = self._makeRequest()
request.method = 'POST'
try:
result(None, None)
except PredicateMismatch as e:
- self.assertEqual(e.detail, 'predicate mismatch for view <lambda>')
+ self.assertEqual(e.detail,
+ 'predicate mismatch for view <lambda> (text)')
else: # pragma: no cover
raise AssertionError
@@ -2921,14 +2923,37 @@ def test_predicate_mismatch_view_has_name(self):
def myview(request): pass
def predicate1(context, request):
return False
+ predicate1.__text__ = 'text'
deriver = self._makeOne(predicates=[predicate1])
result = deriver(myview)
request = self._makeRequest()
request.method = 'POST'
try:
result(None, None)
except PredicateMismatch as e:
- self.assertEqual(e.detail, 'predicate mismatch for view myview')
+ self.assertEqual(e.detail,
+ 'predicate mismatch for view myview (text)')
+ else: # pragma: no cover
+ raise AssertionError
+
+ def test_predicate_mismatch_exception_has_text_in_detail(self):
+ from pyramid.exceptions import PredicateMismatch
+ def myview(request): pass
+ def predicate1(context, request):
+ return True
+ predicate1.__text__ = 'pred1'
+ def predicate2(context, request):
+ return False
+ predicate2.__text__ = 'pred2'
+ deriver = self._makeOne(predicates=[predicate1, predicate2])
+ result = deriver(myview)
+ request = self._makeRequest()
+ request.method = 'POST'
+ try:
+ result(None, None)
+ except PredicateMismatch as e:
+ self.assertEqual(e.detail,
+ 'predicate mismatch for view myview (pred2)')
else: # pragma: no cover
raise AssertionError
@@ -2974,9 +2999,11 @@ def test_with_predicates_notall(self):
def predicate1(context, request):
predicates.append(True)
return True
+ predicate1.__text__ = 'text'
def predicate2(context, request):
predicates.append(True)
return False
+ predicate2.__text__ = 'text'
deriver = self._makeOne(predicates=[predicate1, predicate2])
result = deriver(view)
request = self._makeRequest()

0 comments on commit 61a57ea

Please sign in to comment.