Merge pull request #19634 from edx/release-mergeback-to-master
Merge release back to master
This commit is contained in:
@@ -355,7 +355,7 @@ def _create_mock_json_request(user, data, method='POST'):
|
||||
return request
|
||||
|
||||
|
||||
def get_expiration_banner_text(user, course, language='en'):
|
||||
def get_expiration_banner_text(user, course, language='en-us'):
|
||||
"""
|
||||
Get text for banner that messages user course expiration date
|
||||
for different tests that depend on it.
|
||||
@@ -367,17 +367,17 @@ def get_expiration_banner_text(user, course, language='en'):
|
||||
if upgrade_deadline is None or now() < upgrade_deadline:
|
||||
upgrade_deadline = enrollment.course_upgrade_deadline
|
||||
|
||||
date_string = '<span class="localized-datetime" data-format="shortDate" \
|
||||
data-datetime="{formatted_date}" data-language="{language}">{formatted_date}</span>'
|
||||
formatted_expiration_date = date_string.format(
|
||||
language=language,
|
||||
formatted_date=strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
)
|
||||
language_is_es = language and language.split('-')[0].lower() == 'es'
|
||||
if language_is_es:
|
||||
formatted_expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
formatted_expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
|
||||
if upgrade_deadline:
|
||||
formatted_upgrade_deadline = date_string.format(
|
||||
language=language,
|
||||
formatted_date=strftime_localized(upgrade_deadline, '%b. %-d, %Y')
|
||||
)
|
||||
if language_is_es:
|
||||
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%b. %-d, %Y')
|
||||
|
||||
bannerText = '<strong>Audit Access Expires {expiration_date}</strong><br>\
|
||||
You lose all access to this course, including your progress, on {expiration_date}.\
|
||||
|
||||
@@ -34,7 +34,10 @@ class AuditExpiredError(AccessError):
|
||||
error_code = "audit_expired"
|
||||
developer_message = "User {} had access to {} until {}".format(user, course, expiration_date)
|
||||
language = get_language()
|
||||
expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
if language and language.split('-')[0].lower() == 'es':
|
||||
expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
user_message = _("Access expired on {expiration_date}").format(expiration_date=expiration_date)
|
||||
try:
|
||||
course_name = CourseOverview.get_from_id(course.id).display_name_with_default
|
||||
@@ -151,17 +154,17 @@ def generate_course_expired_message(user, course):
|
||||
using_upgrade_messaging = False
|
||||
|
||||
language = get_language()
|
||||
date_string = '<span class="localized-datetime" data-format="shortDate" \
|
||||
data-datetime="{formatted_date}" data-language="{language}">{formatted_date}</span>'
|
||||
formatted_expiration_date = date_string.format(
|
||||
language=language,
|
||||
formatted_date=strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
)
|
||||
language_is_es = language and language.split('-')[0].lower() == 'es'
|
||||
if language_is_es:
|
||||
formatted_expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
formatted_expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
|
||||
|
||||
if using_upgrade_messaging:
|
||||
formatted_upgrade_deadline = date_string.format(
|
||||
language=language,
|
||||
formatted_date=strftime_localized(upgrade_deadline, '%b. %-d, %Y')
|
||||
)
|
||||
if language_is_es:
|
||||
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%b. %-d, %Y')
|
||||
|
||||
return HTML(full_message).format(
|
||||
a_open=HTML('<a href="{upgrade_link}">').format(
|
||||
@@ -170,17 +173,17 @@ def generate_course_expired_message(user, course):
|
||||
sronly_span_open=HTML('<span class="sr-only">'),
|
||||
span_close=HTML('</span>'),
|
||||
a_close=HTML('</a>'),
|
||||
expiration_date=HTML(formatted_expiration_date),
|
||||
expiration_date=formatted_expiration_date,
|
||||
strong_open=HTML('<strong>'),
|
||||
strong_close=HTML('</strong>'),
|
||||
line_break=HTML('<br>'),
|
||||
upgrade_deadline=HTML(formatted_upgrade_deadline)
|
||||
upgrade_deadline=formatted_upgrade_deadline
|
||||
)
|
||||
|
||||
else:
|
||||
return HTML(full_message).format(
|
||||
span_close=HTML('</span>'),
|
||||
expiration_date=HTML(formatted_expiration_date),
|
||||
expiration_date=formatted_expiration_date,
|
||||
strong_open=HTML('<strong>'),
|
||||
strong_close=HTML('</strong>'),
|
||||
line_break=HTML('<br>'),
|
||||
|
||||
@@ -8,6 +8,7 @@ from course_modes.tests.factories import CourseModeFactory
|
||||
from django.test import RequestFactory
|
||||
from django.utils import timezone
|
||||
from courseware.models import DynamicUpgradeDeadlineConfiguration
|
||||
from mock import patch
|
||||
from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from openedx.features.course_duration_limits.access import (
|
||||
@@ -32,11 +33,12 @@ class TestAccess(CacheIsolationTestCase):
|
||||
|
||||
@ddt.data(
|
||||
*itertools.product(
|
||||
['en-us', 'es-419'],
|
||||
itertools.product([None, -2, -1, 1, 2], repeat=2),
|
||||
)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_generate_course_expired_message(self, offsets):
|
||||
def test_generate_course_expired_message(self, language, offsets):
|
||||
now = timezone.now()
|
||||
schedule_offset, course_offset = offsets
|
||||
|
||||
@@ -51,40 +53,45 @@ class TestAccess(CacheIsolationTestCase):
|
||||
course_upgrade_deadline = None
|
||||
|
||||
def format_date(date):
|
||||
return strftime_localized(date, '%b. %-d, %Y')
|
||||
if language.startswith('es-'):
|
||||
return strftime_localized(date, '%-d de %b. de %Y').lower()
|
||||
else:
|
||||
return strftime_localized(date, '%b. %-d, %Y')
|
||||
|
||||
enrollment = CourseEnrollmentFactory.create(
|
||||
course__start=datetime(2018, 1, 1, tzinfo=UTC),
|
||||
course__self_paced=True,
|
||||
)
|
||||
CourseModeFactory.create(
|
||||
course_id=enrollment.course.id,
|
||||
mode_slug=CourseMode.VERIFIED,
|
||||
expiration_datetime=course_upgrade_deadline,
|
||||
)
|
||||
CourseModeFactory.create(
|
||||
course_id=enrollment.course.id,
|
||||
mode_slug=CourseMode.AUDIT,
|
||||
)
|
||||
ScheduleFactory.create(
|
||||
enrollment=enrollment,
|
||||
upgrade_deadline=schedule_upgrade_deadline,
|
||||
)
|
||||
patch_lang = patch('openedx.features.course_duration_limits.access.get_language', return_value=language)
|
||||
with patch_lang:
|
||||
enrollment = CourseEnrollmentFactory.create(
|
||||
course__start=datetime(2018, 1, 1, tzinfo=UTC),
|
||||
course__self_paced=True,
|
||||
)
|
||||
CourseModeFactory.create(
|
||||
course_id=enrollment.course.id,
|
||||
mode_slug=CourseMode.VERIFIED,
|
||||
expiration_datetime=course_upgrade_deadline,
|
||||
)
|
||||
CourseModeFactory.create(
|
||||
course_id=enrollment.course.id,
|
||||
mode_slug=CourseMode.AUDIT,
|
||||
)
|
||||
ScheduleFactory.create(
|
||||
enrollment=enrollment,
|
||||
upgrade_deadline=schedule_upgrade_deadline,
|
||||
)
|
||||
|
||||
duration_limit_upgrade_deadline = get_user_course_expiration_date(enrollment.user, enrollment.course)
|
||||
self.assertIsNotNone(duration_limit_upgrade_deadline)
|
||||
duration_limit_upgrade_deadline = get_user_course_expiration_date(enrollment.user, enrollment.course)
|
||||
self.assertIsNotNone(duration_limit_upgrade_deadline)
|
||||
|
||||
message = generate_course_expired_message(enrollment.user, enrollment.course)
|
||||
message = generate_course_expired_message(enrollment.user, enrollment.course)
|
||||
|
||||
self.assertIn(format_date(duration_limit_upgrade_deadline), message)
|
||||
self.assertIn(format_date(duration_limit_upgrade_deadline), message)
|
||||
|
||||
soft_upgradeable = schedule_upgrade_deadline is not None and now < schedule_upgrade_deadline
|
||||
upgradeable = course_upgrade_deadline is None or now < course_upgrade_deadline
|
||||
has_upgrade_deadline = course_upgrade_deadline is not None
|
||||
soft_upgradeable = schedule_upgrade_deadline is not None and now < schedule_upgrade_deadline
|
||||
upgradeable = course_upgrade_deadline is None or now < course_upgrade_deadline
|
||||
has_upgrade_deadline = course_upgrade_deadline is not None
|
||||
|
||||
if upgradeable and soft_upgradeable:
|
||||
self.assertIn(format_date(schedule_upgrade_deadline), message)
|
||||
elif upgradeable and has_upgrade_deadline:
|
||||
self.assertIn(format_date(course_upgrade_deadline), message)
|
||||
else:
|
||||
self.assertNotIn("Upgrade by", message)
|
||||
if upgradeable and soft_upgradeable:
|
||||
self.assertIn(format_date(schedule_upgrade_deadline), message)
|
||||
elif upgradeable and has_upgrade_deadline:
|
||||
self.assertIn(format_date(course_upgrade_deadline), message)
|
||||
else:
|
||||
self.assertNotIn("Upgrade by", message)
|
||||
|
||||
Reference in New Issue
Block a user