1
0
mirror of https://github.com/django/django.git synced 2025-08-16 23:09:13 +00:00

Silenced all admin validation warnings.

Warnings could escape depending on the order in which tests were run.
This commit is contained in:
Tim Graham 2014-11-27 09:45:24 -05:00
parent 17fe0bd808
commit 8402909876

View File

@ -73,6 +73,8 @@ class ValidationTestCase(TestCase):
class ExcludedFields1(admin.ModelAdmin): class ExcludedFields1(admin.ModelAdmin):
exclude = ('foo') exclude = ('foo')
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"'ExcludedFields1.exclude' must be a list or tuple.", "'ExcludedFields1.exclude' must be a list or tuple.",
ExcludedFields1.validate, ExcludedFields1.validate,
@ -82,6 +84,8 @@ class ValidationTestCase(TestCase):
class ExcludedFields2(admin.ModelAdmin): class ExcludedFields2(admin.ModelAdmin):
exclude = ('name', 'name') exclude = ('name', 'name')
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"There are duplicate field(s) in ExcludedFields2.exclude", "There are duplicate field(s) in ExcludedFields2.exclude",
ExcludedFields2.validate, ExcludedFields2.validate,
@ -96,6 +100,8 @@ class ValidationTestCase(TestCase):
model = Album model = Album
inlines = [ExcludedFieldsInline] inlines = [ExcludedFieldsInline]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"'ExcludedFieldsInline.exclude' must be a list or tuple.", "'ExcludedFieldsInline.exclude' must be a list or tuple.",
ExcludedFieldsAlbumAdmin.validate, ExcludedFieldsAlbumAdmin.validate,
@ -114,6 +120,8 @@ class ValidationTestCase(TestCase):
model = Album model = Album
inlines = [SongInline] inlines = [SongInline]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.", "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
AlbumAdmin.validate, AlbumAdmin.validate,
@ -158,6 +166,8 @@ class ValidationTestCase(TestCase):
class MyAdmin(admin.ModelAdmin): class MyAdmin(admin.ModelAdmin):
inlines = [TwoAlbumFKAndAnEInline] inlines = [TwoAlbumFKAndAnEInline]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ValueError, self.assertRaisesMessage(ValueError,
"'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'.", "'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'.",
MyAdmin.validate, Album) MyAdmin.validate, Album)
@ -216,6 +226,8 @@ class ValidationTestCase(TestCase):
class SongAdmin(admin.ModelAdmin): class SongAdmin(admin.ModelAdmin):
readonly_fields = ("title", "nonexistent") readonly_fields = ("title", "nonexistent")
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
str_prefix("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable " str_prefix("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable "
"or an attribute of 'SongAdmin' or found in the model 'Song'."), "or an attribute of 'SongAdmin' or found in the model 'Song'."),
@ -227,6 +239,8 @@ class ValidationTestCase(TestCase):
model = City model = City
readonly_fields = ['i_dont_exist'] # Missing attribute readonly_fields = ['i_dont_exist'] # Missing attribute
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
str_prefix("CityInline.readonly_fields[0], %(_)s'i_dont_exist' is not a callable " str_prefix("CityInline.readonly_fields[0], %(_)s'i_dont_exist' is not a callable "
"or an attribute of 'CityInline' or found in the model 'City'."), "or an attribute of 'CityInline' or found in the model 'City'."),
@ -262,6 +276,8 @@ class ValidationTestCase(TestCase):
class BookAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):
fields = ['authors'] fields = ['authors']
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.", "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
BookAdmin.validate, BookAdmin.validate,
@ -274,6 +290,8 @@ class ValidationTestCase(TestCase):
('Header 2', {'fields': ('authors',)}), ('Header 2', {'fields': ('authors',)}),
) )
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.", "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
FieldsetBookAdmin.validate, FieldsetBookAdmin.validate,