Ticket #11058: tests.diff

File tests.diff, 2.8 KB (added by cmbeelby, 14 years ago)

Test cases to ensure fix doesn't break again later

  • django/contrib/admin/tests/__init__.py

     
     1from django.contrib.admin.tests.display import AdminTest
     2
  • django/contrib/admin/tests/admin.py

     
     1from django.contrib import admin
     2from django.contrib.admin.tests.models import TestModel
     3
     4def admin_callable(obj):
     5    return 'test'
     6
     7class TestModelAdmin(admin.ModelAdmin):
     8    list_display = ('string_field', 'model_admin_attr', 'model_attribute', admin_callable)
     9    list_display_links = ('string_field', 'model_admin_attr', 'model_attribute', admin_callable)
     10
     11    def model_admin_attr(self, obj):
     12        return obj.id
     13
     14
     15class BadTestModelAdmin(admin.ModelAdmin):
     16    list_display = ('string_field', 'model_admin_attr', 'model_attribute', admin_callable)
     17    list_display_links = ('bad_item',)
     18
  • django/contrib/admin/tests/display.py

     
     1from django.test import TestCase
     2from django.contrib.admin.validation import validate
     3from django.contrib.admin.tests.models import TestModel
     4from django.contrib.admin.tests.admin import TestModelAdmin, BadTestModelAdmin
     5from django.core.exceptions import ImproperlyConfigured
     6
     7class AdminTest(TestCase):
     8    def test_list_display(self):
     9        """
     10        This tests that the validate method does not return an
     11        exception on a properly configured model and admin class.
     12        The focus of the test is around the configration of the
     13        list_display and list_display_links variables.
     14        """
     15        try:
     16            validate(TestModelAdmin, TestModel)
     17        except ImproperlyConfigured, msg:
     18            self.fail(msg)
     19
     20    def test_invalid_list_display_links(self):
     21        """
     22        This test confirms that if you have an item in the list_display_links
     23        that is not also in list_display you will get an exception.
     24        """
     25
     26        self.assertRaises(ImproperlyConfigured, validate, BadTestModelAdmin, TestModel)
  • django/contrib/admin/tests/models.py

     
     1from django.db import models
     2
     3class TestModel(models.Model):
     4    string_field = models.CharField(max_length=50)
     5
     6    def model_attribute(self):
     7        return self.string_field.toupper()
Back to Top