@@ -73,19 +73,23 @@ def test_exclude_values(self):
73
73
class ExcludedFields1 (admin .ModelAdmin ):
74
74
exclude = ('foo' )
75
75
76
- self .assertRaisesMessage (ImproperlyConfigured ,
77
- "'ExcludedFields1.exclude' must be a list or tuple." ,
78
- ExcludedFields1 .validate ,
79
- Book )
76
+ with warnings .catch_warnings (record = True ):
77
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
78
+ self .assertRaisesMessage (ImproperlyConfigured ,
79
+ "'ExcludedFields1.exclude' must be a list or tuple." ,
80
+ ExcludedFields1 .validate ,
81
+ Book )
80
82
81
83
def test_exclude_duplicate_values (self ):
82
84
class ExcludedFields2 (admin .ModelAdmin ):
83
85
exclude = ('name' , 'name' )
84
86
85
- self .assertRaisesMessage (ImproperlyConfigured ,
86
- "There are duplicate field(s) in ExcludedFields2.exclude" ,
87
- ExcludedFields2 .validate ,
88
- Book )
87
+ with warnings .catch_warnings (record = True ):
88
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
89
+ self .assertRaisesMessage (ImproperlyConfigured ,
90
+ "There are duplicate field(s) in ExcludedFields2.exclude" ,
91
+ ExcludedFields2 .validate ,
92
+ Book )
89
93
90
94
def test_exclude_in_inline (self ):
91
95
class ExcludedFieldsInline (admin .TabularInline ):
@@ -96,10 +100,12 @@ class ExcludedFieldsAlbumAdmin(admin.ModelAdmin):
96
100
model = Album
97
101
inlines = [ExcludedFieldsInline ]
98
102
99
- self .assertRaisesMessage (ImproperlyConfigured ,
100
- "'ExcludedFieldsInline.exclude' must be a list or tuple." ,
101
- ExcludedFieldsAlbumAdmin .validate ,
102
- Album )
103
+ with warnings .catch_warnings (record = True ):
104
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
105
+ self .assertRaisesMessage (ImproperlyConfigured ,
106
+ "'ExcludedFieldsInline.exclude' must be a list or tuple." ,
107
+ ExcludedFieldsAlbumAdmin .validate ,
108
+ Album )
103
109
104
110
def test_exclude_inline_model_admin (self ):
105
111
"""
@@ -114,10 +120,12 @@ class AlbumAdmin(admin.ModelAdmin):
114
120
model = Album
115
121
inlines = [SongInline ]
116
122
117
- self .assertRaisesMessage (ImproperlyConfigured ,
118
- "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album." ,
119
- AlbumAdmin .validate ,
120
- Album )
123
+ with warnings .catch_warnings (record = True ):
124
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
125
+ self .assertRaisesMessage (ImproperlyConfigured ,
126
+ "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album." ,
127
+ AlbumAdmin .validate ,
128
+ Album )
121
129
122
130
def test_app_label_in_admin_validation (self ):
123
131
"""
@@ -158,9 +166,11 @@ class TwoAlbumFKAndAnEInline(admin.TabularInline):
158
166
class MyAdmin (admin .ModelAdmin ):
159
167
inlines = [TwoAlbumFKAndAnEInline ]
160
168
161
- self .assertRaisesMessage (ValueError ,
162
- "'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'." ,
163
- MyAdmin .validate , Album )
169
+ with warnings .catch_warnings (record = True ):
170
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
171
+ self .assertRaisesMessage (ValueError ,
172
+ "'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'." ,
173
+ MyAdmin .validate , Album )
164
174
165
175
def test_inline_with_specified (self ):
166
176
class TwoAlbumFKAndAnEInline (admin .TabularInline ):
@@ -216,22 +226,26 @@ def test_nonexistent_field(self):
216
226
class SongAdmin (admin .ModelAdmin ):
217
227
readonly_fields = ("title" , "nonexistent" )
218
228
219
- self .assertRaisesMessage (ImproperlyConfigured ,
220
- str_prefix ("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable "
221
- "or an attribute of 'SongAdmin' or found in the model 'Song'." ),
222
- SongAdmin .validate ,
223
- Song )
229
+ with warnings .catch_warnings (record = True ):
230
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
231
+ self .assertRaisesMessage (ImproperlyConfigured ,
232
+ str_prefix ("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable "
233
+ "or an attribute of 'SongAdmin' or found in the model 'Song'." ),
234
+ SongAdmin .validate ,
235
+ Song )
224
236
225
237
def test_nonexistent_field_on_inline (self ):
226
238
class CityInline (admin .TabularInline ):
227
239
model = City
228
240
readonly_fields = ['i_dont_exist' ] # Missing attribute
229
241
230
- self .assertRaisesMessage (ImproperlyConfigured ,
231
- str_prefix ("CityInline.readonly_fields[0], %(_)s'i_dont_exist' is not a callable "
232
- "or an attribute of 'CityInline' or found in the model 'City'." ),
233
- CityInline .validate ,
234
- City )
242
+ with warnings .catch_warnings (record = True ):
243
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
244
+ self .assertRaisesMessage (ImproperlyConfigured ,
245
+ str_prefix ("CityInline.readonly_fields[0], %(_)s'i_dont_exist' is not a callable "
246
+ "or an attribute of 'CityInline' or found in the model 'City'." ),
247
+ CityInline .validate ,
248
+ City )
235
249
236
250
def test_extra (self ):
237
251
class SongAdmin (admin .ModelAdmin ):
@@ -262,10 +276,12 @@ def test_graceful_m2m_fail(self):
262
276
class BookAdmin (admin .ModelAdmin ):
263
277
fields = ['authors' ]
264
278
265
- self .assertRaisesMessage (ImproperlyConfigured ,
266
- "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model." ,
267
- BookAdmin .validate ,
268
- Book )
279
+ with warnings .catch_warnings (record = True ):
280
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
281
+ self .assertRaisesMessage (ImproperlyConfigured ,
282
+ "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model." ,
283
+ BookAdmin .validate ,
284
+ Book )
269
285
270
286
def test_cannot_include_through (self ):
271
287
class FieldsetBookAdmin (admin .ModelAdmin ):
@@ -274,10 +290,12 @@ class FieldsetBookAdmin(admin.ModelAdmin):
274
290
('Header 2' , {'fields' : ('authors' ,)}),
275
291
)
276
292
277
- self .assertRaisesMessage (ImproperlyConfigured ,
278
- "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model." ,
279
- FieldsetBookAdmin .validate ,
280
- Book )
293
+ with warnings .catch_warnings (record = True ):
294
+ warnings .filterwarnings ('ignore' , module = 'django.contrib.admin.options' )
295
+ self .assertRaisesMessage (ImproperlyConfigured ,
296
+ "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model." ,
297
+ FieldsetBookAdmin .validate ,
298
+ Book )
281
299
282
300
def test_nested_fields (self ):
283
301
class NestedFieldsAdmin (admin .ModelAdmin ):
0 commit comments