Ejemplo n.º 1
0
def send_proctoring_attempt_status_email(exam_attempt_obj, course_name):
    """
    Sends an email about change in proctoring attempt status.
    """

    course_info_url = ''
    email_template = loader.get_template(
        'emails/proctoring_attempt_status_email.html')
    try:
        course_info_url = reverse(
            'courseware.views.course_info',
            args=[exam_attempt_obj.proctored_exam.course_id])
    except NoReverseMatch:
        # we are allowing a failure here since we can't guarantee
        # that we are running in-proc with the edx-platform LMS
        # (for example unit tests)
        pass

    course_id = exam_attempt_obj.proctored_exam.course_id
    provider_name = get_provider_name_by_course_id(course_id)
    proctor_settings = get_proctoring_settings(provider_name)
    scheme = 'https' if getattr(settings, 'HTTPS', 'on') == 'on' else 'http'
    course_url = '{scheme}://{site_name}{course_info_url}'.format(
        scheme=scheme,
        site_name=get_proctor_settings_param(proctor_settings, 'SITE_NAME'),
        course_info_url=course_info_url)

    body = email_template.render(
        Context({
            'course_url':
            course_url,
            'course_name':
            course_name,
            'exam_name':
            exam_attempt_obj.proctored_exam.exam_name,
            'status':
            ProctoredExamStudentAttemptStatus.get_status_alias(
                exam_attempt_obj.status),
            'platform':
            get_proctor_settings_param(proctor_settings, 'PLATFORM_NAME'),
            'contact_email':
            get_proctor_settings_param(proctor_settings, 'CONTACT_EMAIL'),
        }))

    subject = (
        _('Proctoring Session Results Update for {course_name} {exam_name}'
          ).format(course_name=course_name,
                   exam_name=exam_attempt_obj.proctored_exam.exam_name))

    email = EmailMessage(body=body,
                         from_email=get_proctor_settings_param(
                             proctor_settings, 'FROM_EMAIL'),
                         to=[exam_attempt_obj.user.email],
                         subject=subject)
    email.content_subtype = "html"
    email.send()
Ejemplo n.º 2
0
def send_proctoring_attempt_status_email(exam_attempt_obj, course_name):
    """
    Sends an email about change in proctoring attempt status.
    """

    course_info_url = ''
    email_template = loader.get_template('emails/proctoring_attempt_status_email.html')
    try:
        course_info_url = reverse('courseware.views.course_info', args=[exam_attempt_obj.proctored_exam.course_id])
    except NoReverseMatch:
        # we are allowing a failure here since we can't guarantee
        # that we are running in-proc with the edx-platform LMS
        # (for example unit tests)
        pass

    course_id = exam_attempt_obj.proctored_exam.course_id
    provider_name = get_provider_name_by_course_id(course_id)
    proctor_settings = get_proctoring_settings(provider_name)
    scheme = 'https' if getattr(settings, 'HTTPS', 'on') == 'on' else 'http'
    course_url = '{scheme}://{site_name}{course_info_url}'.format(
        scheme=scheme,
        site_name=get_proctor_settings_param(proctor_settings, 'SITE_NAME'),
        course_info_url=course_info_url
    )

    body = email_template.render(
        Context({
            'course_url': course_url,
            'course_name': course_name,
            'exam_name': exam_attempt_obj.proctored_exam.exam_name,
            'status': ProctoredExamStudentAttemptStatus.get_status_alias(exam_attempt_obj.status),
            'platform': get_proctor_settings_param(proctor_settings, 'PLATFORM_NAME'),
            'contact_email': get_proctor_settings_param(proctor_settings, 'CONTACT_EMAIL'),
        })
    )

    subject = (
        _('Proctoring Session Results Update for {course_name} {exam_name}').format(
            course_name=course_name,
            exam_name=exam_attempt_obj.proctored_exam.exam_name
        )
    )

    email = EmailMessage(
        body=body,
        from_email=get_proctor_settings_param(proctor_settings, 'FROM_EMAIL'),
        to=[exam_attempt_obj.user.email],
        subject=subject
    )
    email.content_subtype = "html"
    email.send()
Ejemplo n.º 3
0
    def test_send_email(self, status):
        """
        Assert that email is sent on the following statuses of proctoring attempt.
        """

        exam_attempt = self._create_started_exam_attempt()
        credit_state = get_runtime_service('credit').get_credit_state(
            self.user_id, self.course_id)
        update_attempt_status(exam_attempt.proctored_exam_id, self.user.id,
                              status)
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.proctored_exam_email_subject,
                      mail.outbox[0].subject)
        self.assertIn(self.proctored_exam_email_body, mail.outbox[0].body)
        self.assertIn(
            ProctoredExamStudentAttemptStatus.get_status_alias(status),
            mail.outbox[0].body)
        self.assertIn(credit_state['course_name'], mail.outbox[0].body)
Ejemplo n.º 4
0
    def test_send_email_unicode(self):
        """
        Assert that email can be sent with a unicode course name.
        """

        course_name = u'अआईउऊऋऌ अआईउऊऋऌ'
        set_runtime_service('credit',
                            MockCreditService(course_name=course_name))

        exam_attempt = self._create_started_exam_attempt()
        credit_state = get_runtime_service('credit').get_credit_state(
            self.user_id, self.course_id)
        update_attempt_status(exam_attempt.proctored_exam_id, self.user.id,
                              ProctoredExamStudentAttemptStatus.submitted)
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.proctored_exam_email_subject,
                      mail.outbox[0].subject)
        self.assertIn(course_name, mail.outbox[0].subject)
        self.assertIn(self.proctored_exam_email_body, mail.outbox[0].body)
        self.assertIn(
            ProctoredExamStudentAttemptStatus.get_status_alias(
                ProctoredExamStudentAttemptStatus.submitted),
            mail.outbox[0].body)
        self.assertIn(credit_state['course_name'], mail.outbox[0].body)