Ticket #10992: 10992_tests.diff

File 10992_tests.diff, 3.2 KB (added by Zain Memon, 16 years ago)

Tests demonstrating the bug

  • tests/regressiontests/admin_views/tests.py

     
    1616from models import (Article, BarAccount, CustomArticle, EmptyModel,
    1717                    ExternalSubscriber, FooAccount, Gallery,
    1818                    ModelWithStringPrimaryKey, Person, Persona, Picture,
    19                     Podcast, Section, Subscriber, Vodcast, Language)
     19                    Podcast, Section, Subscriber, Vodcast, Language, Master, Detail)
    2020
    2121try:
    2222    set
     
    908908        # confirm the search returned 1 object
    909909        self.assertContains(response, "\n1 recommendation\n")
    910910
     911class SaveCustomPKInlines(TestCase):
     912    fixtures = ['admin-views-users']
     913   
     914    def setUp(self):
     915        self.client.login(username='super', password='secret')
     916       
     917        master = Master(codice="djangocon")
     918        master.save()
     919        detail = Detail(codice="prague", fk=master)
     920        detail.save()
     921
     922    def tearDown(self):
     923        self.client.logout()
     924
     925    def test_saving_existing_inline(self):
     926        data = {
     927            "detail_set-0-fk": "djangocon",
     928            "codice": "djangocon",
     929            "detail_set-2-codice": "",
     930            "detail_set-INITIAL_FORMS": "1",
     931            "detail_set-1-fk": "djangocon",
     932            "detail_set-2-fk": "djangocon",
     933            "detail_set-3-fk": "djangocon",
     934            "detail_set-0-codice": "prague",
     935            "detail_set-TOTAL_FORMS": "4",
     936            "detail_set-1-codice": "",
     937            "detail_set-3-codice": "",
     938            "_save": "Save"
     939        }
     940       
     941        response = self.client.post('/test_admin/admin/admin_views/master/djangocon/',
     942            data, follow=True)
     943       
     944        self.failUnlessEqual(response.status_code, 200)
     945
    911946class AdminInheritedInlinesTest(TestCase):
    912947    fixtures = ['admin-views-users.xml',]
    913948
  • tests/regressiontests/admin_views/models.py

     
    356356class RecommendationAdmin(admin.ModelAdmin):
    357357    search_fields = ('titletranslation__text', 'recommender__titletranslation__text',)
    358358
     359class Master(models.Model):
     360    codice = models.CharField(primary_key=True, max_length=30)
    359361
     362class Detail(models.Model):
     363    codice = models.CharField(primary_key=True, max_length=30)
     364    fk = models.ForeignKey(Master)
     365
     366class DetailInline(admin.TabularInline):
     367    model = Detail
     368
     369class MasterAdmin(admin.ModelAdmin):
     370    inlines = [DetailInline,]
     371
    360372admin.site.register(Article, ArticleAdmin)
    361373admin.site.register(CustomArticle, CustomArticleAdmin)
    362374admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    378390admin.site.register(Language, LanguageAdmin)
    379391admin.site.register(Recommendation, RecommendationAdmin)
    380392admin.site.register(Recommender)
     393admin.site.register(Master, MasterAdmin)
    381394
    382395# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    383396# That way we cover all four cases:
Back to Top