Example #1
0
    def update(self, instance, validated_data):
        lms_course_id = validated_data.get('lms_course_id')

        # Handle saving the preview URL as a slug first
        preview_url = validated_data.pop('preview_url', None)
        if preview_url:
            self.update_preview_url(preview_url, lms_course_id
                                    or instance.lms_course_id)

        instance = super(CourseRunSerializer,
                         self).update(instance, validated_data)
        request = self.context['request']

        if preview_url:
            # Change ownership to CourseTeam.
            instance.course_run_state.change_owner_role(
                PublisherUserRole.CourseTeam)

        if waffle.switch_is_active('enable_publisher_email_notifications'):
            if preview_url:
                send_email_preview_page_is_available(instance,
                                                     site=request.site)

            elif lms_course_id:
                send_email_for_studio_instance_created(instance,
                                                       site=request.site)

        return instance
    def test_preview_available_email_with_notification_disabled(self):
        """ Verify that email not sent if notification disabled by user."""
        factories.UserAttributeFactory(user=self.course.course_team_admin,
                                       enable_email_notification=False)
        emails.send_email_preview_page_is_available(self.run_state.course_run)

        self.assertEqual(len(mail.outbox), 0)
    def test_preview_available_email_with_error(self):
        """ Verify that exception raised on email failure."""

        with self.assertRaises(Exception) as ex:
            emails.send_email_preview_page_is_available(
                self.run_state.course_run)
            error_message = 'Failed to send email notifications for preview available of course-run {}'.format(
                self.run_state.course_run.id)
            self.assertEqual(ex.message, error_message)
Example #4
0
    def test_preview_available_email_with_error(self):
        """ Verify that email failure log error message."""

        with mock.patch('django.core.mail.message.EmailMessage.send', side_effect=TypeError):
            with LogCapture(emails.logger.name) as l:
                emails.send_email_preview_page_is_available(self.run_state.course_run)
                l.check(
                    (
                        emails.logger.name,
                        'ERROR',
                        'Failed to send email notifications for preview available of course-run {}'.format(
                            self.run_state.course_run.id
                        )
                    )
                )
    def update(self, instance, validated_data):
        instance = super(CourseRunSerializer, self).update(instance, validated_data)
        preview_url = validated_data.get('preview_url')
        lms_course_id = validated_data.get('lms_course_id')

        if preview_url:
            # Change ownership to CourseTeam.
            instance.course_run_state.change_owner_role(PublisherUserRole.CourseTeam)

        if waffle.switch_is_active('enable_publisher_email_notifications'):
            if preview_url:
                send_email_preview_page_is_available(instance)

            elif lms_course_id:
                send_email_for_studio_instance_created(instance)

        return instance
Example #6
0
 def test_preview_available_email(self):
     """
     Verify that preview available email functionality works fine.
     """
     emails.send_email_preview_page_is_available(self.run_state.course_run)
     run_name = '{pacing_type}: {start_date}'.format(
         pacing_type=self.run_state.course_run.get_pacing_type_display(),
         start_date=self.run_state.course_run.start.strftime("%B %d, %Y")
     )
     subject = 'Preview for {run_name} is available'.format(
         run_name=run_name
     )
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual([self.course.course_team_admin.email], mail.outbox[0].bcc)
     self.assertEqual(str(mail.outbox[0].subject), subject)
     body = mail.outbox[0].body.strip()
     page_path = reverse('publisher:publisher_course_run_detail', kwargs={'pk': self.run_state.course_run.id})
     page_url = 'https://{host}{path}'.format(host=Site.objects.get_current().domain.strip('/'), path=page_path)
     self.assertIn(page_url, body)
     self.assertIn('is available for review.', body)
    def test_preview_available_email(self):
        """
        Verify that preview available email functionality works fine.
        """
        course_run = self.run_state.course_run
        course_run.lms_course_id = 'course-v1:testX+testX1.0+2017T1'
        course_run.save()

        emails.send_email_preview_page_is_available(course_run)

        course_key = CourseKey.from_string(course_run.lms_course_id)
        subject = 'Review requested: Preview for {course_name} {run_number}'.format(
            course_name=self.course.title, run_number=course_key.run)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual([self.course.course_team_admin.email],
                         mail.outbox[0].to)
        self.assertEqual(str(mail.outbox[0].subject), subject)
        body = mail.outbox[0].body.strip()
        page_path = reverse('publisher:publisher_course_run_detail',
                            kwargs={'pk': course_run.id})
        page_url = 'https://{host}{path}'.format(
            host=Site.objects.get_current().domain.strip('/'), path=page_path)
        self.assertIn(page_url, body)
        self.assertIn('A preview is now available for the', body)
Example #8
0
    def change_state(self, state, user, site=None):
        """
        Change course run workflow state and ownership also send emails if required.
        """
        if state == CourseRunStateChoices.Draft:
            self.draft()
        elif state == CourseRunStateChoices.Review:
            user_role = self.course_run.course.course_user_roles.get(user=user)
            if user_role.role == PublisherUserRole.ProjectCoordinator:
                self.change_owner_role(PublisherUserRole.CourseTeam)
            elif user_role.role == PublisherUserRole.CourseTeam:
                self.change_owner_role(PublisherUserRole.ProjectCoordinator)

            self.review()

            if waffle.switch_is_active('enable_publisher_email_notifications'):
                emails.send_email_for_send_for_review_course_run(
                    self.course_run, user, site)

        elif state == CourseRunStateChoices.Approved:
            user_role = self.course_run.course.course_user_roles.get(user=user)
            self.approved_by_role = user_role.role
            self.change_owner_role(PublisherUserRole.CourseTeam)
            self.approved()

            if waffle.switch_is_active('enable_publisher_email_notifications'):
                emails.send_email_for_mark_as_reviewed_course_run(
                    self.course_run, user, site)
                emails.send_email_to_publisher(self.course_run, user, site)
                emails.send_email_preview_page_is_available(
                    self.course_run, site)

        elif state == CourseRunStateChoices.Published:
            self.published(site)

        self.save()