diff options
Diffstat (limited to 'tests/auth_tests')
| -rw-r--r-- | tests/auth_tests/test_management.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index a941847474..ab8e8a60e0 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -427,8 +427,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): self.assertEqual(u.group, group) non_existent_email = 'mymail2@gmail.com' - with self.assertRaisesMessage(CommandError, - 'email instance with email %r does not exist.' % non_existent_email): + msg = 'email instance with email %r does not exist.' % non_existent_email + with self.assertRaisesMessage(CommandError, msg): call_command( 'createsuperuser', interactive=False, @@ -670,10 +670,12 @@ class PermissionTestCase(TestCase): # check duplicated default permission Permission._meta.permissions = [ ('change_permission', 'Can edit permission (duplicate)')] - six.assertRaisesRegex(self, CommandError, + msg = ( "The permission codename 'change_permission' clashes with a " - "builtin permission for model 'auth.Permission'.", - create_permissions, auth_app_config, verbosity=0) + "builtin permission for model 'auth.Permission'." + ) + with self.assertRaisesMessage(CommandError, msg): + create_permissions(auth_app_config, verbosity=0) # check duplicated custom permissions Permission._meta.permissions = [ @@ -681,10 +683,9 @@ class PermissionTestCase(TestCase): ('other_one', 'Some other permission'), ('my_custom_permission', 'Some permission with duplicate permission code'), ] - six.assertRaisesRegex(self, CommandError, - "The permission codename 'my_custom_permission' is duplicated for model " - "'auth.Permission'.", - create_permissions, auth_app_config, verbosity=0) + msg = "The permission codename 'my_custom_permission' is duplicated for model 'auth.Permission'." + with self.assertRaisesMessage(CommandError, msg): + create_permissions(auth_app_config, verbosity=0) # should not raise anything Permission._meta.permissions = [ @@ -723,9 +724,9 @@ class PermissionTestCase(TestCase): Permission.objects.filter(content_type=permission_content_type).delete() Permission._meta.verbose_name = "some ridiculously long verbose name that is out of control" * 5 - six.assertRaisesRegex(self, exceptions.ValidationError, - "The verbose_name of auth.permission is longer than 244 characters", - create_permissions, auth_app_config, verbosity=0) + msg = "The verbose_name of auth.permission is longer than 244 characters" + with self.assertRaisesMessage(exceptions.ValidationError, msg): + create_permissions(auth_app_config, verbosity=0) def test_custom_permission_name_length(self): auth_app_config = apps.get_app_config('auth') |
