summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_unaccent.py
diff options
context:
space:
mode:
authorThomas Chaumeny <t.chaumeny@gmail.com>2014-09-05 22:53:11 +0200
committerTim Graham <timograham@gmail.com>2014-11-28 18:22:20 -0500
commit17fe0bd808a47f37dd1351adb01a8ad2cc852f24 (patch)
treea25e46a939ec1471c54a2dadf8ed57ec029afe1e /tests/postgres_tests/test_unaccent.py
parent47789410dbf351fd17a7854492b7b5b99a66bb1c (diff)
Fixed #23423 -- Added unaccent lookup in django.contrib.postgres
Diffstat (limited to 'tests/postgres_tests/test_unaccent.py')
-rw-r--r--tests/postgres_tests/test_unaccent.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_unaccent.py b/tests/postgres_tests/test_unaccent.py
new file mode 100644
index 0000000000..47ccbda519
--- /dev/null
+++ b/tests/postgres_tests/test_unaccent.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+import unittest
+
+from django.db import connection
+from django.test import TestCase, modify_settings
+
+from .models import CharFieldModel, TextFieldModel
+
+
+@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
+@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
+class UnaccentTest(TestCase):
+
+ Model = CharFieldModel
+
+ def setUp(self):
+ self.Model.objects.bulk_create([
+ self.Model(field="àéÖ"),
+ self.Model(field="aeO"),
+ self.Model(field="aeo"),
+ ])
+
+ def test_unaccent(self):
+ self.assertQuerysetEqual(
+ self.Model.objects.filter(field__unaccent="aeO"),
+ ["àéÖ", "aeO"],
+ transform=lambda instance: instance.field,
+ ordered=False
+ )
+
+ def test_unaccent_chained(self):
+ """
+ Check that unaccent can be used chained with a lookup (which should be
+ the case since unaccent implements the Transform API)
+ """
+ self.assertQuerysetEqual(
+ self.Model.objects.filter(field__unaccent__iexact="aeO"),
+ ["àéÖ", "aeO", "aeo"],
+ transform=lambda instance: instance.field,
+ ordered=False
+ )
+ self.assertQuerysetEqual(
+ self.Model.objects.filter(field__unaccent__endswith="éÖ"),
+ ["àéÖ", "aeO"],
+ transform=lambda instance: instance.field,
+ ordered=False
+ )
+
+ def test_unaccent_accentuated_needle(self):
+ self.assertQuerysetEqual(
+ self.Model.objects.filter(field__unaccent="aéÖ"),
+ ["àéÖ", "aeO"],
+ transform=lambda instance: instance.field,
+ ordered=False
+ )
+
+
+class UnaccentTextFieldTest(UnaccentTest):
+ """
+ TextField should have the exact same behavior as CharField
+ regarding unaccent lookups.
+ """
+ Model = TextFieldModel