diff options
| author | Sarah Abderemane <sarahabderemane@gmail.com> | 2021-10-01 03:57:56 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-04 07:18:16 +0200 |
| commit | 533f345c09c935ce0117f52aa124599c52ffa80b (patch) | |
| tree | bf038547652489c448c2d67c35f58907abe22b91 | |
| parent | c2f6c05c4cc73e831b7e852eb58bd6d7a83fa46c (diff) | |
Refs #27694 -- Added more tests for chaining lookups with HStoreField key transforms.
| -rw-r--r-- | tests/postgres_tests/test_hstore.py | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py index 0c01129e18..b6fdd2da60 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -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), |
