From 1b0a8991aec7079405be6b4be5fb17d69e1f4ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Lazarevi=C4=87?= Date: Mon, 8 Jan 2024 13:41:42 +0700 Subject: [PATCH] Refs #28404 -- Split test_null_display_for_field() test. --- tests/admin_utils/tests.py | 50 +++++++++++++++----------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index 0adee38afa..582ed23b4d 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -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) - self.assertEqual(display_value, 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 = ( - 'None' - % settings.STATIC_URL + f'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"}}'),