mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Refs #28404 -- Split test_null_display_for_field() test.
This commit is contained in:
parent
415982be10
commit
1b0a8991ae
@ -149,43 +149,33 @@ class UtilsTests(SimpleTestCase):
|
||||
|
||||
self.assertEqual(value, resolved_value)
|
||||
|
||||
def test_null_display_for_field(self):
|
||||
"""
|
||||
Regression test for #12550: display_for_field should handle None
|
||||
value.
|
||||
"""
|
||||
display_value = display_for_field(None, models.CharField(), self.empty_value)
|
||||
def test_empty_value_display_for_field(self):
|
||||
tests = [
|
||||
models.CharField(),
|
||||
models.DateField(),
|
||||
models.DecimalField(),
|
||||
models.FloatField(),
|
||||
models.JSONField(),
|
||||
models.TimeField(),
|
||||
]
|
||||
for model_field in tests:
|
||||
with self.subTest(model_field=model_field):
|
||||
display_value = display_for_field(None, model_field, self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
display_value = display_for_field(
|
||||
None, models.CharField(choices=((None, "test_none"),)), self.empty_value
|
||||
)
|
||||
def test_empty_value_display_choices(self):
|
||||
model_field = models.CharField(choices=((None, "test_none"),))
|
||||
display_value = display_for_field(None, model_field, self.empty_value)
|
||||
self.assertEqual(display_value, "test_none")
|
||||
|
||||
display_value = display_for_field(None, models.DateField(), self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
display_value = display_for_field(None, models.TimeField(), self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
display_value = display_for_field(
|
||||
None, models.BooleanField(null=True), self.empty_value
|
||||
)
|
||||
def test_empty_value_display_booleanfield(self):
|
||||
model_field = models.BooleanField(null=True)
|
||||
display_value = display_for_field(None, model_field, self.empty_value)
|
||||
expected = (
|
||||
'<img src="%sadmin/img/icon-unknown.svg" alt="None" />'
|
||||
% settings.STATIC_URL
|
||||
f'<img src="{settings.STATIC_URL}admin/img/icon-unknown.svg" alt="None" />'
|
||||
)
|
||||
self.assertHTMLEqual(display_value, expected)
|
||||
|
||||
display_value = display_for_field(None, models.DecimalField(), self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
display_value = display_for_field(None, models.FloatField(), self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
display_value = display_for_field(None, models.JSONField(), self.empty_value)
|
||||
self.assertEqual(display_value, self.empty_value)
|
||||
|
||||
def test_json_display_for_field(self):
|
||||
tests = [
|
||||
({"a": {"b": "c"}}, '{"a": {"b": "c"}}'),
|
||||
|
Loading…
Reference in New Issue
Block a user