Skip to content

Commit eea62de

Browse files
test: assert award task scheduled via transaction.on_commit
Address Copilot review: explicitly assert on_commit is invoked so the race-condition fix is covered. Without it, tests would still pass if .delay were called directly. Assert on_commit fires in the enabled case and not in the records-disabled case.
1 parent 1853157 commit eea62de

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

openedx/core/djangoapps/programs/tests/test_signals.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def test_credentials_enabled(self, mock_on_commit, mock_is_learner_issuance_enab
153153
handle_course_cert_changed(**self.signal_kwargs)
154154

155155
assert mock_is_learner_issuance_enabled.call_count == 1
156+
assert mock_on_commit.call_count == 1
156157
assert mock_task.call_count == 1
157158
assert mock_task.call_args[0] == (TEST_USERNAME, str(TEST_COURSE_KEY))
158159

@@ -162,15 +163,18 @@ def test_records_enabled(self, mock_on_commit, mock_is_learner_issuance_enabled,
162163

163164
site_config = SiteConfigurationFactory.create(site_values={"course_org_filter": ["edX"]})
164165

165-
# Correctly sent
166+
# Correctly sent (scheduled via transaction.on_commit)
166167
handle_course_cert_changed(**self.signal_kwargs)
168+
assert mock_on_commit.called
167169
assert mock_task.called
170+
mock_on_commit.reset_mock()
168171
mock_task.reset_mock()
169172

170173
# Correctly not sent
171174
site_config.site_values["ENABLE_LEARNER_RECORDS"] = False
172175
site_config.save()
173176
handle_course_cert_changed(**self.signal_kwargs)
177+
assert not mock_on_commit.called
174178
assert not mock_task.called
175179

176180

0 commit comments

Comments
 (0)