|
2 | 2 | Unit tests for the VerificationDeadline signals |
3 | 3 | """ |
4 | 4 |
|
5 | | - |
6 | 5 | from datetime import timedelta |
7 | 6 | from unittest.mock import patch # pylint: disable=wrong-import-order |
8 | 7 |
|
| 8 | +from django.db import connection |
| 9 | +from django.test import override_settings |
| 10 | +from django.test.utils import CaptureQueriesContext |
9 | 11 | from django.utils.timezone import now |
10 | 12 |
|
11 | 13 | from common.djangoapps.student.models_api import do_name_change_request |
12 | 14 | from common.djangoapps.student.tests.factories import UserFactory |
13 | 15 | from lms.djangoapps.verify_student.models import ( |
| 16 | + ManualVerification, |
14 | 17 | SoftwareSecurePhotoVerification, |
15 | 18 | VerificationAttempt, |
16 | 19 | VerificationDeadline, |
|
25 | 28 | VerificationAttemptFactory, |
26 | 29 | ) |
27 | 30 | from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import fake_completed_retirement |
| 31 | +from openedx.core.djangolib.testing.utils import assert_redact_before_delete |
28 | 32 | from xmodule.modulestore.tests.django_utils import ( |
29 | 33 | ModuleStoreTestCase, # pylint: disable=wrong-import-order |
30 | 34 | ) |
@@ -70,7 +74,7 @@ def test_deadline_explicit(self): |
70 | 74 |
|
71 | 75 | class RetirementHandlerTest(ModuleStoreTestCase): |
72 | 76 | """ |
73 | | - Tests for the VerificationDeadline handler |
| 77 | + Tests for verify_student handlers in the LMS retirement flow. |
74 | 78 | """ |
75 | 79 |
|
76 | 80 | def _create_entry(self): |
@@ -118,6 +122,42 @@ def test_idempotent(self): |
118 | 122 | for field in ('name', 'face_image_url', 'photo_id_image_url', 'photo_id_key'): |
119 | 123 | assert '' == getattr(ver_obj, field) |
120 | 124 |
|
| 125 | + def test_manual_verification_retirement_behavior(self): |
| 126 | + user = UserFactory() |
| 127 | + other_user = UserFactory() |
| 128 | + user_name = 'Manual Verification Name' |
| 129 | + ManualVerification.objects.create( |
| 130 | + user=user, |
| 131 | + name=user_name, |
| 132 | + status='approved', |
| 133 | + ) |
| 134 | + ManualVerification.objects.create( |
| 135 | + user=other_user, |
| 136 | + name=user_name, |
| 137 | + status='approved', |
| 138 | + ) |
| 139 | + |
| 140 | + with override_settings(REDACT_MANUAL_VERIFICATION_HISTORICAL_PII=False): |
| 141 | + _listen_for_lms_retire(sender=self.__class__, user=user) |
| 142 | + |
| 143 | + manual_verification = ManualVerification.objects.get(user=user) |
| 144 | + assert manual_verification.name == user_name |
| 145 | + assert ManualVerification.objects.filter(user=user).exists() |
| 146 | + assert ManualVerification.objects.filter(user=other_user, name=user_name).exists() |
| 147 | + |
| 148 | + with override_settings(REDACT_MANUAL_VERIFICATION_HISTORICAL_PII=True): |
| 149 | + with CaptureQueriesContext(connection) as context: |
| 150 | + _listen_for_lms_retire(sender=self.__class__, user=user) |
| 151 | + |
| 152 | + assert_redact_before_delete( |
| 153 | + [query['sql'] for query in context.captured_queries], |
| 154 | + table=ManualVerification._meta.db_table, |
| 155 | + expected_redacted_value_list=[''], |
| 156 | + ) |
| 157 | + assert not ManualVerification.objects.filter(user=user).exists() |
| 158 | + |
| 159 | + assert ManualVerification.objects.filter(user=other_user, name=user_name).exists() |
| 160 | + |
121 | 161 |
|
122 | 162 | class PostSavePhotoVerificationTest(ModuleStoreTestCase): |
123 | 163 | """ |
|
0 commit comments