Ticket #24316: 24316_test_case.diff

File 24316_test_case.diff, 2.1 KB (added by JordanBright, 10 years ago)
  • tests/admin_changelist/admin.py

    diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
    index b2bd578..8dbd810 100644
    a b class CustomPaginator(Paginator):  
    1818
    1919
    2020class EventAdmin(admin.ModelAdmin):
    21     list_display = ['event_date_func']
     21    event_year_lambda = lambda event: event.date.year
     22    event_year_lambda.short_description = 'Year'
     23
     24    list_display = ['event_date_func', event_year_lambda]
    2225
    2326    def event_date_func(self, event):
    2427        return event.date
  • tests/admin_changelist/tests.py

    diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
    index 431999d..38efc22 100644
    a b class ChangeListTests(TestCase):  
    369369        self.assertContains(response, formats.localize(event.date))
    370370        self.assertNotContains(response, six.text_type(event.date))
    371371
     372    def test_list_display_css_class_of_function_uses_short_description_in_th(self):
     373        User.objects.create_superuser(
     374            username='super', email='super@localhost', password='secret')
     375        self.client.login(username='super', password='secret')
     376        event = Event.objects.create(date=datetime.date.today())
     377        response = self.client.get('/admin/admin_changelist/event/')
     378        self.assertNotContains(response, 'class="column-<function <lambda>')
     379        self.assertContains(response, 'class="column-year"')
     380
     381    def test_list_display_css_class_of_function_uses_short_description_in_td(self):
     382        User.objects.create_superuser(
     383            username='super', email='super@localhost', password='secret')
     384        self.client.login(username='super', password='secret')
     385        event = Event.objects.create(date=datetime.date.today())
     386        response = self.client.get('/admin/admin_changelist/event/')
     387        self.assertNotContains(response, 'class="field-<function <lambda>')
     388        self.assertContains(response, 'class="field-year"')
     389
    372390    def test_dynamic_list_display(self):
    373391        """
    374392        Regression tests for #14206: dynamic list_display support.
Back to Top