def change_state(self, state, user): if state == CourseStateChoices.Draft: self.draft() elif state == CourseStateChoices.Review: user_role = self.course.course_user_roles.get(user=user) if user_role.role == PublisherUserRole.MarketingReviewer: self.owner_role = PublisherUserRole.CourseTeam self.owner_role_modified = timezone.now() elif user_role.role == PublisherUserRole.CourseTeam: self.owner_role = PublisherUserRole.MarketingReviewer self.owner_role_modified = timezone.now() self.review() if waffle.switch_is_active('enable_publisher_email_notifications'): emails.send_email_for_send_for_review(self.course, user) elif state == CourseStateChoices.Approved: user_role = self.course.course_user_roles.get(user=user) self.approved_by_role = user_role.role self.owner_role_modified = timezone.now() self.approved() if waffle.switch_is_active('enable_publisher_email_notifications'): emails.send_email_for_mark_as_reviewed(self.course, user) self.save()
def change_state(self, state, user, site=None): """ Change course workflow state and ownership also send emails if required. """ is_notifications_enabled = waffle.switch_is_active( 'enable_publisher_email_notifications') if state == CourseStateChoices.Draft: self.draft() elif state == CourseStateChoices.Review: user_role = self.course.course_user_roles.get(user=user) if user_role.role == PublisherUserRole.MarketingReviewer: self.change_owner_role(PublisherUserRole.CourseTeam) self.marketing_reviewed = True elif user_role.role == PublisherUserRole.CourseTeam: self.change_owner_role(PublisherUserRole.MarketingReviewer) if is_notifications_enabled: emails.send_email_for_seo_review(self.course, site) self.review() if is_notifications_enabled: emails.send_email_for_send_for_review(self.course, user, site) elif state == CourseStateChoices.Approved: user_role = self.course.course_user_roles.get(user=user) self.approved_by_role = user_role.role self.marketing_reviewed = True self.approved() if is_notifications_enabled: emails.send_email_for_mark_as_reviewed(self.course, user, site) self.save()
def test_email_with_error(self): """ Verify that email failure logs error message.""" with LogCapture(emails.logger.name) as output: emails.send_email_for_send_for_review(self.course_state.course, self.user, self.site) output.check(( emails.logger.name, 'ERROR', 'Failed to send email notifications send for review of course {}' .format(self.course_state.course.id)))