From dad2150ebea0040f5b1a5721331f479121216dc5 Mon Sep 17 00:00:00 2001 From: Richard Barrell Date: Tue, 8 Nov 2011 16:39:19 -0800 Subject: Added a unit test that asserts that HTTPFound(location=None) throws a ValueError. --- pyramid/tests/test_httpexceptions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index 927d27733..d319a59a0 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -294,6 +294,16 @@ class Test_HTTPMove(unittest.TestCase): from pyramid.httpexceptions import _HTTPMove return _HTTPMove(*arg, **kw) + def test_it_location_none_valueerrors(self): + """ Constructing a HTTPMove instance with location=None should + throw a ValueError from __init__ so that a more-confusing + exception won't be thrown later from .prepare(environ) """ + try: + exc = self._makeOne(location=None) + self.assertEqual(1, 0) + except ValueError, e: + pass + def test_it_location_not_passed(self): exc = self._makeOne() self.assertEqual(exc.location, '') -- cgit v1.2.3 From 45b15a8fb327d18078b29f9517bdd08aec366a7b Mon Sep 17 00:00:00 2001 From: Richard Barrell Date: Tue, 8 Nov 2011 16:41:57 -0800 Subject: Raise a ValueError from HTTPFound.__init__() if location is None. --- pyramid/httpexceptions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 4dbca7021..bd745df87 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -434,6 +434,8 @@ ${html_comment}''') def __init__(self, location='', detail=None, headers=None, comment=None, body_template=None, **kw): + if location is None: + raise ValueError("HTTP redirects need a location to redirect to.") super(_HTTPMove, self).__init__( detail=detail, headers=headers, comment=comment, body_template=body_template, location=location, **kw) -- cgit v1.2.3 From d55ba532da4eb5a8c5d48f94397dcdd85ea785ea Mon Sep 17 00:00:00 2001 From: Richard Barrell Date: Tue, 8 Nov 2011 16:54:57 -0800 Subject: Rewrite my unit test to behave correctly w.r.t. different exception types. --- pyramid/tests/test_httpexceptions.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index d319a59a0..2cbe208cd 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -298,11 +298,8 @@ class Test_HTTPMove(unittest.TestCase): """ Constructing a HTTPMove instance with location=None should throw a ValueError from __init__ so that a more-confusing exception won't be thrown later from .prepare(environ) """ - try: + with self.assertRaises(ValueError): exc = self._makeOne(location=None) - self.assertEqual(1, 0) - except ValueError, e: - pass def test_it_location_not_passed(self): exc = self._makeOne() -- cgit v1.2.3 From dfbbe87219e848ea6f02a94926140d918beb088d Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 8 Nov 2011 17:02:27 -0800 Subject: the with statement doesnt work under py26; unit tests shouldnt show comments --- pyramid/tests/test_httpexceptions.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index 2cbe208cd..84485fadc 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -295,11 +295,10 @@ class Test_HTTPMove(unittest.TestCase): return _HTTPMove(*arg, **kw) def test_it_location_none_valueerrors(self): - """ Constructing a HTTPMove instance with location=None should - throw a ValueError from __init__ so that a more-confusing - exception won't be thrown later from .prepare(environ) """ - with self.assertRaises(ValueError): - exc = self._makeOne(location=None) + # Constructing a HTTPMove instance with location=None should + # throw a ValueError from __init__ so that a more-confusing + # exception won't be thrown later from .prepare(environ) + self.assertRaises(ValueError, self._makeOne, location=None) def test_it_location_not_passed(self): exc = self._makeOne() -- cgit v1.2.3