[2.2.x] Cleaned up exception message checking in some tests.
Backport of 95b7699ffc
from master.
This commit is contained in:
parent
985e6c224b
commit
87fad5a392
|
@ -855,7 +855,7 @@ class LoginRedirectAuthenticatedUser(AuthViewsTestCase):
|
|||
self.login()
|
||||
msg = (
|
||||
"Redirection loop for authenticated user detected. Check that "
|
||||
"your LOGIN_REDIRECT_URL doesn't point to a login page"
|
||||
"your LOGIN_REDIRECT_URL doesn't point to a login page."
|
||||
)
|
||||
with self.settings(LOGIN_REDIRECT_URL=self.do_redirect_url):
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
|
|
@ -386,8 +386,8 @@ class FileUploadTests(TestCase):
|
|||
file.write(b'a' * (2 ** 21))
|
||||
file.seek(0)
|
||||
|
||||
# AttributeError: You cannot alter upload handlers after the upload has been processed.
|
||||
with self.assertRaises(AttributeError):
|
||||
msg = 'You cannot alter upload handlers after the upload has been processed.'
|
||||
with self.assertRaisesMessage(AttributeError, msg):
|
||||
self.client.post('/quota/broken/', {'f': file})
|
||||
|
||||
def test_fileupload_getlist(self):
|
||||
|
|
|
@ -63,7 +63,8 @@ class ManyToManyTests(TestCase):
|
|||
)
|
||||
|
||||
# Adding an object of the wrong type raises TypeError
|
||||
with self.assertRaisesMessage(TypeError, "'Publication' instance expected, got <Article"):
|
||||
msg = "'Publication' instance expected, got <Article: Django lets you create Web apps easily>"
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
with transaction.atomic():
|
||||
a6.publications.add(a5)
|
||||
|
||||
|
|
|
@ -815,8 +815,9 @@ class ClientTest(TestCase):
|
|||
|
||||
def test_response_raises_multi_arg_exception(self):
|
||||
"""A request may raise an exception with more than one required arg."""
|
||||
with self.assertRaises(TwoArgException):
|
||||
with self.assertRaises(TwoArgException) as cm:
|
||||
self.client.get('/two_arg_exception/')
|
||||
self.assertEqual(cm.exception.args, ('one', 'two'))
|
||||
|
||||
def test_uploading_temp_file(self):
|
||||
with tempfile.TemporaryFile() as test_file:
|
||||
|
|
|
@ -999,8 +999,11 @@ class RequestURLconfTests(SimpleTestCase):
|
|||
Test reversing an URL from the *default* URLconf from inside
|
||||
a response middleware.
|
||||
"""
|
||||
message = "Reverse for 'outer' not found."
|
||||
with self.assertRaisesMessage(NoReverseMatch, message):
|
||||
msg = (
|
||||
"Reverse for 'outer' not found. 'outer' is not a valid view "
|
||||
"function or pattern name."
|
||||
)
|
||||
with self.assertRaisesMessage(NoReverseMatch, msg):
|
||||
self.client.get('/second_test/')
|
||||
|
||||
@override_settings(
|
||||
|
@ -1072,7 +1075,8 @@ class DefaultErrorHandlerTests(SimpleTestCase):
|
|||
response = self.client.get('/test/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
with self.assertRaisesMessage(ValueError, "I don't think I'm getting good"):
|
||||
msg = "I don't think I'm getting good value for this view"
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
self.client.get('/bad_view/')
|
||||
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ class TestRaiseLastException(SimpleTestCase):
|
|||
exc_info = sys.exc_info()
|
||||
|
||||
with mock.patch('django.utils.autoreload._exception', exc_info):
|
||||
with self.assertRaises(MyException, msg='Test Message'):
|
||||
with self.assertRaisesMessage(MyException, 'Test Message'):
|
||||
autoreload.raise_last_exception()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue