summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2019-09-19 12:36:15 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-23 08:24:00 +0200
commit485f65b3c010c25b8d75d1b40156db0fa9d5ca57 (patch)
tree5f4f18284a47dd20671f0143231e4f7345537f90
parent28e769dfe6a65bf604f5adc6a650ab47ba6b3bef (diff)
Refs #29915 -- Added tests for using pattern lookups with values without hyphens for UUIDField.
-rw-r--r--tests/model_fields/test_uuid.py72
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py
index 11e4a689e1..875dac5c84 100644
--- a/tests/model_fields/test_uuid.py
+++ b/tests/model_fields/test_uuid.py
@@ -2,7 +2,9 @@ import json
import uuid
from django.core import exceptions, serializers
-from django.db import IntegrityError, models
+from django.db import IntegrityError, connection, models
+from django.db.models import CharField, F, Value
+from django.db.models.functions import Concat
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
)
@@ -90,11 +92,35 @@ class TestQuerying(TestCase):
NullableUUIDModel.objects.create(field=None),
]
+ def assertSequenceEqualWithoutHyphens(self, qs, result):
+ """
+ Backends with a native datatype for UUID don't support fragment lookups
+ without hyphens because they store values with them.
+ """
+ self.assertSequenceEqual(
+ qs,
+ [] if connection.features.has_native_uuid_field else result,
+ )
+
def test_exact(self):
self.assertSequenceEqual(
NullableUUIDModel.objects.filter(field__exact='550e8400e29b41d4a716446655440000'),
[self.objs[1]]
)
+ self.assertSequenceEqual(
+ NullableUUIDModel.objects.filter(
+ field__exact='550e8400-e29b-41d4-a716-446655440000'
+ ),
+ [self.objs[1]],
+ )
+
+ def test_iexact(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(
+ field__iexact='550E8400E29B41D4A716446655440000'
+ ),
+ [self.objs[1]],
+ )
def test_isnull(self):
self.assertSequenceEqual(
@@ -102,6 +128,50 @@ class TestQuerying(TestCase):
[self.objs[2]]
)
+ def test_contains(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__contains='8400e29b'),
+ [self.objs[1]],
+ )
+
+ def test_icontains(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__icontains='8400E29B'),
+ [self.objs[1]],
+ )
+
+ def test_startswith(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__startswith='550e8400e29b4'),
+ [self.objs[1]],
+ )
+
+ def test_istartswith(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__istartswith='550E8400E29B4'),
+ [self.objs[1]],
+ )
+
+ def test_endswith(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__endswith='a716446655440000'),
+ [self.objs[1]],
+ )
+
+ def test_iendswith(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.filter(field__iendswith='A716446655440000'),
+ [self.objs[1]],
+ )
+
+ def test_filter_with_expr(self):
+ self.assertSequenceEqualWithoutHyphens(
+ NullableUUIDModel.objects.annotate(
+ value=Concat(Value('8400'), Value('e29b'), output_field=CharField()),
+ ).filter(field__contains=F('value')),
+ [self.objs[1]],
+ )
+
class TestSerialization(SimpleTestCase):
test_data = (