Skip to content

Commit

Permalink
Ignored warnings correctly in test_get_formsets_with_inlines_returns_…
Browse files Browse the repository at this point in the history
…tuples().

The subclass check in ModelAdmin.get_formsets_with_inlines() wasn't
tested correctly because of the super() call in
EpisodeAdmin.get_formsets().
  • Loading branch information
berkerpeksag authored and timgraham committed Dec 31, 2014
1 parent 013c2d8 commit 32ca159
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/options.py
Expand Up @@ -773,7 +773,7 @@ def get_formsets_with_inlines(self, request, obj=None):
warnings.warn(
"ModelAdmin.get_formsets() is deprecated and will be removed in "
"Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
RemovedInDjango19Warning
RemovedInDjango19Warning, stacklevel=2
)
if formsets:
zipped = zip(formsets, self.get_inline_instances(request, None))
Expand Down
17 changes: 8 additions & 9 deletions tests/generic_inline_admin/tests.py
Expand Up @@ -9,7 +9,7 @@
from django.contrib.contenttypes.forms import generic_inlineformset_factory
from django.forms.formsets import DEFAULT_MAX_NUM
from django.forms.models import ModelForm
from django.test import TestCase, override_settings, RequestFactory
from django.test import RequestFactory, TestCase, ignore_warnings, override_settings
from django.utils.deprecation import RemovedInDjango19Warning

# local test models
Expand Down Expand Up @@ -474,6 +474,7 @@ class EpisodeAdmin(admin.ModelAdmin):
list(ma.get_formsets_with_inlines(request))
self.assertEqual(len(w), 0)

@ignore_warnings(category=RemovedInDjango19Warning)
def test_get_formsets_with_inlines_returns_tuples(self):
"""
Ensure that get_formsets_with_inlines() returns the correct tuples.
Expand Down Expand Up @@ -506,14 +507,12 @@ class EpisodeAdmin(admin.ModelAdmin):
]

def get_formsets(self, request, obj=None):
# Catch the deprecation warning to force the usage of get_formsets
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
return super(EpisodeAdmin, self).get_formsets(request, obj)
# Override get_formsets to force the usage of get_formsets in
# ModelAdmin.get_formsets_with_inlines() then ignore the
# warning raised by ModelAdmin.get_formsets_with_inlines()
return self._get_formsets(request, obj)

ma = EpisodeAdmin(Episode, self.site)
inlines = ma.get_inline_instances(request)
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
for (formset, inline), other_inline in zip(ma.get_formsets_with_inlines(request), inlines):
self.assertIsInstance(formset, other_inline.get_formset(request).__class__)
for (formset, inline), other_inline in zip(ma.get_formsets_with_inlines(request), inlines):
self.assertIsInstance(formset, other_inline.get_formset(request).__class__)

0 comments on commit 32ca159

Please sign in to comment.