| 1 | import unittest |
| 2 | from django.contrib import admin |
| 3 | from django.db import models |
| 4 | from django.contrib.admin.util import display_for_field |
| 5 | from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE |
| 6 | |
| 7 | class UtilTests(unittest.TestCase): |
| 8 | def test_null_display_for_field(self): |
| 9 | """ |
| 10 | Regression test for #12550: display_for_field should not throw |
| 11 | if None value is passed. |
| 12 | """ |
| 13 | display_value = display_for_field(None, models.DateField()) |
| 14 | self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE) |
| 15 | |
| 16 | display_value = display_for_field(None, models.TimeField()) |
| 17 | self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE) |
| 18 | |
| 19 | display_value = display_for_field(None, models.NullBooleanField()) |
| 20 | self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE) |
| 21 | |
| 22 | display_value = display_for_field(None, models.DecimalField()) |
| 23 | self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE) |
| 24 | |
| 25 | display_value = display_for_field(None, models.FloatField()) |
| 26 | self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE) |
| 27 | |