Code

Ticket #9969: t9969-r9708.diff

File t9969-r9708.diff, 3.5 KB (added by ramiro, 6 years ago)

New patch, includes tests

Line 
1diff -r a21ec5adcb71 tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml
2--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
3+++ b/tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml        Tue Jan 06 21:26:27 2009 -0200
4@@ -0,0 +1,12 @@
5+<?xml version="1.0" encoding="utf-8"?>
6+<django-objects version="1.0">
7+  <object pk="1" model="admin_views.fabric">
8+    <field type="CharField" name="surface">x</field>
9+  </object>
10+  <object pk="2" model="admin_views.fabric">
11+    <field type="CharField" name="surface">y</field>
12+  </object>
13+  <object pk="3" model="admin_views.fabric">
14+    <field type="CharField" name="surface">plain</field>
15+  </object>
16+</django-objects>
17diff -r a21ec5adcb71 tests/regressiontests/admin_views/models.py
18--- a/tests/regressiontests/admin_views/models.py       Tue Jan 06 15:53:13 2009 -0200
19+++ b/tests/regressiontests/admin_views/models.py       Tue Jan 06 21:26:27 2009 -0200
20@@ -134,12 +134,28 @@
21 class ThingAdmin(admin.ModelAdmin):
22     list_filter = ('color',)
23 
24+class Fabric(models.Model):
25+    NG_CHOICES = (
26+        ('Textured', (
27+                ('x', 'Horizontal'),
28+                ('y', 'Vertical'),
29+            )
30+        ),
31+        ('plain', 'Smooth'),
32+    )
33+    surface = models.CharField(max_length=20, choices=NG_CHOICES)
34+
35+class FabricAdmin(admin.ModelAdmin):
36+    list_display = ('surface',)
37+    list_filter = ('surface',)
38+
39 admin.site.register(Article, ArticleAdmin)
40 admin.site.register(CustomArticle, CustomArticleAdmin)
41 admin.site.register(Section, inlines=[ArticleInline])
42 admin.site.register(ModelWithStringPrimaryKey)
43 admin.site.register(Color)
44 admin.site.register(Thing, ThingAdmin)
45+admin.site.register(Fabric, FabricAdmin)
46 
47 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
48 # That way we cover all four cases:
49diff -r a21ec5adcb71 tests/regressiontests/admin_views/tests.py
50--- a/tests/regressiontests/admin_views/tests.py        Tue Jan 06 15:53:13 2009 -0200
51+++ b/tests/regressiontests/admin_views/tests.py        Tue Jan 06 21:26:27 2009 -0200
52@@ -12,8 +12,8 @@
53 from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey
54 
55 class AdminViewBasicTest(TestCase):
56-    fixtures = ['admin-views-users.xml', 'admin-views-colors.xml']
57-   
58+    fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml']
59+
60     def setUp(self):
61         self.client.login(username='super', password='secret')
62     
63@@ -147,7 +147,21 @@
64             response.content.index('Middle content') < response.content.index('Newest content'),
65             "Results of sorting on ModelAdmin method are out of order."
66         )
67-       
68+
69+    def testNamedGroupFieldChoicesChangeList(self):
70+        """
71+        Ensures the admin changelist shows correct values in the relevant column
72+        for rows corresponding to instances of a model in which a named group
73+        has been used in the choices option of a field.
74+        """
75+        response = self.client.get('/test_admin/admin/admin_views/fabric/')
76+        self.failUnlessEqual(response.status_code, 200)
77+        self.failUnless(
78+            '<a href="1/">Horizontal</a>' in response.content and
79+            '<a href="2/">Vertical</a>' in response.content,
80+            "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group."
81+        )
82+
83     def testLimitedFilter(self):
84         """Ensure admin changelist filters do not contain objects excluded via limit_choices_to."""
85         response = self.client.get('/test_admin/admin/admin_views/thing/')