예제 #1
0
    def test_choose_mode_redirect(self, course_mode, expected_redirect):
        # Create the course modes
        for mode in ('audit', 'honor', 'verified'):
            min_price = 0 if mode in ["honor", "audit"] else 1
            CourseModeFactory.create(mode_slug=mode,
                                     course_id=self.course.id,
                                     min_price=min_price)

        # Choose the mode (POST request)
        choose_track_url = reverse('course_modes_choose',
                                   args=[str(self.course.id)])
        response = self.client.post(
            choose_track_url, self.POST_PARAMS_FOR_COURSE_MODE[course_mode])

        # Verify the redirect
        if expected_redirect == 'dashboard':
            redirect_url = reverse('dashboard')
        elif expected_redirect == 'start-flow':
            redirect_url = IDVerificationService.get_verify_location(
                course_id=self.course.id)
        else:
            self.fail("Must provide a valid redirect URL name")

        with mock_payment_processors(expect_called=None):
            self.assertRedirects(
                response,
                redirect_url,
                fetch_redirect_response=False,
            )
예제 #2
0
    def test_professional_enrollment(self, mode):
        # The only course mode is professional ed
        CourseModeFactory.create(mode_slug=mode,
                                 course_id=self.course.id,
                                 min_price=1)

        # Go to the "choose your track" page
        choose_track_url = reverse('course_modes_choose',
                                   args=[six.text_type(self.course.id)])
        response = self.client.get(choose_track_url)

        # Since the only available track is professional ed, expect that
        # we're redirected immediately to the start of the payment flow.
        purchase_workflow = "?purchase_workflow=single"
        start_flow_url = reverse('verify_student_start_flow',
                                 args=[six.text_type(self.course.id)
                                       ]) + purchase_workflow
        with mock_payment_processors():
            self.assertRedirects(response, start_flow_url)

        # Now enroll in the course
        CourseEnrollmentFactory(
            user=self.user,
            is_active=True,
            mode=mode,
            course_id=six.text_type(self.course.id),
        )

        # Expect that this time we're redirected to the dashboard (since we're already registered)
        response = self.client.get(choose_track_url)
        self.assertRedirects(response, reverse('dashboard'))
예제 #3
0
    def test_start_flow(self):
        # Go to the course mode page, expecting a redirect to the intro step of the
        # payment flow (since this is a professional ed course). Otherwise, the student
        # would have the option to choose their track.
        with mock_payment_processors():
            resp = self.client.get(self.urls['course_modes_choose'], follow=True)
            self.assertRedirects(resp, self.urls['verify_student_start_flow'])

        # For professional ed courses, expect that the student is NOT enrolled
        # automatically in the course.
        self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key))

        # On the first page of the flow, verify that there's a button allowing the user
        # to proceed to the payment processor; this is the only action the user is allowed to take.
        self.assertContains(resp, 'payment-button')
예제 #4
0
    def test_no_id_redirect(self):
        # Create the course modes
        CourseModeFactory.create(mode_slug=CourseMode.NO_ID_PROFESSIONAL_MODE,
                                 course_id=self.course.id,
                                 min_price=100)

        # Enroll the user in the test course
        CourseEnrollmentFactory(is_active=False,
                                mode=CourseMode.NO_ID_PROFESSIONAL_MODE,
                                course_id=self.course.id,
                                user=self.user)

        # Configure whether we're upgrading or not
        url = reverse('course_modes_choose',
                      args=[six.text_type(self.course.id)])
        response = self.client.get(url)
        # Check whether we were correctly redirected
        purchase_workflow = "?purchase_workflow=single"
        start_flow_url = reverse('verify_student_start_flow',
                                 args=[six.text_type(self.course.id)
                                       ]) + purchase_workflow
        with mock_payment_processors():
            self.assertRedirects(response, start_flow_url)