diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-03-15 16:27:57 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-03-15 19:28:13 -0400 |
| commit | 87fad5a3925c39380f79643387cdc5adde1d8863 (patch) | |
| tree | 7df9bb4021ec73803e073f087388be92efc64533 /tests | |
| parent | 985e6c224be0681d7a753b9ded4646024d332bc7 (diff) | |
[2.2.x] Cleaned up exception message checking in some tests.
Backport of 95b7699ffc4bdb32a504fccfd127f1b76a8a1d1c from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_views.py | 2 | ||||
| -rw-r--r-- | tests/file_uploads/tests.py | 4 | ||||
| -rw-r--r-- | tests/many_to_many/tests.py | 3 | ||||
| -rw-r--r-- | tests/test_client/tests.py | 3 | ||||
| -rw-r--r-- | tests/urlpatterns_reverse/tests.py | 10 | ||||
| -rw-r--r-- | tests/utils_tests/test_autoreload.py | 2 |
6 files changed, 15 insertions, 9 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index 4949ce1bf4..e7ad1cbcdf 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -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): diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index fb333dcf13..ea4976dc0a 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -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): diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py index 933eb23a7a..71c5f92d8d 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 432865328f..aa4f0e94b5 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -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: diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index f902cffdac..72d4016d00 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -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/') 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() |
