diff options
| author | Mads Jensen <mje@inducks.org> | 2017-05-28 21:37:21 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-29 19:07:23 -0400 |
| commit | a51c4de1945be2225f20fad794cfb52d8f1f9236 (patch) | |
| tree | 36386b70a27cf027a8a491de319c3e59e0d3d0cd /tests/auth_tests | |
| parent | 38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff) | |
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/auth_tests')
| -rw-r--r-- | tests/auth_tests/test_auth_backends.py | 12 | ||||
| -rw-r--r-- | tests/auth_tests/test_basic.py | 9 | ||||
| -rw-r--r-- | tests/auth_tests/test_management.py | 5 |
3 files changed, 20 insertions, 6 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py index ea9ddd426c..744f8ad817 100644 --- a/tests/auth_tests/test_auth_backends.py +++ b/tests/auth_tests/test_auth_backends.py @@ -445,7 +445,11 @@ class NoBackendsTest(TestCase): self.user = User.objects.create_user('test', 'test@example.com', 'test') def test_raises_exception(self): - with self.assertRaises(ImproperlyConfigured): + msg = ( + 'No authentication backends have been defined. ' + 'Does AUTHENTICATION_BACKENDS contain anything?' + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): self.user.has_perm(('perm', TestObj())) @@ -626,7 +630,11 @@ class ImproperlyConfiguredUserModelTest(TestCase): request = HttpRequest() request.session = self.client.session - with self.assertRaises(ImproperlyConfigured): + msg = ( + "AUTH_USER_MODEL refers to model 'thismodel.doesntexist' " + "that has not been installed" + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): get_user(request) diff --git a/tests/auth_tests/test_basic.py b/tests/auth_tests/test_basic.py index b2c70faffb..80a56f8ca3 100644 --- a/tests/auth_tests/test_basic.py +++ b/tests/auth_tests/test_basic.py @@ -97,13 +97,18 @@ class BasicTestCase(TestCase): @override_settings(AUTH_USER_MODEL='badsetting') def test_swappable_user_bad_setting(self): "The alternate user setting must point to something in the format app.model" - with self.assertRaises(ImproperlyConfigured): + msg = "AUTH_USER_MODEL must be of the form 'app_label.model_name'" + with self.assertRaisesMessage(ImproperlyConfigured, msg): get_user_model() @override_settings(AUTH_USER_MODEL='thismodel.doesntexist') def test_swappable_user_nonexistent_model(self): "The current user model must point to an installed model" - with self.assertRaises(ImproperlyConfigured): + msg = ( + "AUTH_USER_MODEL refers to model 'thismodel.doesntexist' " + "that has not been installed" + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): get_user_model() def test_user_verbose_names_translatable(self): diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index c4368b3bcf..c43091d932 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -158,7 +158,8 @@ class ChangepasswordManagementCommandTestCase(TestCase): A CommandError should be thrown by handle() if the user enters in mismatched passwords three times. """ - with self.assertRaises(CommandError): + msg = "Aborting password change for user 'joe' after 3 attempts" + with self.assertRaisesMessage(CommandError, msg): call_command('changepassword', username='joe', stdout=self.stdout, stderr=self.stderr) @mock.patch.object(changepassword.Command, '_get_pass', return_value='1234567890') @@ -316,7 +317,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase): # We skip validation because the temporary substitution of the # swappable User model messes with validation. new_io = StringIO() - with self.assertRaises(CommandError): + with self.assertRaisesMessage(CommandError, 'You must use --email with --noinput.'): call_command( "createsuperuser", interactive=False, |
