From bb0e7f90e4799e0f60a73fb22344d976532fb4ef Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 3 Sep 2024 11:03:04 -0300 Subject: [PATCH] chore: Attempt to create tests --- edx_name_affirmation/models.py | 3 ++- edx_name_affirmation/tests/test_models.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/edx_name_affirmation/models.py b/edx_name_affirmation/models.py index 0dc2056..6bd6db6 100644 --- a/edx_name_affirmation/models.py +++ b/edx_name_affirmation/models.py @@ -52,9 +52,10 @@ def verification_attempt_status(self): try: from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification - except ImportError: + except (ImportError, ModuleNotFoundError): return None + verification = SoftwareSecurePhotoVerification.objects.get(id=self.verification_attempt_id) return verification.status if verification else None diff --git a/edx_name_affirmation/tests/test_models.py b/edx_name_affirmation/tests/test_models.py index 043c1bf..11a186c 100644 --- a/edx_name_affirmation/tests/test_models.py +++ b/edx_name_affirmation/tests/test_models.py @@ -4,15 +4,11 @@ from django.contrib.auth import get_user_model from django.test import TestCase +from unittest.mock import patch, MagicMock from edx_name_affirmation.models import VerifiedName from edx_name_affirmation.statuses import VerifiedNameStatus -try: - from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification -except ImportError: - pass - User = get_user_model() @@ -30,15 +26,23 @@ def setUp(self): ) return super().setUp() - def test_histories(self): + @patch('edx_name_affirmation.models.SoftwareSecurePhotoVerification') + def test_histories(self, sspv_mock): """ Test the model history is recording records as expected """ + idv_attempt_id = 34455 + idv_attempt_status = 'submitted' + + sspv_instance = MagicMock() + sspv_instance.objects.get.return_value = lambda id : idv_attempt_status if id == idv_attempt_id else None + sspv_mock.return_value = sspv_instance + verified_name_history = self.verified_name.history.all().order_by('history_date') assert len(verified_name_history) == 1 - idv_attempt_id = 34455 self.verified_name.status = VerifiedNameStatus.APPROVED self.verified_name.verification_attempt_id = idv_attempt_id + assert self.verified_name.verification_attempt_status is idv_attempt_status self.verified_name.save() verified_name_history = self.verified_name.history.all().order_by('history_date') assert len(verified_name_history) == 2