From a0da93131739e796faf1389eb4e18a9c2a1e8a1a Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Mon, 30 Sep 2024 10:26:56 -0400 Subject: [PATCH] feat: deprecate get_verification_details_by_id --- lms/djangoapps/verify_student/services.py | 31 ------------ .../verify_student/tests/test_services.py | 48 ------------------ openedx/core/djangoapps/user_api/urls.py | 6 --- .../verification_api/tests/test_views.py | 49 ------------------- .../user_api/verification_api/views.py | 19 ------- 5 files changed, 153 deletions(-) diff --git a/lms/djangoapps/verify_student/services.py b/lms/djangoapps/verify_student/services.py index f0d8a8631482..bee016de7740 100644 --- a/lms/djangoapps/verify_student/services.py +++ b/lms/djangoapps/verify_student/services.py @@ -8,7 +8,6 @@ from urllib.parse import quote from django.conf import settings -from django.core.exceptions import ObjectDoesNotExist from django.utils.timezone import now from django.utils.translation import gettext as _ from openedx_filters.learning.filters import IDVPageURLRequested @@ -249,33 +248,3 @@ def get_verify_location(cls, course_id=None): # .. filter_implemented_name: IDVPageURLRequested # .. filter_type: org.openedx.learning.idv.page.url.requested.v1 return IDVPageURLRequested.run_filter(location) - - @classmethod - def get_verification_details_by_id(cls, attempt_id): - """ - Returns a verification attempt object by attempt_id - If the verification object cannot be found, returns None - - This method does not take into account verifications stored in the - VerificationAttempt model used for pluggable IDV implementations. - - As part of the work to implement pluggable IDV, this method's use - will be deprecated: https://openedx.atlassian.net/browse/OSPR-1011 - """ - verification = None - - # This does not look at the VerificationAttempt model since the provided id would become - # ambiguous between tables. The verification models in this list all inherit from the same - # base class and share the same id space. - verification_models = [ - SoftwareSecurePhotoVerification, - SSOVerification, - ManualVerification, - ] - for ver_model in verification_models: - if not verification: - try: - verification = ver_model.objects.get(id=attempt_id) - except ObjectDoesNotExist: - pass - return verification diff --git a/lms/djangoapps/verify_student/tests/test_services.py b/lms/djangoapps/verify_student/tests/test_services.py index d57993d368af..5b6d740a1ba0 100644 --- a/lms/djangoapps/verify_student/tests/test_services.py +++ b/lms/djangoapps/verify_student/tests/test_services.py @@ -2,9 +2,7 @@ Tests for the service classes in verify_student. """ -import itertools from datetime import datetime, timedelta, timezone -from random import randint from unittest.mock import patch import ddt @@ -231,52 +229,6 @@ def test_get_expiration_datetime_mixed_models(self): expiration_datetime = IDVerificationService.get_expiration_datetime(user, ['approved']) assert expiration_datetime == newest.expiration_datetime - @ddt.data( - {'status': 'denied', 'error_msg': '[{"generalReasons": ["Name mismatch"]}]'}, - {'status': 'approved', 'error_msg': ''}, - {'status': 'submitted', 'error_msg': ''}, - ) - def test_get_verification_details_by_id(self, kwargs): - user = UserFactory.create() - kwargs['user'] = user - sspv = SoftwareSecurePhotoVerification.objects.create(**kwargs) - attempt = IDVerificationService.get_verification_details_by_id(sspv.id) - assert attempt.id == sspv.id - assert attempt.user.id == user.id - assert attempt.status == kwargs['status'] - assert attempt.error_msg == kwargs['error_msg'] - - @ddt.data( - *itertools.product( - [SSOVerification, ManualVerification], - [ - {'status': 'denied'}, - {'status': 'approved'}, - {'status': 'submitted'}, - ] - ) - ) - @ddt.unpack - def test_get_verification_details_other_types(self, verification_model, kwargs): - user = UserFactory.create() - kwargs['user'] = user - model_object = verification_model.objects.create(**kwargs) - - attempt = IDVerificationService.get_verification_details_by_id(model_object.id) - assert attempt.id == model_object.id - assert attempt.user.id == user.id - assert attempt.status == kwargs['status'] - - @ddt.data( - SoftwareSecurePhotoVerification, SSOVerification, ManualVerification - ) - def test_get_verification_details_not_found(self, verification_model): - user = UserFactory.create() - model_object = verification_model.objects.create(user=user) - not_found_id = model_object.id + randint(100, 200) - attempt = IDVerificationService.get_verification_details_by_id(not_found_id) - assert attempt is None - @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @ddt.ddt diff --git a/openedx/core/djangoapps/user_api/urls.py b/openedx/core/djangoapps/user_api/urls.py index e93e7119ecea..6bd34fccc6e5 100644 --- a/openedx/core/djangoapps/user_api/urls.py +++ b/openedx/core/djangoapps/user_api/urls.py @@ -26,7 +26,6 @@ from .verification_api.views import ( IDVerificationStatusView, IDVerificationStatusDetailsView, - IDVerificationSupportView, ) ME = AccountViewSet.as_view({ @@ -147,11 +146,6 @@ IDVerificationStatusDetailsView.as_view(), name='verification_details' ), - re_path( - r'^v1/accounts/verifications/(?P[0-9]+)/$', - IDVerificationSupportView.as_view(), - name='verification_for_support' - ), re_path( fr'^v1/accounts/{settings.USERNAME_PATTERN}/retirement_status/$', RETIREMENT_RETRIEVE, diff --git a/openedx/core/djangoapps/user_api/verification_api/tests/test_views.py b/openedx/core/djangoapps/user_api/verification_api/tests/test_views.py index c585936e21ad..b8f51ef79a59 100644 --- a/openedx/core/djangoapps/user_api/verification_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/verification_api/tests/test_views.py @@ -4,7 +4,6 @@ import datetime import json -import ddt import freezegun from django.conf import settings from django.test import TestCase @@ -258,51 +257,3 @@ def test_multiple_verification_instances(self): }, ] assert json.loads(response.content.decode('utf-8')) == expected - - -@override_settings(VERIFY_STUDENT=VERIFY_STUDENT) -@ddt.ddt -class VerificationSupportViewTests(VerificationViewTestsMixinBase, TestCase): - """ - Tests for the verification_for_support view - """ - @property - def path(self): - return reverse('verification_for_support', kwargs={'attempt_id': self.photo_verification.id}) - - def get_expected_response(self, *args, **kwargs): - return { - 'type': 'Software Secure', - 'status': self.photo_verification.status, - 'expiration_datetime': '{}Z'.format(kwargs.get('expected_expires').isoformat()), - 'message': kwargs.get('error_msg'), - 'updated_at': f'{self.CREATED_AT.isoformat()}Z', - 'receipt_id': self.photo_verification.receipt_id, - } - - @ddt.data( - ('accepted', ''), - ('denied', '[{"generalReasons": ["Name mismatch"]}]'), - ('submitted', ''), - ('must_retry', ''), - ) - @ddt.unpack - def test_get_details(self, status, error_message): - self.photo_verification.status = status - self.photo_verification.error_msg = error_message - self.photo_verification.save() - self.client.login(username=self.staff.username, password=self.PASSWORD) - response = self.assert_verification_returned() - expected_expires = self.CREATED_AT + datetime.timedelta(settings.VERIFY_STUDENT['DAYS_GOOD_FOR']) - expected = self.get_expected_response(expected_expires=expected_expires, error_msg=error_message) - assert json.loads(response.content.decode('utf-8')) == expected - - @ddt.data( - 0, - 234324, - 'not_a_number', - ) - def test_not_found(self, attempt_id): - not_found_path = self.path.replace(str(self.photo_verification.id), str(attempt_id)) - response = self.client.get(not_found_path) - assert response.status_code == 404 diff --git a/openedx/core/djangoapps/user_api/verification_api/views.py b/openedx/core/djangoapps/user_api/verification_api/views.py index 584479596c53..1ef159150cda 100644 --- a/openedx/core/djangoapps/user_api/verification_api/views.py +++ b/openedx/core/djangoapps/user_api/verification_api/views.py @@ -3,7 +3,6 @@ from django.contrib.auth import get_user_model from django.http import Http404 from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from edx_rest_framework_extensions.permissions import IsStaff from rest_framework.authentication import SessionAuthentication from rest_framework.generics import ListAPIView from rest_framework.response import Response @@ -61,21 +60,3 @@ def get_queryset(self): return sorted(verifications, key=lambda x: x.updated_at, reverse=True) except User.DoesNotExist: raise Http404 # lint-amnesty, pylint: disable=raise-missing-from - - -class IDVerificationSupportView(APIView): - """ IDVerification endpoint for support-tool""" - authentication_classes = (JwtAuthentication, BearerAuthentication, SessionAuthentication,) - permission_classes = (IsStaff,) - - def get(self, request, **kwargs): - """ - Get IDV attempt details by attempt_id. Only accessible by global staff. - """ - attempt_id = kwargs.get('attempt_id') - verification_detail = IDVerificationService.get_verification_details_by_id(attempt_id) - if not verification_detail: - raise Http404 - return Response( - IDVerificationDetailsSerializer(verification_detail).data - )