Skip to content

Commit

Permalink
chore: Attempt to create tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Sep 3, 2024
1 parent 180fd69 commit bb0e7f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion edx_name_affirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions edx_name_affirmation/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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
Expand Down

0 comments on commit bb0e7f9

Please sign in to comment.