summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-02 12:39:15 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-05 14:16:25 +0200
commit0e02e496cdc75741a789f8694f66e776bb8214f1 (patch)
tree895b47bf31b150661c48a32b63975dceca71a16f /tests/postgres_tests/test_array.py
parent25f21bd2376603c8e233a0a0e5a726a0fdfdd33e (diff)
downloaddjango-0e02e496cdc75741a789f8694f66e776bb8214f1.tar.gz
Added tests for using ArrayField's IndexTransform/SliceTransform on expressions with params.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 170c1caa0a..fc4c07ea86 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -9,6 +9,8 @@ from django.core import checks, exceptions, serializers, validators
from django.core.exceptions import FieldError
from django.core.management import call_command
from django.db import IntegrityError, connection, models
+from django.db.models.expressions import RawSQL
+from django.db.models.functions import Cast
from django.test import TransactionTestCase, modify_settings, override_settings
from django.test.utils import isolate_apps
from django.utils import timezone
@@ -24,6 +26,7 @@ from .models import (
try:
from django.contrib.postgres.fields import ArrayField
+ from django.contrib.postgres.fields.array import IndexTransform, SliceTransform
from django.contrib.postgres.forms import (
SimpleArrayField, SplitArrayField, SplitArrayWidget,
)
@@ -304,6 +307,18 @@ class TestQuerying(PostgreSQLTestCase):
[instance]
)
+ def test_index_transform_expression(self):
+ expr = RawSQL("string_to_array(%s, ';')", ['1;2'])
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(
+ field__0=Cast(
+ IndexTransform(1, models.IntegerField, expr),
+ output_field=models.IntegerField(),
+ ),
+ ),
+ self.objs[:1],
+ )
+
def test_overlap(self):
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(field__overlap=[1, 2]),
@@ -358,6 +373,13 @@ class TestQuerying(PostgreSQLTestCase):
[instance]
)
+ def test_slice_transform_expression(self):
+ expr = RawSQL("string_to_array(%s, ';')", ['9;2;3'])
+ self.assertSequenceEqual(
+ NullableIntegerArrayModel.objects.filter(field__0_2=SliceTransform(2, 3, expr)),
+ self.objs[2:3],
+ )
+
def test_usage_in_subquery(self):
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(