Ticket #9588: 9588.2.diff

File 9588.2.diff, 2.4 KB (added by Preston Timmons, 13 years ago)

Added tests. Patched against r16231.

  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 81301cf..2e5a4c5 100644
    a b class GenericInlineModelAdmin(InlineModelAdmin):  
    396396    ct_fk_field = "object_id"
    397397    formset = BaseGenericInlineFormSet
    398398
    399     def get_formset(self, request, obj=None):
     399    def get_formset(self, request, obj=None, **kwargs):
    400400        if self.declared_fieldsets:
    401401            fields = flatten_fieldsets(self.declared_fieldsets)
    402402        else:
    class GenericInlineModelAdmin(InlineModelAdmin):  
    420420            "max_num": self.max_num,
    421421            "exclude": exclude
    422422        }
     423        defaults.update(kwargs)
    423424        return generic_inlineformset_factory(self.model, **defaults)
    424425
    425426class GenericStackedInline(GenericInlineModelAdmin):
  • tests/regressiontests/generic_inline_admin/tests.py

    diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
    index c40b6dd..d989697 100644
    a b  
    11# coding: utf-8
    22
    33from django.conf import settings
     4from django.contrib.admin.sites import AdminSite
    45from django.contrib.contenttypes.generic import generic_inlineformset_factory
    56from django.test import TestCase
    67
    78# local test models
    89from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
    9                    Media, EpisodePermanent, MediaPermanentInline, Category
     10                   Media, MediaInline, EpisodePermanent, MediaPermanentInline, \
     11                   Category
    1012
    1113
    1214class GenericAdminViewTest(TestCase):
    class NoInlineDeletionTest(TestCase):  
    214216        fake_request = object()
    215217        formset = inline.get_formset(fake_request)
    216218        self.assertFalse(formset.can_delete)
     219
     220class GenericInlineModelAdminTest(TestCase):
     221
     222    def test_get_formset_kwargs(self):
     223        media_inline = MediaInline(Media, AdminSite())
     224
     225        # Create a formset with default arguments
     226        formset = media_inline.get_formset(None)
     227        self.assertEqual(formset.max_num, None)
     228        self.assertEqual(formset.can_order, False)
     229
     230        # Create a formset with custom keyword arguments
     231        formset = media_inline.get_formset(None, max_num=100, can_order=True)
     232        self.assertEqual(formset.max_num, 100)
     233        self.assertEqual(formset.can_order, True)
Back to Top