summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-03-15 16:27:57 -0700
committerTim Graham <timograham@gmail.com>2019-03-15 19:27:57 -0400
commit95b7699ffc4bdb32a504fccfd127f1b76a8a1d1c (patch)
tree436ce672484e93cae672f96d8f91d88ed4e02912 /tests
parent58ad030d05fa50cfed327368ab61defca3303e02 (diff)
Cleaned up exception message checking in some tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/auth_tests/test_views.py2
-rw-r--r--tests/file_uploads/tests.py4
-rw-r--r--tests/many_to_many/tests.py3
-rw-r--r--tests/test_client/tests.py3
-rw-r--r--tests/urlpatterns_reverse/tests.py10
-rw-r--r--tests/utils_tests/test_autoreload.py2
6 files changed, 15 insertions, 9 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index f738a73e64..99de78e44d 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -854,7 +854,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):
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index 2824b6eb42..7b31d369b2 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -385,8 +385,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):
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 098cd29e46..f0156bbe8d 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -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)
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 02f5113890..84d245c05e 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -829,8 +829,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:
diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
index 77745976af..ba8cbedf4a 100644
--- a/tests/urlpatterns_reverse/tests.py
+++ b/tests/urlpatterns_reverse/tests.py
@@ -997,8 +997,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(
@@ -1070,7 +1073,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/')
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 3a8bf99983..1f3bc0c95b 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -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()