Ticket #29637: 29637-test.diff

File 29637-test.diff, 5.7 KB (added by Tim Graham, 6 years ago)

Regression test for Django's test suite

  • tests/admin_inlines/admin.py

    diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py
    index 7ac13ed..b5f343a 100644
    a b class InnerInline2(admin.StackedInline):  
    7474        js = ('my_awesome_inline_scripts.js',)
    7575
    7676
     77class InnerInline2Tabular(admin.TabularInline):
     78    model = Inner2
     79
     80
    7781class CustomNumberWidget(forms.NumberInput):
    7882    class Media:
    7983        js = ('custom_number.js',)
    site.register(TitleCollection, inlines=[TitleInline])  
    236240# only ModelAdmin media
    237241site.register(Holder, HolderAdmin, inlines=[InnerInline])
    238242# ModelAdmin and Inline media
    239 site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
     243site.register(Holder2, HolderAdmin, inlines=[InnerInline2, InnerInline2Tabular])
    240244# only Inline media
    241245site.register(Holder3, inlines=[InnerInline3])
    242246
  • tests/admin_inlines/tests.py

    diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
    index 4ce744f..d09b48f 100644
    a b class TestInlinePermissions(TestCase):  
    588588        self.author_book_auto_m2m_intermediate_id = author_book_auto_m2m_intermediate.pk
    589589
    590590        holder = Holder2.objects.create(dummy=13)
    591         inner2 = Inner2.objects.create(dummy=42, holder=holder)
     591        self.inner2 = Inner2.objects.create(dummy=42, holder=holder)
    592592        self.holder_change_url = reverse('admin:admin_inlines_holder2_change', args=(holder.id,))
    593         self.inner2_id = inner2.id
    594593
    595594        self.client.force_login(self.user)
    596595
    class TestInlinePermissions(TestCase):  
    684683        )
    685684        self.assertNotContains(
    686685            response,
    687             '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
     686            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
    688687            html=True
    689688        )
    690689
    class TestInlinePermissions(TestCase):  
    693692        self.user.user_permissions.add(permission)
    694693        response = self.client.get(self.holder_change_url)
    695694        # Change permission on inner2s, so we can change existing but not add new
    696         self.assertContains(response, '<h2>Inner2s</h2>')
     695        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
    697696        # Just the one form for existing instances
    698697        self.assertContains(
    699698            response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS">',
    class TestInlinePermissions(TestCase):  
    701700        )
    702701        self.assertContains(
    703702            response,
    704             '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
     703            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
    705704            html=True
    706705        )
    707706        # max-num 0 means we can't add new ones
    class TestInlinePermissions(TestCase):  
    710709            '<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" value="0" name="inner2_set-MAX_NUM_FORMS">',
    711710            html=True
    712711        )
     712        # Tabular form
     713        self.assertContains(response, '<th class="required">Dummy</th>', html=True)
     714        self.assertContains(
     715            response,
     716            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
     717            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
     718        )
    713719
    714720    def test_inline_change_fk_add_change_perm(self):
    715721        permission = Permission.objects.get(codename='add_inner2', content_type=self.inner_ct)
    class TestInlinePermissions(TestCase):  
    726732        )
    727733        self.assertContains(
    728734            response,
    729             '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
     735            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
    730736            html=True
    731737        )
    732738
    class TestInlinePermissions(TestCase):  
    746752        )
    747753        self.assertContains(
    748754            response,
    749             '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
     755            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
    750756            html=True
    751757        )
    752758        self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
    class TestInlinePermissions(TestCase):  
    760766        self.user.user_permissions.add(permission)
    761767        response = self.client.get(self.holder_change_url)
    762768        # All perms on inner2s, so we can add/change/delete
    763         self.assertContains(response, '<h2>Inner2s</h2>')
     769        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
    764770        # One form for existing instance only, three for new
    765771        self.assertContains(
    766772            response,
    class TestInlinePermissions(TestCase):  
    769775        )
    770776        self.assertContains(
    771777            response,
    772             '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
     778            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
    773779            html=True
    774780        )
    775781        self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
     782        # Tabular form
     783        self.assertContains(response, '<th class="required">Dummy</th>', html=True)
     784        self.assertContains(
     785            response,
     786            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
     787            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
     788        )
    776789
    777790
    778791@override_settings(ROOT_URLCONF='admin_inlines.urls')
Back to Top