Loading tests/admin_filters/tests.py +6 −7 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.core.exceptions import ImproperlyConfigured from django.test import RequestFactory, TestCase, override_settings from django.utils import six from django.utils.encoding import force_text from .models import Book, Bookmark, Department, Employee, TaggedItem Loading Loading @@ -818,9 +817,9 @@ class ListFiltersTests(TestCase): """ modeladmin = DecadeFilterBookAdminWithoutTitle(Book, site) request = self.request_factory.get('/', {}) six.assertRaisesRegex(self, ImproperlyConfigured, "The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'.", self.get_changelist, request, Book, modeladmin) msg = "The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'." with self.assertRaisesMessage(ImproperlyConfigured, msg): self.get_changelist(request, Book, modeladmin) def test_simplelistfilter_without_parameter(self): """ Loading @@ -828,9 +827,9 @@ class ListFiltersTests(TestCase): """ modeladmin = DecadeFilterBookAdminWithoutParameter(Book, site) request = self.request_factory.get('/', {}) six.assertRaisesRegex(self, ImproperlyConfigured, "The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'.", self.get_changelist, request, Book, modeladmin) msg = "The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'." with self.assertRaisesMessage(ImproperlyConfigured, msg): self.get_changelist(request, Book, modeladmin) def test_simplelistfilter_with_none_returning_lookups(self): """ Loading tests/aggregation/tests.py +7 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ from django.db.models import ( ) from django.test import TestCase from django.test.utils import Approximate, CaptureQueriesContext from django.utils import six, timezone from django.utils import timezone from .models import Author, Book, Publisher, Store Loading Loading @@ -906,7 +906,7 @@ class AggregateTestCase(TestCase): self.assertEqual(book['price_sum'], Decimal("99999.80")) def test_nonaggregate_aggregation_throws(self): with six.assertRaisesRegex(self, TypeError, 'fail is not an aggregate expression'): with self.assertRaisesMessage(TypeError, 'fail is not an aggregate expression'): Book.objects.aggregate(fail=F('price')) def test_nonfield_annotation(self): Loading @@ -918,7 +918,7 @@ class AggregateTestCase(TestCase): self.assertEqual(book.val, 2) def test_missing_output_field_raises_error(self): with six.assertRaisesRegex(self, FieldError, 'Cannot resolve expression type, unknown output_field'): with self.assertRaisesMessage(FieldError, 'Cannot resolve expression type, unknown output_field'): Book.objects.annotate(val=Max(2)).first() def test_annotation_expressions(self): Loading Loading @@ -962,7 +962,7 @@ class AggregateTestCase(TestCase): self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)}) def test_combine_different_types(self): with six.assertRaisesRegex(self, FieldError, 'Expression contains mixed types. You must set output_field'): with self.assertRaisesMessage(FieldError, 'Expression contains mixed types. You must set output_field'): Book.objects.annotate(sums=Sum('rating') + Sum('pages') + Sum('price')).get(pk=self.b4.pk) b1 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'), Loading @@ -978,11 +978,11 @@ class AggregateTestCase(TestCase): self.assertEqual(b3.sums, Approximate(Decimal("383.69"), places=2)) def test_complex_aggregations_require_kwarg(self): with six.assertRaisesRegex(self, TypeError, 'Complex annotations require an alias'): with self.assertRaisesMessage(TypeError, 'Complex annotations require an alias'): Author.objects.annotate(Sum(F('age') + F('friends__age'))) with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'): with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'): Author.objects.aggregate(Sum('age') / Count('age')) with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'): with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'): Author.objects.aggregate(Sum(1)) def test_aggregate_over_complex_annotation(self): Loading tests/app_loading/tests.py +1 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import os from django.apps import apps from django.test import SimpleTestCase from django.test.utils import extend_sys_path from django.utils import six from django.utils._os import upath Loading Loading @@ -57,7 +56,7 @@ class EggLoadingTest(SimpleTestCase): """Loading an app from an egg that has an import error in its models module raises that error""" egg_name = '%s/brokenapp.egg' % self.egg_dir with extend_sys_path(egg_name): with six.assertRaisesRegex(self, ImportError, 'modelz'): with self.assertRaisesMessage(ImportError, 'modelz'): with self.settings(INSTALLED_APPS=['broken_app']): pass Loading tests/apps/tests.py +3 −3 Original line number Diff line number Diff line Loading @@ -159,12 +159,12 @@ class AppsTests(SimpleTestCase): self.assertEqual(apps.get_app_config('relabeled').name, 'apps') def test_duplicate_labels(self): with six.assertRaisesRegex(self, ImproperlyConfigured, "Application labels aren't unique"): with self.assertRaisesMessage(ImproperlyConfigured, "Application labels aren't unique"): with self.settings(INSTALLED_APPS=['apps.apps.PlainAppsConfig', 'apps']): pass def test_duplicate_names(self): with six.assertRaisesRegex(self, ImproperlyConfigured, "Application names aren't unique"): with self.assertRaisesMessage(ImproperlyConfigured, "Application names aren't unique"): with self.settings(INSTALLED_APPS=['apps.apps.RelabeledAppsConfig', 'apps']): pass Loading @@ -172,7 +172,7 @@ class AppsTests(SimpleTestCase): """ App discovery should preserve stack traces. Regression test for #22920. """ with six.assertRaisesRegex(self, ImportError, "Oops"): with self.assertRaisesMessage(ImportError, "Oops"): with self.settings(INSTALLED_APPS=['import_error_package']): pass Loading tests/auth_tests/test_management.py +13 −12 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 = [ Loading @@ -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 = [ Loading Loading @@ -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') Loading Loading
tests/admin_filters/tests.py +6 −7 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.core.exceptions import ImproperlyConfigured from django.test import RequestFactory, TestCase, override_settings from django.utils import six from django.utils.encoding import force_text from .models import Book, Bookmark, Department, Employee, TaggedItem Loading Loading @@ -818,9 +817,9 @@ class ListFiltersTests(TestCase): """ modeladmin = DecadeFilterBookAdminWithoutTitle(Book, site) request = self.request_factory.get('/', {}) six.assertRaisesRegex(self, ImproperlyConfigured, "The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'.", self.get_changelist, request, Book, modeladmin) msg = "The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'." with self.assertRaisesMessage(ImproperlyConfigured, msg): self.get_changelist(request, Book, modeladmin) def test_simplelistfilter_without_parameter(self): """ Loading @@ -828,9 +827,9 @@ class ListFiltersTests(TestCase): """ modeladmin = DecadeFilterBookAdminWithoutParameter(Book, site) request = self.request_factory.get('/', {}) six.assertRaisesRegex(self, ImproperlyConfigured, "The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'.", self.get_changelist, request, Book, modeladmin) msg = "The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'." with self.assertRaisesMessage(ImproperlyConfigured, msg): self.get_changelist(request, Book, modeladmin) def test_simplelistfilter_with_none_returning_lookups(self): """ Loading
tests/aggregation/tests.py +7 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ from django.db.models import ( ) from django.test import TestCase from django.test.utils import Approximate, CaptureQueriesContext from django.utils import six, timezone from django.utils import timezone from .models import Author, Book, Publisher, Store Loading Loading @@ -906,7 +906,7 @@ class AggregateTestCase(TestCase): self.assertEqual(book['price_sum'], Decimal("99999.80")) def test_nonaggregate_aggregation_throws(self): with six.assertRaisesRegex(self, TypeError, 'fail is not an aggregate expression'): with self.assertRaisesMessage(TypeError, 'fail is not an aggregate expression'): Book.objects.aggregate(fail=F('price')) def test_nonfield_annotation(self): Loading @@ -918,7 +918,7 @@ class AggregateTestCase(TestCase): self.assertEqual(book.val, 2) def test_missing_output_field_raises_error(self): with six.assertRaisesRegex(self, FieldError, 'Cannot resolve expression type, unknown output_field'): with self.assertRaisesMessage(FieldError, 'Cannot resolve expression type, unknown output_field'): Book.objects.annotate(val=Max(2)).first() def test_annotation_expressions(self): Loading Loading @@ -962,7 +962,7 @@ class AggregateTestCase(TestCase): self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)}) def test_combine_different_types(self): with six.assertRaisesRegex(self, FieldError, 'Expression contains mixed types. You must set output_field'): with self.assertRaisesMessage(FieldError, 'Expression contains mixed types. You must set output_field'): Book.objects.annotate(sums=Sum('rating') + Sum('pages') + Sum('price')).get(pk=self.b4.pk) b1 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'), Loading @@ -978,11 +978,11 @@ class AggregateTestCase(TestCase): self.assertEqual(b3.sums, Approximate(Decimal("383.69"), places=2)) def test_complex_aggregations_require_kwarg(self): with six.assertRaisesRegex(self, TypeError, 'Complex annotations require an alias'): with self.assertRaisesMessage(TypeError, 'Complex annotations require an alias'): Author.objects.annotate(Sum(F('age') + F('friends__age'))) with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'): with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'): Author.objects.aggregate(Sum('age') / Count('age')) with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'): with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'): Author.objects.aggregate(Sum(1)) def test_aggregate_over_complex_annotation(self): Loading
tests/app_loading/tests.py +1 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import os from django.apps import apps from django.test import SimpleTestCase from django.test.utils import extend_sys_path from django.utils import six from django.utils._os import upath Loading Loading @@ -57,7 +56,7 @@ class EggLoadingTest(SimpleTestCase): """Loading an app from an egg that has an import error in its models module raises that error""" egg_name = '%s/brokenapp.egg' % self.egg_dir with extend_sys_path(egg_name): with six.assertRaisesRegex(self, ImportError, 'modelz'): with self.assertRaisesMessage(ImportError, 'modelz'): with self.settings(INSTALLED_APPS=['broken_app']): pass Loading
tests/apps/tests.py +3 −3 Original line number Diff line number Diff line Loading @@ -159,12 +159,12 @@ class AppsTests(SimpleTestCase): self.assertEqual(apps.get_app_config('relabeled').name, 'apps') def test_duplicate_labels(self): with six.assertRaisesRegex(self, ImproperlyConfigured, "Application labels aren't unique"): with self.assertRaisesMessage(ImproperlyConfigured, "Application labels aren't unique"): with self.settings(INSTALLED_APPS=['apps.apps.PlainAppsConfig', 'apps']): pass def test_duplicate_names(self): with six.assertRaisesRegex(self, ImproperlyConfigured, "Application names aren't unique"): with self.assertRaisesMessage(ImproperlyConfigured, "Application names aren't unique"): with self.settings(INSTALLED_APPS=['apps.apps.RelabeledAppsConfig', 'apps']): pass Loading @@ -172,7 +172,7 @@ class AppsTests(SimpleTestCase): """ App discovery should preserve stack traces. Regression test for #22920. """ with six.assertRaisesRegex(self, ImportError, "Oops"): with self.assertRaisesMessage(ImportError, "Oops"): with self.settings(INSTALLED_APPS=['import_error_package']): pass Loading
tests/auth_tests/test_management.py +13 −12 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 = [ Loading @@ -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 = [ Loading Loading @@ -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') Loading