Ticket #11058: tests.diff
File tests.diff, 2.8 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/tests/__init__.py
1 from django.contrib.admin.tests.display import AdminTest 2 -
django/contrib/admin/tests/admin.py
1 from django.contrib import admin 2 from django.contrib.admin.tests.models import TestModel 3 4 def admin_callable(obj): 5 return 'test' 6 7 class 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 15 class 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
1 from django.test import TestCase 2 from django.contrib.admin.validation import validate 3 from django.contrib.admin.tests.models import TestModel 4 from django.contrib.admin.tests.admin import TestModelAdmin, BadTestModelAdmin 5 from django.core.exceptions import ImproperlyConfigured 6 7 class 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
1 from django.db import models 2 3 class TestModel(models.Model): 4 string_field = models.CharField(max_length=50) 5 6 def model_attribute(self): 7 return self.string_field.toupper()