kopia lustrzana https://github.com/wagtail/wagtail
Add upgrade note about fixing tests for background tasks (#12794)
* Add upgrade note about fixing tests for background tasks Addition to the upgrade note added in https://github.com/wagtail/wagtail/pull/12787 to cover how to update tests that make database changes and expect to see the results reflected immediately in search queries and other processes that now only happen at the end of a transaction. * Update docs/releases/6.4.md Co-authored-by: sage <laymonage@gmail.com> --------- Co-authored-by: sage <laymonage@gmail.com>pull/12727/merge
rodzic
6a7792e910
commit
ab7547c6cb
|
@ -206,6 +206,19 @@ TASKS = {
|
|||
}
|
||||
```
|
||||
|
||||
Django's test framework typically runs tests inside transactions, and so this situation is also likely to arise in tests that perform database updates and then - within the same test - expect these changes to be immediately reflected in search queries, object usage counts, and other processes that are now handled with background tasks. This can be addressed by setting `ENQUEUE_ON_COMMIT` to `False` as above in the test settings, or by wrapping the database updates in `with self.captureOnCommitCallbacks(execute=True)` to ensure that these tasks are completed before the test continues:
|
||||
|
||||
```python
|
||||
def test_search(self):
|
||||
home_page = Page.objects.get(slug="home")
|
||||
|
||||
with self.captureOnCommitCallbacks(execute=True): # Added
|
||||
home_page.add_child(instance=EventPage(title="Christmas party"))
|
||||
|
||||
response = self.client.get("/search/?q=Christmas")
|
||||
self.assertContains(response, "Christmas party")
|
||||
```
|
||||
|
||||
## Upgrade considerations - deprecation of old functionality
|
||||
|
||||
## Upgrade considerations - changes affecting Wagtail customizations
|
||||
|
|
Ładowanie…
Reference in New Issue