Ticket #12654: test.diff
File test.diff, 2.8 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/admin_util/tests.py
3 3 from django.db import models 4 4 5 5 from django.contrib import admin 6 from django.contrib.admin.util import display_for_field, label_for_field 6 from django.contrib.admin.util import display_for_field, label_for_field, lookup_field 7 7 from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE 8 8 9 9 from models import Article … … 11 11 12 12 13 13 class UtilTests(unittest.TestCase): 14 def test_values_from_lookup_field(self): 15 """ 16 Regression test for #12654: lookup_field 17 """ 18 from django.contrib.sites.models import Site 19 from django.utils.formats import localize 20 from datetime import datetime 14 21 22 SITE_NAME = 'example.com' 23 TITLE_TEXT = 'Some title' 24 CREATED_DATE = datetime.min 25 ADMIN_METHOD = 'admin method' 26 SIMPLE_FUNCTION = 'function' 27 INSTANCE_ATTRIBUTE = 'attr' 28 29 class FakeModelAdmin(object): 30 def get_admin_value(self, obj): 31 return ADMIN_METHOD 32 33 simple_function = lambda obj: SIMPLE_FUNCTION 34 35 article = Article( 36 site=Site(domain=SITE_NAME), 37 title=TITLE_TEXT, 38 created=CREATED_DATE, 39 ) 40 article.non_field = INSTANCE_ATTRIBUTE 41 42 verifications = ( 43 ('site', SITE_NAME), 44 ('created', localize(CREATED_DATE)), 45 ('title', TITLE_TEXT), 46 ('get_admin_value', ADMIN_METHOD), 47 (simple_function, SIMPLE_FUNCTION), 48 ('test_from_model', article.test_from_model()), 49 ('non_field', INSTANCE_ATTRIBUTE) 50 ) 51 52 for name, value in verifications: 53 field, attr, resolved_value = lookup_field( 54 name, 55 article, 56 FakeModelAdmin() 57 ) 58 59 if field is not None: 60 resolved_value = display_for_field(resolved_value, field) 61 62 self.assertEqual(value, resolved_value) 63 15 64 def test_null_display_for_field(self): 16 65 """ 17 66 Regression test for #12550: display_for_field should handle None -
tests/regressiontests/admin_util/models.py
6 6 """ 7 7 A simple Article model for testing 8 8 """ 9 site = models.ForeignKey('sites.Site') 9 10 title = models.CharField(max_length=100) 10 11 title2 = models.CharField(max_length=100, verbose_name="another name") 11 12 created = models.DateTimeField()