Refs #27694 -- Added more tests for chaining lookups with HStoreField key transforms.
This commit is contained in:
parent
c2f6c05c4c
commit
533f345c09
|
@ -78,6 +78,10 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
HStoreModel(field={'c': 'd'}),
|
||||
HStoreModel(field={}),
|
||||
HStoreModel(field=None),
|
||||
HStoreModel(field={'cat': 'TigrOu', 'breed': 'birman'}),
|
||||
HStoreModel(field={'cat': 'minou', 'breed': 'ragdoll'}),
|
||||
HStoreModel(field={'cat': 'kitty', 'breed': 'Persian'}),
|
||||
HStoreModel(field={'cat': 'Kit Kat', 'breed': 'persian'}),
|
||||
])
|
||||
|
||||
def test_exact(self):
|
||||
|
@ -141,7 +145,7 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
qs = HStoreModel.objects.annotate(a=F('field__a'))
|
||||
self.assertCountEqual(
|
||||
qs.values_list('a', flat=True),
|
||||
['b', 'b', None, None, None],
|
||||
['b', 'b', None, None, None, None, None, None, None],
|
||||
)
|
||||
|
||||
def test_keys(self):
|
||||
|
@ -156,12 +160,60 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
self.objs[:1]
|
||||
)
|
||||
|
||||
def test_field_chaining(self):
|
||||
def test_field_chaining_contains(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__a__contains='b'),
|
||||
self.objs[:2]
|
||||
)
|
||||
|
||||
def test_field_chaining_icontains(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__icontains='INo'),
|
||||
[self.objs[6]],
|
||||
)
|
||||
|
||||
def test_field_chaining_startswith(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__startswith='kit'),
|
||||
[self.objs[7]],
|
||||
)
|
||||
|
||||
def test_field_chaining_istartswith(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__istartswith='kit'),
|
||||
self.objs[7:],
|
||||
)
|
||||
|
||||
def test_field_chaining_endswith(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__endswith='ou'),
|
||||
[self.objs[6]],
|
||||
)
|
||||
|
||||
def test_field_chaining_iendswith(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__iendswith='ou'),
|
||||
self.objs[5:7],
|
||||
)
|
||||
|
||||
def test_field_chaining_iexact(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__breed__iexact='persian'),
|
||||
self.objs[7:],
|
||||
)
|
||||
|
||||
def test_field_chaining_regex(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__regex=r'ou$'),
|
||||
[self.objs[6]],
|
||||
)
|
||||
|
||||
def test_field_chaining_iregex(self):
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__cat__iregex=r'oU$'),
|
||||
self.objs[5:7],
|
||||
)
|
||||
|
||||
def test_order_by_field(self):
|
||||
more_objs = (
|
||||
HStoreModel.objects.create(field={'g': '637'}),
|
||||
|
@ -190,7 +242,7 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
obj = HStoreModel.objects.create(field={'a': None})
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__a__isnull=True),
|
||||
self.objs[2:5] + [obj]
|
||||
self.objs[2:9] + [obj],
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
HStoreModel.objects.filter(field__a__isnull=False),
|
||||
|
|
Loading…
Reference in New Issue