mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-22 11:21:52 +00:00
Adds 2 tests for HAVING queries.
This commit is contained in:
parent
81b63eaff3
commit
67c05ed460
2 changed files with 39 additions and 0 deletions
|
|
@ -457,6 +457,17 @@ class ReadTestCase(TransactionTestCase):
|
|||
self.assertListEqual([t.name for t in data2],
|
||||
['test1', 'test2'])
|
||||
|
||||
def test_having(self):
|
||||
with self.assertNumQueries(1):
|
||||
data1 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data1, [self.user])
|
||||
|
||||
with self.assertNumQueries(0):
|
||||
data2 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data2, [self.user])
|
||||
|
||||
def test_extra_select(self):
|
||||
username_length_sql = """
|
||||
SELECT LENGTH(%(user_table)s.username)
|
||||
|
|
|
|||
|
|
@ -299,6 +299,34 @@ class WriteTestCase(TransactionTestCase):
|
|||
self.assertListEqual(data5, [user1, user2])
|
||||
self.assertListEqual([u.n for u in data5], [3, 2])
|
||||
|
||||
def test_invalidate_having(self):
|
||||
with self.assertNumQueries(1):
|
||||
data1 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data1, [])
|
||||
|
||||
u = User.objects.create_user('user')
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
data2 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data2, [])
|
||||
|
||||
p = Permission.objects.first()
|
||||
p.save()
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
data3 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data3, [])
|
||||
|
||||
u.user_permissions.add(p)
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
data3 = list(User.objects.annotate(n=Count('user_permissions'))
|
||||
.filter(n__gte=1))
|
||||
self.assertListEqual(data3, [u])
|
||||
|
||||
def test_invalidate_subquery(self):
|
||||
with self.assertNumQueries(1):
|
||||
data1 = list(Test.objects.filter(owner__in=User.objects.all()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue