diff options
| author | Chris McDonough <chrism@plope.com> | 2012-07-29 14:54:34 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-07-29 14:54:34 -0400 |
| commit | 61a57eaaa82c3e001ee3b0102e7a1b6cdb42532d (patch) | |
| tree | b5a918a8a5301c5010cfd53482a2c39c0bae1645 | |
| parent | 8e45c9df2bf35428f47e106f932d996f18b45395 (diff) | |
| download | pyramid-61a57eaaa82c3e001ee3b0102e7a1b6cdb42532d.tar.gz pyramid-61a57eaaa82c3e001ee3b0102e7a1b6cdb42532d.tar.bz2 pyramid-61a57eaaa82c3e001ee3b0102e7a1b6cdb42532d.zip | |
- 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.
- Fixes issue #502 and issue #519.
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index c6afaf0c7..ecb2bf659 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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. diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 9b46f83c9..ebf1dfb39 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -2905,6 +2905,7 @@ class TestViewDeriver(unittest.TestCase): view = lambda *arg: response def predicate1(context, request): return False + predicate1.__text__ = 'text' deriver = self._makeOne(predicates=[predicate1]) result = deriver(view) request = self._makeRequest() @@ -2912,7 +2913,8 @@ class TestViewDeriver(unittest.TestCase): 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,6 +2923,7 @@ class TestViewDeriver(unittest.TestCase): def myview(request): pass def predicate1(context, request): return False + predicate1.__text__ = 'text' deriver = self._makeOne(predicates=[predicate1]) result = deriver(myview) request = self._makeRequest() @@ -2928,7 +2931,29 @@ class TestViewDeriver(unittest.TestCase): 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 @@ class TestViewDeriver(unittest.TestCase): 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() |
