Ticket #9969: t9969-r9708.diff

File t9969-r9708.diff, 3.5 KB (added by Ramiro Morales, 15 years ago)

New patch, includes tests

  • new file tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml

    diff -r a21ec5adcb71 tests/regressiontests/admin_views/fixtures/admin-views-fabrics.xml
    - +  
     1<?xml version="1.0" encoding="utf-8"?>
     2<django-objects version="1.0">
     3  <object pk="1" model="admin_views.fabric">
     4    <field type="CharField" name="surface">x</field>
     5  </object>
     6  <object pk="2" model="admin_views.fabric">
     7    <field type="CharField" name="surface">y</field>
     8  </object>
     9  <object pk="3" model="admin_views.fabric">
     10    <field type="CharField" name="surface">plain</field>
     11  </object>
     12</django-objects>
  • tests/regressiontests/admin_views/models.py

    diff -r a21ec5adcb71 tests/regressiontests/admin_views/models.py
    a b  
    134134class ThingAdmin(admin.ModelAdmin):
    135135    list_filter = ('color',)
    136136
     137class Fabric(models.Model):
     138    NG_CHOICES = (
     139        ('Textured', (
     140                ('x', 'Horizontal'),
     141                ('y', 'Vertical'),
     142            )
     143        ),
     144        ('plain', 'Smooth'),
     145    )
     146    surface = models.CharField(max_length=20, choices=NG_CHOICES)
     147
     148class FabricAdmin(admin.ModelAdmin):
     149    list_display = ('surface',)
     150    list_filter = ('surface',)
     151
    137152admin.site.register(Article, ArticleAdmin)
    138153admin.site.register(CustomArticle, CustomArticleAdmin)
    139154admin.site.register(Section, inlines=[ArticleInline])
    140155admin.site.register(ModelWithStringPrimaryKey)
    141156admin.site.register(Color)
    142157admin.site.register(Thing, ThingAdmin)
     158admin.site.register(Fabric, FabricAdmin)
    143159
    144160# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    145161# That way we cover all four cases:
  • tests/regressiontests/admin_views/tests.py

    diff -r a21ec5adcb71 tests/regressiontests/admin_views/tests.py
    a b  
    1212from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey
    1313
    1414class AdminViewBasicTest(TestCase):
    15     fixtures = ['admin-views-users.xml', 'admin-views-colors.xml']
    16    
     15    fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml']
     16
    1717    def setUp(self):
    1818        self.client.login(username='super', password='secret')
    1919   
     
    147147            response.content.index('Middle content') < response.content.index('Newest content'),
    148148            "Results of sorting on ModelAdmin method are out of order."
    149149        )
    150        
     150
     151    def testNamedGroupFieldChoicesChangeList(self):
     152        """
     153        Ensures the admin changelist shows correct values in the relevant column
     154        for rows corresponding to instances of a model in which a named group
     155        has been used in the choices option of a field.
     156        """
     157        response = self.client.get('/test_admin/admin/admin_views/fabric/')
     158        self.failUnlessEqual(response.status_code, 200)
     159        self.failUnless(
     160            '<a href="1/">Horizontal</a>' in response.content and
     161            '<a href="2/">Vertical</a>' in response.content,
     162            "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group."
     163        )
     164
    151165    def testLimitedFilter(self):
    152166        """Ensure admin changelist filters do not contain objects excluded via limit_choices_to."""
    153167        response = self.client.get('/test_admin/admin/admin_views/thing/')
Back to Top