summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-10-31 20:33:16 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-05 11:48:44 +0100
commit47379d027ba2786403969367ec9c721936a823f8 (patch)
treec2aec2c7500c8910e2eec386697a31b65f2daeff /tests/postgres_tests
parentdc60597eb643814e54fbb0f7dadfe68c634e52fa (diff)
Fixed #30095 -- Fixed system check for RangeField/ArrayField.choices with lists and tuples.
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_array.py14
-rw-r--r--tests/postgres_tests/test_ranges.py14
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 379a1e9bba..7b7793f6c1 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -592,6 +592,20 @@ class TestChecks(PostgreSQLSimpleTestCase):
self.assertEqual(errors[0].id, 'postgres.E001')
self.assertIn('max_length', errors[0].msg)
+ def test_choices_tuple_list(self):
+ class MyModel(PostgreSQLModel):
+ field = ArrayField(
+ models.CharField(max_length=16),
+ choices=[
+ [
+ 'Media',
+ [(['vinyl', 'cd'], 'Audio'), (('vhs', 'dvd'), 'Video')],
+ ],
+ (['mp3', 'mp4'], 'Digital'),
+ ],
+ )
+ self.assertEqual(MyModel._meta.get_field('field').check(), [])
+
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
class TestMigrations(TransactionTestCase):
diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py
index 3702221107..b68f22112f 100644
--- a/tests/postgres_tests/test_ranges.py
+++ b/tests/postgres_tests/test_ranges.py
@@ -10,7 +10,7 @@ from django.test import override_settings
from django.utils import timezone
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
-from .models import RangeLookupsModel, RangesModel
+from .models import PostgreSQLModel, RangeLookupsModel, RangesModel
try:
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
@@ -413,6 +413,18 @@ class TestSerialization(PostgreSQLSimpleTestCase):
self.assertEqual(new_instance.ints, NumericRange(10, None))
+class TestChecks(PostgreSQLSimpleTestCase):
+ def test_choices_tuple_list(self):
+ class Model(PostgreSQLModel):
+ field = pg_fields.IntegerRangeField(
+ choices=[
+ ['1-50', [((1, 25), '1-25'), ([26, 50], '26-50')]],
+ ((51, 100), '51-100'),
+ ],
+ )
+ self.assertEqual(Model._meta.get_field('field').check(), [])
+
+
class TestValidators(PostgreSQLSimpleTestCase):
def test_max(self):