@@ -108,9 +108,10 @@ def test_cache_purged_for_private_collection(self):
108108 private_collection = CollectionViewRestrictionFactory ().collection
109109 DocumentFactory (collection = private_collection )
110110 with mock .patch (URLOPEN_PATH ) as urlopen_mock :
111- purge_documents_when_collection_saved_with_restrictions (
112- sender = private_collection ._meta .model , instance = private_collection
113- )
111+ with self .captureOnCommitCallbacks (execute = True ):
112+ purge_documents_when_collection_saved_with_restrictions (
113+ sender = private_collection ._meta .model , instance = private_collection
114+ )
114115 urlopen_mock .assert_called ()
115116
116117 @override_settings (
@@ -132,9 +133,10 @@ def test_cache_not_purged_for_public_collection(self):
132133 collection = CollectionFactory ()
133134 DocumentFactory .create_batch (10 , collection = collection )
134135 with mock .patch (URLOPEN_PATH ) as urlopen_mock :
135- purge_documents_when_collection_saved_with_restrictions (
136- sender = collection ._meta .model , instance = collection
137- )
136+ with self .captureOnCommitCallbacks (execute = True ):
137+ purge_documents_when_collection_saved_with_restrictions (
138+ sender = collection ._meta .model , instance = collection
139+ )
138140 urlopen_mock .assert_not_called ()
139141
140142
@@ -158,9 +160,10 @@ class TestPurgeDocumentFromCacheWhenSaved(CreateBucket, TestCase):
158160 def test_create_new_document_purges_cache_for_that_url (self ):
159161 document = DocumentFactory ()
160162 with mock .patch (URLOPEN_PATH ) as urlopen_mock :
161- purge_document_from_cache_when_saved (
162- sender = document ._meta .model , instance = document
163- )
163+ with self .captureOnCommitCallbacks (execute = True ):
164+ purge_document_from_cache_when_saved (
165+ sender = document ._meta .model , instance = document
166+ )
164167 urlopen_mock .assert_called ()
165168
166169 @override_settings (
@@ -181,7 +184,8 @@ def test_create_new_document_purges_cache_for_that_url(self):
181184 def test_delete_document_purges_cache_for_that_url (self ):
182185 document = DocumentFactory ()
183186 with mock .patch (URLOPEN_PATH ) as urlopen_mock :
184- purge_document_from_cache_when_deleted (
185- sender = document ._meta .model , instance = document
186- )
187+ with self .captureOnCommitCallbacks (execute = True ):
188+ purge_document_from_cache_when_deleted (
189+ sender = document ._meta .model , instance = document
190+ )
187191 urlopen_mock .assert_called ()
0 commit comments