def activation_email_task(custom_template_text, email_recipient_list, subscription_uuid): """ Sends license activation email(s) asynchronously, and creates pending enterprise users to link the email recipients to the subscription's enterprise. Arguments: custom_template_text (dict): Dictionary containing `greeting` and `closing` keys to be used for customizing the email template. email_recipient_list (list of str): List of recipients to send the emails to. subscription_uuid (str): UUID (string representation) of the subscription that the recipients are associated with or will be associated with. """ subscription_plan = SubscriptionPlan.objects.get(uuid=subscription_uuid) pending_licenses = subscription_plan.licenses.filter(user_email__in=email_recipient_list).order_by('uuid') enterprise_api_client = EnterpriseApiClient() enterprise_customer = enterprise_api_client.get_enterprise_customer_data(subscription_plan.enterprise_customer_uuid) enterprise_slug = enterprise_customer.get('slug') enterprise_name = enterprise_customer.get('name') enterprise_sender_alias = enterprise_customer.get('sender_alias', 'edX Support Team') try: send_activation_emails( custom_template_text, pending_licenses, enterprise_slug, enterprise_name, enterprise_sender_alias ) except SMTPException: msg = 'License manager activation email sending received an exception for enterprise: {}.'.format( enterprise_name ) logger.error(msg, exc_info=True) return
def send_reminder_email_task(custom_template_text, email_recipient_list, subscription_uuid): """ Sends license activation reminder email(s) asynchronously. Arguments: custom_template_text (dict): Dictionary containing `greeting` and `closing` keys to be used for customizing the email template. email_recipient_list (list of str): List of recipients to send the emails to. subscription_uuid (str): UUID (string representation) of the subscription that the recipients are associated with or will be associated with. """ subscription_plan = SubscriptionPlan.objects.get(uuid=subscription_uuid) pending_licenses = subscription_plan.licenses.filter( user_email__in=email_recipient_list).order_by('uuid') enterprise_api_client = EnterpriseApiClient() enterprise_slug = enterprise_api_client.get_enterprise_slug( subscription_plan.enterprise_customer_uuid) enterprise_name = enterprise_api_client.get_enterprise_name( subscription_plan.enterprise_customer_uuid) try: send_activation_emails(custom_template_text, pending_licenses, enterprise_slug, enterprise_name, is_reminder=True) except Exception: # pylint: disable=broad-except msg = 'License manager reminder email sending received an exception for enterprise: {}.'.format( enterprise_name) logger.error(msg, exc_info=True) # Return without updating the last_remind_date for licenses return License.set_date_fields_to_now(pending_licenses, ['last_remind_date'])
def activation_task(custom_template_text, email_recipient_list, subscription_uuid): """ Sends license activation email(s) asynchronously, and creates pending enterprise users to link the email recipients to the subscription's enterprise. Arguments: custom_template_text (dict): Dictionary containing `greeting` and `closing` keys to be used for customizing the email template. email_recipient_list (list of str): List of recipients to send the emails to. subscription_uuid (str): UUID (string representation) of the subscription that the recipients are associated with or will be associated with. """ subscription_plan = SubscriptionPlan.objects.get(uuid=subscription_uuid) pending_licenses = subscription_plan.licenses.filter( user_email__in=email_recipient_list).order_by('uuid') enterprise_api_client = EnterpriseApiClient() enterprise_slug = enterprise_api_client.get_enterprise_slug( subscription_plan.enterprise_customer_uuid) send_activation_emails(custom_template_text, pending_licenses, enterprise_slug) License.set_date_fields_to_now(pending_licenses, ['last_remind_date', 'assigned_date']) for email_recipient in email_recipient_list: enterprise_api_client.create_pending_enterprise_user( subscription_plan.enterprise_customer_uuid, email_recipient, )
def test_send_reminder_email(self): """ Tests that reminder emails are correctly sent. """ lic = self.licenses[0] emails.send_activation_emails(self.custom_template_text, [lic], self.enterprise_slug, True) self.assertEqual(len(mail.outbox), 1) # Verify the contents of the first message message = mail.outbox[0] self.assertEqual(message.subject, constants.LICENSE_REMINDER_EMAIL_SUBJECT) self.assertTrue('Reminder' in message.body) self._assert_bookmark_content_is_present(message)
def test_send_activation_emails(self): """ Tests that activation emails are correctly sent. """ emails.send_activation_emails(self.custom_template_text, [ license for license in self.licenses if license.status == constants.ASSIGNED ], self.enterprise_slug) self.assertEqual(len(mail.outbox), len(self.email_recipient_list)) # Verify the contents of the first message message = mail.outbox[0] self.assertEqual(message.subject, constants.LICENSE_ACTIVATION_EMAIL_SUBJECT) self.assertFalse('Reminder' in message.body) self._assert_bookmark_content_is_present(message)
def test_send_reminder_email(self): """ Tests that reminder emails are correctly sent. """ lic = self.licenses[0] emails.send_activation_emails( self.custom_template_text, [lic], self.enterprise_slug, self.enterprise_name, self.enterprise_sender_alias, is_reminder=True, ) self.assertEqual(len(mail.outbox), 1) # Verify the contents of the first message message = mail.outbox[0] self.assertEqual(message.subject, constants.LICENSE_REMINDER_EMAIL_SUBJECT) self.assertFalse('Activate' in message.body)