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 , 15 years ago) |
---|
-
tests/regressiontests/admin_views/models.py
diff -r e3845055edd8 tests/regressiontests/admin_views/models.py
a b class CategoryAdmin(admin.ModelAdmin): 417 417 class CategoryInline(admin.StackedInline): 418 418 model = Category 419 419 420 class CollectorAux(models.Model): 421 collector = models.OneToOneField(Collector, primary_key=True) 422 aux_data = models.TextField(blank=True, null=True, default="foo") 423 424 class CollectorAuxInline(admin.StackedInline): 425 model = CollectorAux 426 420 427 class CollectorAdmin(admin.ModelAdmin): 421 inlines = [WidgetInline, DooHickeyInline, GrommetInline, WhatsitInline, FancyDoodadInline, CategoryInline] 428 inlines = [WidgetInline, DooHickeyInline, GrommetInline, WhatsitInline, FancyDoodadInline, CategoryInline, CollectorAuxInline] 429 430 422 431 423 432 admin.site.register(Article, ArticleAdmin) 424 433 admin.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, 18 18 ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \ 19 19 Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ 20 20 Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ 21 Category 21 Category, CollectorAux 22 22 23 23 try: 24 24 set … … class AdminInlineTests(TestCase): 1312 1312 "category_set-2-order": "", 1313 1313 "category_set-2-id": "", 1314 1314 "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", 1315 1321 } 1316 1322 1317 1323 result = self.client.login(username='super', password='secret') … … class AdminInlineTests(TestCase): 1534 1540 self.failUnlessEqual(Category.objects.get(id=3).order, 1) 1535 1541 self.failUnlessEqual(Category.objects.get(id=4).order, 0) 1536 1542 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 1537 1569 1538 1570 class NeverCacheTests(TestCase): 1539 1571 fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml']