remove enroll CTA on course homepage for logged out users visiting a Master's only course

This commit is contained in:
Michael Roytman
2019-04-09 17:46:52 -04:00
parent fe4679fc04
commit f7d0753210
7 changed files with 184 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ Test helpers for the course experience.
"""
from datetime import timedelta
from django.core.exceptions import ObjectDoesNotExist
from django.utils.timezone import now
from course_modes.models import CourseMode
@@ -10,9 +11,16 @@ from course_modes.models import CourseMode
TEST_COURSE_PRICE = 50
def add_course_mode(course, upgrade_deadline_expired=False):
def add_course_mode(course, mode_slug=CourseMode.VERIFIED,
mode_display_name='Verified Certificate', upgrade_deadline_expired=False):
"""
Adds a course mode to the test course.
Add a course mode to the test course.
Args:
course
mode_slug (str): the slug of the mode to add
mode_display_name (str): the display name of the mode to add
upgrade_deadline_expired (bool): whether the upgrade deadline has passed
"""
upgrade_exp_date = now()
if upgrade_deadline_expired:
@@ -22,8 +30,24 @@ def add_course_mode(course, upgrade_deadline_expired=False):
CourseMode(
course_id=course.id,
mode_slug=CourseMode.VERIFIED,
mode_display_name="Verified Certificate",
mode_slug=mode_slug,
mode_display_name=mode_display_name,
min_price=TEST_COURSE_PRICE,
_expiration_datetime=upgrade_exp_date,
).save()
def remove_course_mode(course, mode_slug):
"""
Remove a course mode from the test course if it exists in the course.
Args:
course
mode_slug (str): slug of the mode to remove
"""
try:
mode = CourseMode.objects.get(course_id=course.id, mode_slug=mode_slug)
except ObjectDoesNotExist:
pass
mode.delete()

View File

@@ -58,7 +58,7 @@ from xmodule.modulestore.tests.django_utils import CourseUserType, ModuleStoreTe
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
from ... import COURSE_PRE_START_ACCESS_FLAG, ENABLE_COURSE_GOALS
from .helpers import add_course_mode
from .helpers import add_course_mode, remove_course_mode
from .test_course_updates import create_course_update, remove_course_updates
TEST_PASSWORD = 'test'
@@ -656,6 +656,34 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
@override_waffle_flag(COURSE_PRE_START_ACCESS_FLAG, active=True)
def test_masters_course_message(self):
enroll_button_html = "<button class=\"enroll-btn btn-link\">Enroll now</button>"
# Verify that unenrolled users visiting a course with a Master's track
# that is not the only track are shown an enroll call to action message
add_course_mode(self.course, CourseMode.MASTERS, 'Master\'s Mode', upgrade_deadline_expired=False)
self.create_user_for_course(self.course, CourseUserType.UNENROLLED)
url = course_home_url(self.course)
response = self.client.get(url)
self.assertContains(response, TEST_COURSE_HOME_MESSAGE)
self.assertContains(response, TEST_COURSE_HOME_MESSAGE_UNENROLLED)
self.assertContains(response, enroll_button_html)
# Verify that unenrolled users visiting a course that contains only a Master's track
# are not shown an enroll call to action message
remove_course_mode(self.course, CourseMode.VERIFIED)
response = self.client.get(url)
expected_message = ('You must be enrolled in the course to see course content. '
'Please contact your degree administrator or edX Support if you have questions.')
self.assertContains(response, TEST_COURSE_HOME_MESSAGE)
self.assertContains(response, expected_message)
self.assertNotContains(response, enroll_button_html)
@override_waffle_flag(COURSE_PRE_START_ACCESS_FLAG, active=True)
def test_course_messaging(self):
"""

View File

@@ -5,6 +5,7 @@ View logic for handling course messages.
from datetime import datetime
from babel.dates import format_date, format_timedelta
from course_modes.models import CourseMode
from courseware.courses import get_course_date_blocks, get_course_with_access
from django.contrib import auth
from django.template.loader import render_to_string
@@ -129,7 +130,20 @@ def _register_course_home_messages(request, course, user_access, course_start_da
)
if not user_access['is_anonymous'] and not user_access['is_staff'] and \
not user_access['is_enrolled']:
if not course.invitation_only:
title = Text(_(u'Welcome to {course_display_name}')).format(
course_display_name=course.display_name
)
if CourseMode.is_masters_only(course.id):
# if a course is a Master's only course, we will not offer user ability to self-enroll
CourseHomeMessages.register_info_message(
request,
Text(_('You must be enrolled in the course to see course content. '
'Please contact your degree administrator or edX Support if you have questions.')),
title=title
)
elif not course.invitation_only:
CourseHomeMessages.register_info_message(
request,
Text(_(
@@ -138,9 +152,7 @@ def _register_course_home_messages(request, course, user_access, course_start_da
open_enroll_link=HTML('<button class="enroll-btn btn-link">'),
close_enroll_link=HTML('</button>')
),
title=Text(_(u'Welcome to {course_display_name}')).format(
course_display_name=course.display_name
)
title=title
)
else:
CourseHomeMessages.register_info_message(