Refs #26610 -- Added CIText mixin and CIChar/Email/TextField.

This commit is contained in:
Mads Jensen 2017-02-11 13:16:35 +01:00 committed by Tim Graham
parent fe2d288434
commit fb5bd38e3b
7 changed files with 71 additions and 36 deletions

View file

@ -6,25 +6,31 @@ modifiers to enforce use of an index.
from django.db import IntegrityError
from . import PostgreSQLTestCase
from .models import CITextTestModel
from .models import CITestModel
class CITextTestCase(PostgreSQLTestCase):
@classmethod
def setUpTestData(cls):
CITextTestModel.objects.create(name='JoHn')
cls.john = CITestModel.objects.create(
name='JoHn',
email='joHn@johN.com',
description='Average Joe named JoHn',
)
def test_equal_lowercase(self):
"""
citext removes the need for iexact as the index is case-insensitive.
"""
self.assertEqual(CITextTestModel.objects.filter(name='john').count(), 1)
self.assertEqual(CITestModel.objects.filter(name=self.john.name.lower()).count(), 1)
self.assertEqual(CITestModel.objects.filter(email=self.john.email.lower()).count(), 1)
self.assertEqual(CITestModel.objects.filter(description=self.john.description.lower()).count(), 1)
def test_fail_case(self):
def test_fail_citext_primary_key(self):
"""
Creating an entry for a citext-field which clashes with an existing
value isn't allowed.
Creating an entry for a citext field used as a primary key which
clashes with an existing value isn't allowed.
"""
with self.assertRaises(IntegrityError):
CITextTestModel.objects.create(name='John')
CITestModel.objects.create(name='John')