Ticket #24316: 24316_test_case_1.diff

File 24316_test_case_1.diff, 2.2 KB (added by Manu, 9 years ago)

New TestCase since previous one was passing 2 asserts that it shouldn't

  • tests/admin_changelist/admin.py

    diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
    index 99deafc..ddc0316 100644
    a b class CustomPaginator(Paginator):  
    1717
    1818
    1919class EventAdmin(admin.ModelAdmin):
    20     list_display = ['event_date_func']
     20    event_year_lambda = lambda event: event.date.year
     21    event_year_lambda.short_description = 'Year'
     22
     23    list_display = ['event_date_func', event_year_lambda]
    2124
    2225    def event_date_func(self, event):
    2326        return event.date
     27    event_date_func.short_description = "Event date"
    2428
    2529site.register(Event, EventAdmin)
    2630
  • tests/admin_changelist/tests.py

    diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
    index ded3bfc..251c38d 100644
    a b class ChangeListTests(TestCase):  
    441441        self.assertContains(response, formats.localize(event.date))
    442442        self.assertNotContains(response, six.text_type(event.date))
    443443
     444    def test_list_display_css_class_of_function_uses_short_description_in_th(self):
     445        User.objects.create_superuser(
     446            username='super', email='super@localhost', password='secret')
     447        self.client.login(username='super', password='secret')
     448        event = Event.objects.create(date=datetime.date.today())
     449        response = self.client.get('/admin/admin_changelist/event/')
     450        self.assertNotContains(response, 'class="column-<function EventAdmin.<lambda>')
     451        self.assertContains(response, 'class="column-year"')
     452
     453    def test_list_display_css_class_of_function_uses_short_description_in_td(self):
     454        User.objects.create_superuser(
     455            username='super', email='super@localhost', password='secret')
     456        self.client.login(username='super', password='secret')
     457        event = Event.objects.create(date=datetime.date.today())
     458        response = self.client.get('/admin/admin_changelist/event/')
     459        self.assertNotContains(response, 'class="field-<function EventAdmin.<lambda>')
     460        self.assertContains(response, 'class="field-year"')
     461
    444462    def test_dynamic_list_display(self):
    445463        """
    446464        Regression tests for #14206: dynamic list_display support.
Back to Top