tests: Run on_commit hooks immediately in tornado_redirected_to_list.

Further commits will hook `send_event` calls to `on_commit`
in some cases. This change will make it easier to test such
situations.

We don't need to actually capture the callbacks, because the
events sent are already tested via the list in which they are
captured by `tornado_redirected_to_list`.
This commit is contained in:
Abhijeet Prasad Bodas
2021-06-03 11:38:27 +05:30
parent 8b14704d35
commit 60464a4cea

View File

@@ -1280,7 +1280,13 @@ Output:
# So explicitly change parameter name to 'notice' to work around this problem
django_tornado_api.process_notification = lambda notice: lst.append(notice)
yield
# Some `send_event` calls need to be executed only after the current transaction
# commits (using `on_commit` hooks). Because the transaction in Django tests never
# commits (rather, gets rolled back after the test completes), such events would
# never be sent in tests, and we would be unable to verify them. Hence, we use
# this helper to make sure the `send_event` calls actually run.
with self.captureOnCommitCallbacks(execute=True):
yield
django_tornado_api.process_notification = real_event_queue_process_notification