summaryrefslogtreecommitdiffstats
path: root/cachalot/tests/write.py
diff options
context:
space:
mode:
Diffstat (limited to 'cachalot/tests/write.py')
-rw-r--r--cachalot/tests/write.py128
1 files changed, 84 insertions, 44 deletions
diff --git a/cachalot/tests/write.py b/cachalot/tests/write.py
index aa43425..90e1c30 100644
--- a/cachalot/tests/write.py
+++ b/cachalot/tests/write.py
@@ -468,50 +468,6 @@ class WriteTestCase(TransactionTestCase):
data12 = list(User.objects.exclude(user_permissions=None))
self.assertListEqual(data12, [])
- def test_invalidate_raw_subquery(self):
- permission = Permission.objects.first()
- raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
- (permission.pk,))
- with self.assertNumQueries(1):
- data1 = list(Test.objects.filter(permission=raw_sql))
- with self.assertNumQueries(0):
- data2 = list(Test.objects.filter(permission=raw_sql))
- self.assertListEqual(data2, data1)
- self.assertListEqual(data2, [])
-
- test = Test.objects.create(name='test', permission=permission)
-
- with self.assertNumQueries(1):
- data3 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- with self.assertNumQueries(0):
- data4 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- self.assertListEqual(data4, data3)
- self.assertListEqual(data4, [test])
-
- Permission.objects.first().save()
-
- with self.assertNumQueries(1):
- data5 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- with self.assertNumQueries(0):
- data6 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- self.assertListEqual(data6, data5)
- self.assertListEqual(data6, [test])
-
- test.delete()
-
- with self.assertNumQueries(1):
- data7 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- with self.assertNumQueries(0):
- data8 = list(Test.objects.filter(
- pk__in=Test.objects.filter(permission=raw_sql)))
- self.assertListEqual(data8, data7)
- self.assertListEqual(data8, [])
-
def test_invalidate_nested_subqueries(self):
with self.assertNumQueries(1):
data1 = list(
@@ -574,6 +530,90 @@ class WriteTestCase(TransactionTestCase):
)
self.assertListEqual(data5, [])
+ def test_invalidate_raw_subquery(self):
+ permission = Permission.objects.first()
+ raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
+ (permission.pk,))
+ with self.assertNumQueries(1):
+ data1 = list(Test.objects.filter(permission=raw_sql))
+ with self.assertNumQueries(0):
+ data2 = list(Test.objects.filter(permission=raw_sql))
+ self.assertListEqual(data2, data1)
+ self.assertListEqual(data2, [])
+
+ test = Test.objects.create(name='test', permission=permission)
+
+ with self.assertNumQueries(1):
+ data3 = list(Test.objects.filter(permission=raw_sql))
+ with self.assertNumQueries(0):
+ data4 = list(Test.objects.filter(permission=raw_sql))
+ self.assertListEqual(data4, data3)
+ self.assertListEqual(data4, [test])
+
+ Permission.objects.first().save()
+
+ with self.assertNumQueries(1):
+ data5 = list(Test.objects.filter(permission=raw_sql))
+ with self.assertNumQueries(0):
+ data6 = list(Test.objects.filter(permission=raw_sql))
+ self.assertListEqual(data6, data5)
+ self.assertListEqual(data6, [test])
+
+ test.delete()
+
+ with self.assertNumQueries(1):
+ data7 = list(Test.objects.filter(permission=raw_sql))
+ with self.assertNumQueries(0):
+ data8 = list(Test.objects.filter(permission=raw_sql))
+ self.assertListEqual(data8, data7)
+ self.assertListEqual(data8, [])
+
+ def test_invalidate_nested_raw_subquery(self):
+ permission = Permission.objects.first()
+ raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
+ (permission.pk,))
+ with self.assertNumQueries(1):
+ data1 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ with self.assertNumQueries(0):
+ data2 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ self.assertListEqual(data2, data1)
+ self.assertListEqual(data2, [])
+
+ test = Test.objects.create(name='test', permission=permission)
+
+ with self.assertNumQueries(1):
+ data3 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ with self.assertNumQueries(0):
+ data4 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ self.assertListEqual(data4, data3)
+ self.assertListEqual(data4, [test])
+
+ Permission.objects.first().save()
+
+ with self.assertNumQueries(1):
+ data5 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ with self.assertNumQueries(0):
+ data6 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ self.assertListEqual(data6, data5)
+ self.assertListEqual(data6, [test])
+
+ test.delete()
+
+ with self.assertNumQueries(1):
+ data7 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ with self.assertNumQueries(0):
+ data8 = list(Test.objects.filter(
+ pk__in=Test.objects.filter(permission=raw_sql)))
+ self.assertListEqual(data8, data7)
+ self.assertListEqual(data8, [])
+
def test_invalidate_select_related(self):
with self.assertNumQueries(1):
data1 = list(Test.objects.select_related('owner'))