Ticket #11807: django-2009-08-31-admin-onetoone-pk-inline-test.diff

File django-2009-08-31-admin-onetoone-pk-inline-test.diff, 3.4 KB (added by Adam Gomaa, 15 years ago)

Patch that adds a regression test for this issue.

  • tests/regressiontests/admin_views/models.py

    diff -r e3845055edd8 tests/regressiontests/admin_views/models.py
    a b class CategoryAdmin(admin.ModelAdmin):  
    417417class CategoryInline(admin.StackedInline):
    418418    model = Category
    419419
     420class CollectorAux(models.Model):
     421    collector = models.OneToOneField(Collector, primary_key=True)
     422    aux_data = models.TextField(blank=True, null=True, default="foo")
     423
     424class CollectorAuxInline(admin.StackedInline):
     425    model = CollectorAux
     426
    420427class CollectorAdmin(admin.ModelAdmin):
    421     inlines = [WidgetInline, DooHickeyInline, GrommetInline, WhatsitInline, FancyDoodadInline, CategoryInline]
     428    inlines = [WidgetInline, DooHickeyInline, GrommetInline, WhatsitInline, FancyDoodadInline, CategoryInline, CollectorAuxInline]
     429
     430
    422431
    423432admin.site.register(Article, ArticleAdmin)
    424433admin.site.register(CustomArticle, CustomArticleAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff -r e3845055edd8 tests/regressiontests/admin_views/tests.py
    a b from models import Article, BarAccount,  
    1818    ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
    1919    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    2020    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    21     Category
     21    Category, CollectorAux
    2222
    2323try:
    2424    set
    class AdminInlineTests(TestCase):  
    13121312            "category_set-2-order": "",
    13131313            "category_set-2-id": "",
    13141314            "category_set-2-collector": "1",
     1315
     1316            "collectoraux-TOTAL_FORMS": "1",
     1317            "collectoraux-INITIAL_FORMS": "0",
     1318            "collectoraux-0-id": "",
     1319            "collectoraux-0-collector": "1",
     1320            "collectoraux-0-aux_data": "foo",
    13151321        }
    13161322
    13171323        result = self.client.login(username='super', password='secret')
    class AdminInlineTests(TestCase):  
    15341540        self.failUnlessEqual(Category.objects.get(id=3).order, 1)
    15351541        self.failUnlessEqual(Category.objects.get(id=4).order, 0)
    15361542
     1543    def test_onetoone_pk_inline(self):
     1544        """Check that related OneToOnes that have primary_key=True are
     1545        saved when the default value isn't changed.
     1546
     1547        Regression for #11807.
     1548
     1549        """
     1550        self.failUnlessEqual(CollectorAux.objects.count(), 0)
     1551        self.post_data["collectoraux-0-aux_data"] = "foo"
     1552        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1553        self.failUnlessEqual(response.status_code, 302)
     1554        self.failUnlessEqual(CollectorAux.objects.count(), 1)
     1555
     1556    def test_onetoone_pk_inline_changed(self):
     1557        """Check that related OneToOnes that have primary_key=True are
     1558        saved when the default value *is* changed.
     1559
     1560        Related to  #11807.
     1561
     1562        """
     1563        self.failUnlessEqual(CollectorAux.objects.count(), 0)
     1564        self.post_data['collectoraux-0-aux_data']  = "foo2"
     1565        response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data)
     1566        self.failUnlessEqual(response.status_code, 302)
     1567        self.failUnlessEqual(CollectorAux.objects.count(), 1)
     1568
    15371569
    15381570class NeverCacheTests(TestCase):
    15391571    fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml']
Back to Top