Commit 8502093f by Michael Frey

Redirect to otto checkout for prof ed courses if enabled

parent 40b5f8e6
......@@ -13,6 +13,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from course_modes.tests.factories import CourseModeFactory
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from student.models import CourseEnrollment
import lms.djangoapps.commerce.tests.test_utils as ecomm_test_utils
from course_modes.models import CourseMode, Mode
from openedx.core.djangoapps.theming.test_util import with_is_edx_domain
......@@ -82,6 +83,25 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase):
start_flow_url = reverse('verify_student_start_flow', args=[unicode(self.course.id)])
self.assertRedirects(response, start_flow_url)
def test_no_id_redirect_otto(self):
# Create the course modes
prof_course = CourseFactory.create()
CourseModeFactory(mode_slug=CourseMode.NO_ID_PROFESSIONAL_MODE, course_id=prof_course.id,
min_price=100, sku='TEST')
ecomm_test_utils.update_commerce_config(enabled=True)
# Enroll the user in the test course
CourseEnrollmentFactory(
is_active=False,
mode=CourseMode.NO_ID_PROFESSIONAL_MODE,
course_id=prof_course.id,
user=self.user
)
# Configure whether we're upgrading or not
url = reverse('course_modes_choose', args=[unicode(prof_course.id)])
response = self.client.get(url)
self.assertRedirects(response, 'http://testserver/test_basket/?sku=TEST', fetch_redirect_response=False)
ecomm_test_utils.update_commerce_config(enabled=False)
def test_no_enrollment(self):
# Create the course modes
for mode in ('audit', 'honor', 'verified'):
......
......@@ -80,18 +80,19 @@ class ChooseModeView(View):
enrollment_mode, is_active = CourseEnrollment.enrollment_mode_for_user(request.user, course_key)
modes = CourseMode.modes_for_course_dict(course_key)
ecommerce_service = EcommerceService()
# We assume that, if 'professional' is one of the modes, it is the *only* mode.
# If we offer more modes alongside 'professional' in the future, this will need to route
# to the usual "choose your track" page same is true for no-id-professional mode.
# We assume that, if 'professional' is one of the modes, it should be the *only* mode.
# If there are both modes, default to non-id-professional.
has_enrolled_professional = (CourseMode.is_professional_slug(enrollment_mode) and is_active)
if CourseMode.has_professional_mode(modes) and not has_enrolled_professional:
return redirect(
reverse(
'verify_student_start_flow',
kwargs={'course_id': unicode(course_key)}
)
)
redirect_url = reverse('verify_student_start_flow', kwargs={'course_id': unicode(course_key)})
if ecommerce_service.is_enabled(request):
professional_mode = modes.get(CourseMode.NO_ID_PROFESSIONAL_MODE) or modes.get(CourseMode.PROFESSIONAL)
if professional_mode.sku:
redirect_url = ecommerce_service.checkout_page_url(professional_mode.sku)
return redirect(redirect_url)
# If there isn't a verified mode available, then there's nothing
# to do on this page. The user has almost certainly been auto-registered
......@@ -150,7 +151,6 @@ class ChooseModeView(View):
context["verified_description"] = verified_mode.description
if verified_mode.sku:
ecommerce_service = EcommerceService()
context["use_ecommerce_payment_flow"] = ecommerce_service.is_enabled(request)
context["ecommerce_payment_page"] = ecommerce_service.payment_page_url()
context["sku"] = verified_mode.sku
......
......@@ -9,6 +9,14 @@ from django.test.client import RequestFactory
from student.tests.factories import UserFactory
def update_commerce_config(enabled=False, checkout_page='/test_basket/'):
""" Enable / Disable CommerceConfiguration model """
CommerceConfiguration.objects.create(
checkout_on_ecommerce_service=enabled,
single_course_checkout_page=checkout_page
)
class AuditLogTests(TestCase):
"""Tests of the commerce audit logging helper."""
@patch('commerce.utils.log')
......@@ -31,10 +39,7 @@ class EcommerceServiceTests(TestCase):
self.user = UserFactory.create()
self.request = self.request_factory.get("foo")
self.request.user = self.user
CommerceConfiguration.objects.create(
checkout_on_ecommerce_service=True,
single_course_checkout_page='/test_basket/'
)
update_commerce_config(enabled=True)
super(EcommerceServiceTests, self).setUp()
def test_is_enabled(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment