Ticket #16838: t16838-inlines_tests.diff

File t16838-inlines_tests.diff, 3.8 KB (added by jamesp, 13 years ago)

Tests to pass for admin inlines with related_name='+'

  • tests/regressiontests/admin_inlines/admin.py

    diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py
    index 6f8076a..4edd361 100644
    a b class NovelAdmin(admin.ModelAdmin):  
    101101    inlines = [ChapterInline]
    102102
    103103
     104class ConsigliereInline(admin.TabularInline):
     105    model = Consigliere
     106
     107
     108class SottoCapoInline(admin.TabularInline):
     109    model = SottoCapo
     110
     111
    104112site.register(TitleCollection, inlines=[TitleInline])
    105113# Test bug #12561 and #12778
    106114# only ModelAdmin media
    site.register(Novel, NovelAdmin)  
    115123site.register(Fashionista, inlines=[InlineWeakness])
    116124site.register(Holder4, Holder4Admin)
    117125site.register(Author, AuthorAdmin)
     126site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline])
  • tests/regressiontests/admin_inlines/models.py

    diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
    index f4e58f2..748280d 100644
    a b class Novel(models.Model):  
    122122class Chapter(models.Model):
    123123    novel = models.ForeignKey(Novel)
    124124
     125
     126# Models for #16838
     127class CapoFamiglia(models.Model):
     128    name = models.CharField(max_length=100)
     129
     130
     131class Consigliere(models.Model):
     132    name = models.CharField(max_length=100)
     133    capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+')
     134
     135
     136class SottoCapo(models.Model):
     137    name = models.CharField(max_length=100)
     138    capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+')
  • tests/regressiontests/admin_inlines/tests.py

    diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
    index efa6cf6..955d620 100644
    a b from django.test import TestCase  
    44
    55# local test models
    66from models import (Holder, Inner, Holder2, Inner2, Holder3,
    7     Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child)
     7    Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child,
     8    CapoFamiglia, Consigliere, SottoCapo)
    89from admin import InnerInline
    910
    1011
    class TestInline(TestCase):  
    115116        self.assertContains(response, '<p class="help">Awesome stacked help text is awesome.</p>', 4)
    116117        self.assertContains(response, '<img src="/static/admin/img/icon-unknown.gif" class="help help-tooltip" width="10" height="10" alt="(Awesome tabular help text is awesome.)" title="Awesome tabular help text is awesome." />', 1)
    117118
     119    def test_non_related_name_inline(self):
     120        """
     121        Ensure that multiple inlines with related_name='+' have correct form
     122        prefixes. Bug #16838.
     123        """
     124        response = self.client.get('/admin/admin_inlines/capofamiglia/add/')
     125
     126        self.assertContains(response,
     127                '<input type="hidden" name="-1-0-id" id="id_-1-0-id" />')
     128        self.assertContains(response,
     129                '<input type="hidden" name="-1-0-capo_famiglia" '
     130                'id="id_-1-0-capo_famiglia" />')
     131        self.assertContains(response,
     132                '<input id="id_-1-0-name" type="text" class="vTextField" '
     133                'name="-1-0-name" maxlength="100" />')
     134
     135        self.assertContains(response,
     136                '<input type="hidden" name="-2-0-id" id="id_-2-0-id" />')
     137        self.assertContains(response,
     138                '<input type="hidden" name="-2-0-capo_famiglia" '
     139                'id="id_-2-0-capo_famiglia" />')
     140        self.assertContains(response,
     141                '<input id="id_-2-0-name" type="text" class="vTextField" '
     142                'name="-2-0-name" maxlength="100" />')
     143
     144
    118145class TestInlineMedia(TestCase):
    119146    urls = "regressiontests.admin_inlines.urls"
    120147    fixtures = ['admin-views-users.xml']
Back to Top