Code

Ticket #19524: 19524.testcase.diff

File 19524.testcase.diff, 3.6 KB (added by aaugustin, 19 months ago)
Line 
1diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py
2index cf51fa4..536c3ec 100644
3--- a/tests/regressiontests/admin_inlines/admin.py
4+++ b/tests/regressiontests/admin_inlines/admin.py
5@@ -124,6 +124,9 @@ class ChildModel1Inline(admin.TabularInline):
6 class ChildModel2Inline(admin.StackedInline):
7     model = ChildModel2
8 
9+# admin for #19524
10+class SightingInline(admin.TabularInline):
11+    model = Sighting
12 
13 site.register(TitleCollection, inlines=[TitleInline])
14 # Test bug #12561 and #12778
15@@ -141,4 +144,5 @@ site.register(Holder4, Holder4Admin)
16 site.register(Author, AuthorAdmin)
17 site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline])
18 site.register(ProfileCollection, inlines=[ProfileInline])
19-site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
20\ No newline at end of file
21+site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
22+site.register(ExtraTerrestrial, inlines=[SightingInline])
23diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
24index b004d5f..147873a 100644
25--- a/tests/regressiontests/admin_inlines/models.py
26+++ b/tests/regressiontests/admin_inlines/models.py
27@@ -90,7 +90,6 @@ class Inner4Tabular(models.Model):
28     dummy = models.IntegerField(help_text="Awesome tabular help text is awesome.")
29     holder = models.ForeignKey(Holder4)
30 
31-
32 # Models for #12749
33 
34 class Person(models.Model):
35@@ -133,6 +132,7 @@ class Chapter(models.Model):
36 
37 
38 # Models for #16838
39+
40 class CapoFamiglia(models.Model):
41     name = models.CharField(max_length=100)
42 
43@@ -170,6 +170,17 @@ class ChildModel2(models.Model):
44     def get_absolute_url(self):
45         return '/child_model2/'
46 
47+# Models for #19524
48+
49+class LifeForm(models.Model):
50+    pass
51+
52+class ExtraTerrestrial(LifeForm):
53+    name = models.CharField(max_length=100)
54+
55+class Sighting(models.Model):
56+    et = models.ForeignKey(ExtraTerrestrial)
57+    place = models.CharField(max_length=100)
58 
59 # Other models
60 
61diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
62index 3c86801..54283bf 100644
63--- a/tests/regressiontests/admin_inlines/tests.py
64+++ b/tests/regressiontests/admin_inlines/tests.py
65@@ -12,7 +12,7 @@ from .admin import InnerInline, TitleInline, site
66 from .models import (Holder, Inner, Holder2, Inner2, Holder3, Inner3, Person,
67     OutfitItem, Fashionista, Teacher, Parent, Child, Author, Book, Profile,
68     ProfileCollection, ParentModelWithCustomPk, ChildModel1, ChildModel2,
69-    Title)
70+    Sighting, Title)
71 
72 
73 @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
74@@ -172,6 +172,23 @@ class TestInline(TestCase):
75         self.assertContains(response, child1_shortcut)
76         self.assertContains(response, child2_shortcut)
77 
78+    def test_create_inlines_on_inherited_model(self):
79+        """
80+        Ensure that an object can be created with inlines when it inherits
81+        another class. Bug #19524.
82+        """
83+        data = {
84+            'name': 'Martian',
85+            'sighting_set-TOTAL_FORMS': 1,
86+            'sighting_set-INITIAL_FORMS': 0,
87+            'sighting_set-MAX_NUM_FORMS': 0,
88+            'sighting_set-0-place': 'Zone 51',
89+            '_save': 'Save',
90+        }
91+        response = self.client.post('/admin/admin_inlines/extraterrestrial/add/', data)
92+        self.assertEqual(response.status_code, 302)
93+        self.assertEqual(Sighting.objects.filter(et__name='Martian').count(), 1)
94+
95 
96 @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
97 class TestInlineMedia(TestCase):