def test_email_sent_successfully(self):
        """ Verify that studio instance request email sent successfully."""

        emails.send_email_for_course_creation(self.course_run.course,
                                              self.course_run)
        subject = 'Studio URL requested: {title}'.format(
            title=self.course_run.course.title)
        self.assert_email_sent(subject)
    def test_email_not_sent_with_notification_disabled(self):
        """ Verify that emails not sent if notification disabled by user."""
        user_attribute = UserAttributes.objects.get(user=self.user)
        user_attribute.enable_email_notification = False
        user_attribute.save()
        emails.send_email_for_course_creation(self.course_run.course,
                                              self.course_run)

        self.assertEqual(len(mail.outbox), 0)
Exemple #3
0
 def test_email_with_error(self):
     """ Verify that emails failure logs error message."""
     with LogCapture(emails.logger.name) as output:
         emails.send_email_for_course_creation(self.course_run.course,
                                               self.course_run, self.site)
         output.check((
             emails.logger.name, 'ERROR',
             'Failed to send email notifications for creation of course [{}]'
             .format(self.course_run.course.id)))
Exemple #4
0
    def test_email_sent_successfully(self):
        """ Verify that emails send as course creation notifications."""

        emails.send_email_for_course_creation(self.course_run.course, self.course_run)
        subject = 'New Studio instance request for {title}'.format(title=self.course_run.course.title)
        self.assert_email_sent(subject)
Exemple #5
0
    def post(self, request, *args, **kwargs):
        ctx = self.get_context_data()

        # pass selected organization to CustomCourseForm to populate related
        # choices into institution admin field
        user = self.request.user
        organization = self.request.POST.get('organization')
        course_form = self.course_form(request.POST,
                                       request.FILES,
                                       user=user,
                                       organization=organization)
        run_form = self.run_form(request.POST)
        seat_form = self.seat_form(request.POST)
        if course_form.is_valid() and run_form.is_valid(
        ) and seat_form.is_valid():
            try:
                with transaction.atomic():
                    seat = None
                    if request.POST.get('type'):
                        seat = seat_form.save(commit=False)

                    run_course = run_form.save(commit=False)
                    course = course_form.save(commit=False)
                    course.changed_by = user
                    course.save()
                    # commit false does not save m2m object. Keyword field is m2m.
                    course_form.save_m2m()

                    run_course.course = course
                    run_course.changed_by = user
                    run_course.save()

                    # commit false does not save m2m object.
                    run_form.save_m2m()

                    if seat:
                        seat.course_run = run_course
                        seat.changed_by = user
                        seat.save()

                    organization_extension = get_object_or_404(
                        OrganizationExtension,
                        organization=course_form.data['organization'])
                    course.organizations.add(
                        organization_extension.organization)

                    # add default organization roles into course-user-roles
                    course.assign_organization_role(
                        organization_extension.organization)

                    # add team admin as CourseTeam role again course
                    CourseUserRole.add_course_roles(
                        course=course,
                        role=PublisherUserRole.CourseTeam,
                        user=User.objects.get(
                            id=course_form.data['team_admin']))

                    # Initialize workflow for Course.
                    CourseState.objects.create(
                        course=course, owner_role=PublisherUserRole.CourseTeam)

                    # Initialize workflow for Course-run.
                    CourseRunState.objects.create(
                        course_run=run_course,
                        owner_role=PublisherUserRole.CourseTeam)

                    # pylint: disable=no-member
                    messages.success(
                        request,
                        _("You have successfully created a course. You can edit the course information or enter "
                          "information for the course About page at any time. "
                          "An edX project coordinator will create a Studio instance for this course. When you "
                          "receive an email notification that the Studio instance is ready, you can enter course "
                          "content in Studio."))

                    # sending email for notifying new course is created.
                    emails.send_email_for_course_creation(course, run_course)

                    return HttpResponseRedirect(self.get_success_url(
                        course.id))
            except Exception as e:  # pylint: disable=broad-except
                # pylint: disable=no-member
                error_message = _(
                    'An error occurred while saving your changes. {error}'
                ).format(error=str(e))
                messages.error(request, error_message)

        if not messages.get_messages(request):
            messages.error(request, _('Please fill all required fields.'))

        if course_form.errors.get('image'):
            messages.error(request, course_form.errors.get('image'))

        ctx.update({
            'course_form': course_form,
            'run_form': run_form,
            'seat_form': seat_form
        })
        return render(request, self.template_name, ctx, status=400)