forked from openedx/edx-platform
-
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.
Merge pull request openedx#34875 from openedx/michaelroytman/COSMO-31…
…0-idv-approval-email-in-command Send IDV approval email in approve_id_verifications management command
- Loading branch information
Showing
5 changed files
with
115 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
API module. | ||
""" | ||
from django.conf import settings | ||
from django.utils.translation import gettext as _ | ||
|
||
from lms.djangoapps.verify_student.emails import send_verification_approved_email | ||
from lms.djangoapps.verify_student.tasks import send_verification_status_email | ||
|
||
|
||
def send_approval_email(attempt): | ||
""" | ||
Send an approval email to the learner associated with the IDV attempt. | ||
""" | ||
verification_status_email_vars = { | ||
'platform_name': settings.PLATFORM_NAME, | ||
} | ||
|
||
expiration_datetime = attempt.expiration_datetime.date() | ||
if settings.VERIFY_STUDENT.get('USE_DJANGO_MAIL'): | ||
verification_status_email_vars['expiration_datetime'] = expiration_datetime.strftime("%m/%d/%Y") | ||
verification_status_email_vars['full_name'] = attempt.user.profile.name | ||
subject = _("Your {platform_name} ID verification was approved!").format( | ||
platform_name=settings.PLATFORM_NAME | ||
) | ||
context = { | ||
'subject': subject, | ||
'template': 'emails/passed_verification_email.txt', | ||
'email': attempt.user.email, | ||
'email_vars': verification_status_email_vars | ||
} | ||
send_verification_status_email.delay(context) | ||
else: | ||
email_context = {'user': attempt.user, 'expiration_datetime': expiration_datetime.strftime("%m/%d/%Y")} | ||
send_verification_approved_email(context=email_context) |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Tests of API module. | ||
""" | ||
from unittest.mock import patch | ||
|
||
import ddt | ||
from django.conf import settings | ||
from django.core import mail | ||
from django.test import TestCase | ||
|
||
from common.djangoapps.student.tests.factories import UserFactory | ||
from lms.djangoapps.verify_student.api import send_approval_email | ||
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification | ||
|
||
|
||
@ddt.ddt | ||
class TestSendApprovalEmail(TestCase): | ||
""" | ||
Test cases for the send_approval_email API method. | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.user = UserFactory.create() | ||
self.attempt = SoftwareSecurePhotoVerification( | ||
status="submitted", | ||
user=self.user | ||
) | ||
self.attempt.save() | ||
|
||
def _assert_verification_approved_email(self, expiration_date): | ||
"""Check that a verification approved email was sent.""" | ||
assert len(mail.outbox) == 1 | ||
email = mail.outbox[0] | ||
assert email.subject == 'Your édX ID verification was approved!' | ||
assert 'Your édX ID verification photos have been approved' in email.body | ||
assert expiration_date.strftime("%m/%d/%Y") in email.body | ||
|
||
@ddt.data(True, False) | ||
def test_send_approval(self, use_ace): | ||
with patch.dict(settings.VERIFY_STUDENT, {'USE_DJANGO_MAIL': use_ace}): | ||
send_approval_email(self.attempt) | ||
self._assert_verification_approved_email(self.attempt.expiration_datetime) |
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