1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #28161 -- Fixed return type of ArrayField(CITextField()).

Thanks Tim for the review.
This commit is contained in:
Simon Charette
2017-05-03 01:25:30 -04:00
parent f37467ec7a
commit b91868507a
8 changed files with 40 additions and 15 deletions

View File

@@ -12,14 +12,14 @@ class PostgreSQLTestCase(TestCase):
@classmethod
def tearDownClass(cls):
# No need to keep that signal overhead for non PostgreSQL-related tests.
from django.contrib.postgres.signals import register_hstore_handler
from django.contrib.postgres.signals import register_type_handlers
connection_created.disconnect(register_hstore_handler)
connection_created.disconnect(register_type_handlers)
super().tearDownClass()
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
# To locate the widget's template.
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
class PostgreSQLWidgetTestCase(WidgetTest):
class PostgreSQLWidgetTestCase(WidgetTest, PostgreSQLTestCase):
pass

View File

@@ -142,6 +142,7 @@ class Migration(migrations.Migration):
('name', CICharField(primary_key=True, max_length=255)),
('email', CIEmailField()),
('description', CITextField()),
('array_field', ArrayField(CITextField(), null=True)),
],
options={
'required_db_vendor': 'postgresql',

View File

@@ -106,6 +106,7 @@ class CITestModel(PostgreSQLModel):
name = CICharField(primary_key=True, max_length=255)
email = CIEmailField()
description = CITextField()
array_field = ArrayField(CITextField(), null=True)
def __str__(self):
return self.name

View File

@@ -4,11 +4,13 @@ strings and thus eliminates the need for operations such as iexact and other
modifiers to enforce use of an index.
"""
from django.db import IntegrityError
from django.test.utils import modify_settings
from . import PostgreSQLTestCase
from .models import CITestModel
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
class CITextTestCase(PostgreSQLTestCase):
@classmethod
@@ -17,6 +19,7 @@ class CITextTestCase(PostgreSQLTestCase):
name='JoHn',
email='joHn@johN.com',
description='Average Joe named JoHn',
array_field=['JoE', 'jOhn'],
)
def test_equal_lowercase(self):
@@ -34,3 +37,8 @@ class CITextTestCase(PostgreSQLTestCase):
"""
with self.assertRaises(IntegrityError):
CITestModel.objects.create(name='John')
def test_array_field(self):
instance = CITestModel.objects.get()
self.assertEqual(instance.array_field, self.john.array_field)
self.assertTrue(CITestModel.objects.filter(array_field__contains=['joe']).exists())