-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IDV Status to VerifiedName (#215)
* feat: Adding IDV Status to VerifiedName * fix: Moved attempt status getter from Serialized to Model * fix: Reverted Views unit tests * fix: Updated tests * chore: Added proper tests to model * fix: Added catch to not found exception * chore: Updated tests * fix: Updated tests * chore: Moved test variables to be more localized * chore: Moved test variables to be more localized
- Loading branch information
Showing
4 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
""" | ||
Tests for Name Affirmation models | ||
""" | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.test import TestCase | ||
|
||
from edx_name_affirmation.models import VerifiedName | ||
|
@@ -16,6 +18,9 @@ class VerifiedNameModelTests(TestCase): | |
Test suite for the VerifiedName models | ||
""" | ||
def setUp(self): | ||
self.idv_attempt_id = 34455 | ||
self.idv_attempt_status = 'submitted' | ||
self.idv_attempt_id_notfound = 404 | ||
self.verified_name = 'Test Tester' | ||
self.user = User.objects.create(username='modelTester', email='[email protected]') | ||
self.verified_name = VerifiedName.objects.create( | ||
|
@@ -29,11 +34,11 @@ def test_histories(self): | |
""" | ||
Test the model history is recording records as expected | ||
""" | ||
|
||
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 | ||
self.verified_name.verification_attempt_id = self.idv_attempt_id | ||
self.verified_name.save() | ||
verified_name_history = self.verified_name.history.all().order_by('history_date') | ||
assert len(verified_name_history) == 2 | ||
|
@@ -44,4 +49,37 @@ def test_histories(self): | |
|
||
second_history_record = verified_name_history[1] | ||
assert second_history_record.status == VerifiedNameStatus.APPROVED | ||
assert second_history_record.verification_attempt_id == idv_attempt_id | ||
assert second_history_record.verification_attempt_id == self.idv_attempt_id | ||
|
||
@patch('edx_name_affirmation.models.SoftwareSecurePhotoVerification') | ||
def test_verification_status(self, sspv_mock): | ||
""" | ||
Test the model history is recording records as expected | ||
""" | ||
|
||
idv_attempt_id_notfound_status = None | ||
|
||
sspv_mock.objects.get = self._mocked_model_get | ||
|
||
self.verified_name.verification_attempt_id = self.idv_attempt_id_notfound | ||
assert self.verified_name.verification_attempt_status is idv_attempt_id_notfound_status | ||
|
||
self.verified_name.verification_attempt_id = self.idv_attempt_id | ||
assert self.verified_name.verification_attempt_status is self.idv_attempt_status | ||
|
||
# Helper methods | ||
|
||
def _obj(self, dictionary): | ||
"Helper method to turn a dict into an object. Used to mock below." | ||
|
||
return type('obj', (object,), dictionary) | ||
|
||
def _mocked_model_get(self, id): # pylint: disable=redefined-builtin | ||
"Helper method to mock the behavior of SoftwareSecurePhotoVerification model. Used to mock below." | ||
if id == self.idv_attempt_id_notfound: | ||
raise ObjectDoesNotExist | ||
|
||
if id == self.idv_attempt_id: | ||
return self._obj({'status': self.idv_attempt_status}) | ||
|
||
return self._obj({'status': None}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters