|
5 | 5 | from completion import models |
6 | 6 | from completion.test_utils import CompletionWaffleTestMixin |
7 | 7 | from django.db import connection |
| 8 | +from django.db.models.signals import pre_delete |
8 | 9 | from django.test import TestCase |
9 | 10 | from django.test.utils import CaptureQueriesContext, override_settings |
10 | 11 | from social_django.models import UserSocialAuth |
11 | 12 |
|
12 | 13 | from common.djangoapps.student.models import CourseEnrollment |
13 | 14 | from common.djangoapps.student.tests.factories import UserFactory |
14 | | -from openedx.core.djangoapps.user_api.accounts.signals import get_redacted_social_auth_uid |
| 15 | +from openedx.core.djangoapps.user_api.accounts.signals import get_redacted_social_auth_uid, redact_social_auth_pii_before_deletion |
15 | 16 | from openedx.core.djangoapps.user_api.accounts.utils import ( |
16 | 17 | redact_and_delete_social_auth, |
17 | 18 | retrieve_last_sitewide_block_completed, |
@@ -145,8 +146,25 @@ def test_retrieve_last_sitewide_block_completed(self): |
145 | 146 | class RedactAndDeleteSocialAuthTest(TestCase): |
146 | 147 | """ |
147 | 148 | Tests for the redact_and_delete_social_auth utility function. |
| 149 | +
|
| 150 | + The safety-net pre_delete signal handler is disconnected for all tests in this class |
| 151 | + to verify that redact_and_delete_social_auth itself redacts before deleting, |
| 152 | + not the fallback signal. |
148 | 153 | """ |
149 | 154 |
|
| 155 | + @classmethod |
| 156 | + def setUpClass(cls): |
| 157 | + super().setUpClass() |
| 158 | + # Disconnect the safety-net signal so tests verify redact_and_delete_social_auth |
| 159 | + # itself issues the UPDATE before DELETE, not the signal. |
| 160 | + pre_delete.disconnect(redact_social_auth_pii_before_deletion, sender=UserSocialAuth) |
| 161 | + |
| 162 | + @classmethod |
| 163 | + def tearDownClass(cls): |
| 164 | + super().tearDownClass() |
| 165 | + # Reconnect the signal after the test class completes. |
| 166 | + pre_delete.connect(redact_social_auth_pii_before_deletion, sender=UserSocialAuth) |
| 167 | + |
150 | 168 | def setUp(self): |
151 | 169 | super().setUp() |
152 | 170 | self.user = UserFactory.create(username='testuser', email='testuser@example.com') |
@@ -183,17 +201,6 @@ def create_social_auth(self, provider='google-oauth2', uid='user@example.com', e |
183 | 201 | extra_data=extra_data, |
184 | 202 | ) |
185 | 203 |
|
186 | | - def test_get_redacted_social_auth_uid_format(self): |
187 | | - """ |
188 | | - Test that get_redacted_social_auth_uid returns the expected string format. |
189 | | -
|
190 | | - This is the single source of truth for the redacted uid format. |
191 | | - If this test breaks, the bulk retirement Concat/Cast in utils.py and |
192 | | - retire_user.py must also be updated to match. |
193 | | - """ |
194 | | - assert get_redacted_social_auth_uid(42) == 'redacted-before-delete-42@safe.com' |
195 | | - assert get_redacted_social_auth_uid(1) == 'redacted-before-delete-1@safe.com' |
196 | | - |
197 | 204 | def test_redact_and_delete_issues_update_before_delete(self): |
198 | 205 | """ |
199 | 206 | Test that redact_and_delete_social_auth issues an UPDATE (redaction) before the DELETE. |
|
0 commit comments