summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-08-22 23:30:14 +0200
committerCarlton Gibson <carlton@noumenal.es>2022-08-23 15:51:42 +0200
commit897f38fabea5e1b196f11250ff6dadfffa489840 (patch)
treedf26436ba26484c23809978af9b6732a593ee35e /tests/postgres_tests/test_array.py
parent4488a25cc93eab28fc25ffc464e08f075642fa27 (diff)
downloaddjango-897f38fabea5e1b196f11250ff6dadfffa489840.tar.gz
Fixed #33927 -- Fixed crash when displaying ArrayField with choices in admin.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 1100e8f3b0..436838dd09 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -5,6 +5,7 @@ import unittest
import uuid
from django import forms
+from django.contrib.admin.utils import display_for_field
from django.core import checks, exceptions, serializers, validators
from django.core.exceptions import FieldError
from django.core.management import call_command
@@ -1366,3 +1367,39 @@ class TestSplitFormWidget(PostgreSQLWidgetTestCase):
),
False,
)
+
+
+class TestAdminUtils(PostgreSQLTestCase):
+ empty_value = "-empty-"
+
+ def test_array_display_for_field(self):
+ array_field = ArrayField(models.IntegerField())
+ display_value = display_for_field(
+ [1, 2],
+ array_field,
+ self.empty_value,
+ )
+ self.assertEqual(display_value, "1, 2")
+
+ def test_array_with_choices_display_for_field(self):
+ array_field = ArrayField(
+ models.IntegerField(),
+ choices=[
+ ([1, 2, 3], "1st choice"),
+ ([1, 2], "2nd choice"),
+ ],
+ )
+
+ display_value = display_for_field(
+ [1, 2],
+ array_field,
+ self.empty_value,
+ )
+ self.assertEqual(display_value, "2nd choice")
+
+ display_value = display_for_field(
+ [99, 99],
+ array_field,
+ self.empty_value,
+ )
+ self.assertEqual(display_value, self.empty_value)