Migrated admin_inlines doctest. Thanks to Sebastian Hillig.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13880 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ea07fe7a3f
commit
856a9e953b
|
@ -123,25 +123,3 @@ class InlineWeakness(admin.TabularInline):
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
admin.site.register(Fashionista, inlines=[InlineWeakness])
|
admin.site.register(Fashionista, inlines=[InlineWeakness])
|
||||||
|
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
|
||||||
|
|
||||||
# Regression test for #9362
|
|
||||||
|
|
||||||
>>> sally = Teacher.objects.create(name='Sally')
|
|
||||||
>>> john = Parent.objects.create(name='John')
|
|
||||||
>>> joe = Child.objects.create(name='Joe', teacher=sally, parent=john)
|
|
||||||
|
|
||||||
The problem depends only on InlineAdminForm and its "original" argument, so
|
|
||||||
we can safely set the other arguments to None/{}. We just need to check that
|
|
||||||
the content_type argument of Child isn't altered by the internals of the
|
|
||||||
inline form.
|
|
||||||
|
|
||||||
>>> from django.contrib.admin.helpers import InlineAdminForm
|
|
||||||
>>> iaf = InlineAdminForm(None, None, {}, {}, joe)
|
|
||||||
>>> iaf.original
|
|
||||||
<Child: I am Joe, a child of John>
|
|
||||||
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from django.contrib.admin.helpers import InlineAdminForm
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
# local test models
|
# local test models
|
||||||
from models import Holder, Inner, InnerInline
|
from models import Holder, Inner, InnerInline
|
||||||
from models import Holder2, Inner2, Holder3, Inner3
|
from models import Holder2, Inner2, Holder3, Inner3
|
||||||
from models import Person, OutfitItem, Fashionista
|
from models import Person, OutfitItem, Fashionista
|
||||||
|
from models import Teacher, Parent, Child
|
||||||
|
|
||||||
|
|
||||||
class TestInline(TestCase):
|
class TestInline(TestCase):
|
||||||
fixtures = ['admin-views-users.xml']
|
fixtures = ['admin-views-users.xml']
|
||||||
|
@ -100,3 +104,20 @@ class TestInlineMedia(TestCase):
|
||||||
response = self.client.get(change_url)
|
response = self.client.get(change_url)
|
||||||
self.assertContains(response, 'my_awesome_admin_scripts.js')
|
self.assertContains(response, 'my_awesome_admin_scripts.js')
|
||||||
self.assertContains(response, 'my_awesome_inline_scripts.js')
|
self.assertContains(response, 'my_awesome_inline_scripts.js')
|
||||||
|
|
||||||
|
class TestInlineAdminForm(TestCase):
|
||||||
|
|
||||||
|
def test_immutable_content_type(self):
|
||||||
|
"""Regression for #9362
|
||||||
|
The problem depends only on InlineAdminForm and its "original"
|
||||||
|
argument, so we can safely set the other arguments to None/{}. We just
|
||||||
|
need to check that the content_type argument of Child isn't altered by
|
||||||
|
the internals of the inline form."""
|
||||||
|
|
||||||
|
sally = Teacher.objects.create(name='Sally')
|
||||||
|
john = Parent.objects.create(name='John')
|
||||||
|
joe = Child.objects.create(name='Joe', teacher=sally, parent=john)
|
||||||
|
|
||||||
|
iaf = InlineAdminForm(None, None, {}, {}, joe)
|
||||||
|
parent_ct = ContentType.objects.get_for_model(Parent)
|
||||||
|
self.assertEqual(iaf.original.content_type, parent_ct)
|
||||||
|
|
Loading…
Reference in New Issue