Silenced all admin validation warnings.
Warnings could escape depending on the order in which tests were run.
This commit is contained in:
parent
17fe0bd808
commit
8402909876
|
@ -73,6 +73,8 @@ class ValidationTestCase(TestCase):
|
|||
class ExcludedFields1(admin.ModelAdmin):
|
||||
exclude = ('foo')
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"'ExcludedFields1.exclude' must be a list or tuple.",
|
||||
ExcludedFields1.validate,
|
||||
|
@ -82,6 +84,8 @@ class ValidationTestCase(TestCase):
|
|||
class ExcludedFields2(admin.ModelAdmin):
|
||||
exclude = ('name', 'name')
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"There are duplicate field(s) in ExcludedFields2.exclude",
|
||||
ExcludedFields2.validate,
|
||||
|
@ -96,6 +100,8 @@ class ValidationTestCase(TestCase):
|
|||
model = Album
|
||||
inlines = [ExcludedFieldsInline]
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"'ExcludedFieldsInline.exclude' must be a list or tuple.",
|
||||
ExcludedFieldsAlbumAdmin.validate,
|
||||
|
@ -114,6 +120,8 @@ class ValidationTestCase(TestCase):
|
|||
model = Album
|
||||
inlines = [SongInline]
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
|
||||
AlbumAdmin.validate,
|
||||
|
@ -158,6 +166,8 @@ class ValidationTestCase(TestCase):
|
|||
class MyAdmin(admin.ModelAdmin):
|
||||
inlines = [TwoAlbumFKAndAnEInline]
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ValueError,
|
||||
"'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'.",
|
||||
MyAdmin.validate, Album)
|
||||
|
@ -216,6 +226,8 @@ class ValidationTestCase(TestCase):
|
|||
class SongAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("title", "nonexistent")
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
str_prefix("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable "
|
||||
"or an attribute of 'SongAdmin' or found in the model 'Song'."),
|
||||
|
@ -227,6 +239,8 @@ class ValidationTestCase(TestCase):
|
|||
model = City
|
||||
readonly_fields = ['i_dont_exist'] # Missing attribute
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
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'."),
|
||||
|
@ -262,6 +276,8 @@ class ValidationTestCase(TestCase):
|
|||
class BookAdmin(admin.ModelAdmin):
|
||||
fields = ['authors']
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
|
||||
BookAdmin.validate,
|
||||
|
@ -274,6 +290,8 @@ class ValidationTestCase(TestCase):
|
|||
('Header 2', {'fields': ('authors',)}),
|
||||
)
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||
self.assertRaisesMessage(ImproperlyConfigured,
|
||||
"'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
|
||||
FieldsetBookAdmin.validate,
|
||||
|
|
Loading…
Reference in New Issue