From 6446f6111e2438f631d250dcc34cb91b716c6d6b Mon Sep 17 00:00:00 2001 From: cahrens <christina@edx.org> Date: Fri, 11 Aug 2017 14:22:18 -0400 Subject: [PATCH] Log courses with improper end dates. EDUCATOR-1134 --- cms/envs/common.py | 5 ++--- common/lib/xmodule/xmodule/course_module.py | 11 ++++++++++- .../lib/xmodule/xmodule/tests/test_course_module.py | 11 +++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 854204d8fe3..55b241fa1a3 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -254,9 +254,8 @@ FEATURES = { 'ENABLE_ENROLLMENT_TRACK_USER_PARTITION': True, # Whether archived courses (courses with end dates in the past) should be - # shown in Studio in a separate list. Note that attempting to enable this - # failed on stage-- see EDUCATOR-1134. - 'ENABLE_SEPARATE_ARCHIVED_COURSES': False + # shown in Studio in a separate list. + 'ENABLE_SEPARATE_ARCHIVED_COURSES': True } ENABLE_JASMINE = False diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 29e3a925f59..8a3f8e2c925 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -1451,4 +1451,13 @@ class CourseSummary(object): """ Returns whether the course has ended. """ - return course_metadata_utils.has_course_ended(self.end) + try: + return course_metadata_utils.has_course_ended(self.end) + except TypeError as e: + log.warning( + "Course '{course_id}' has an improperly formatted end date '{end_date}'. Error: '{err}'.".format( + course_id=unicode(self.id), end_date=self.end, err=e + ) + ) + modified_end = self.end.replace(tzinfo=utc) + return course_metadata_utils.has_course_ended(modified_end) diff --git a/common/lib/xmodule/xmodule/tests/test_course_module.py b/common/lib/xmodule/xmodule/tests/test_course_module.py index a5f8b723713..99e89b680ef 100644 --- a/common/lib/xmodule/xmodule/tests/test_course_module.py +++ b/common/lib/xmodule/xmodule/tests/test_course_module.py @@ -2,6 +2,7 @@ import ddt import unittest from datetime import datetime, timedelta +from dateutil import parser import itertools from fs.memoryfs import MemoryFS @@ -142,6 +143,16 @@ class HasEndedMayCertifyTestCase(unittest.TestCase): self.assertFalse(self.future_noshow_certs.may_certify()) +class CourseSummaryHasEnded(unittest.TestCase): + """ Test for has_ended method when end date is missing timezone information. """ + + def test_course_end(self): + test_course = get_dummy_course("2012-01-01T12:00") + bad_end_date = parser.parse("2012-02-21 10:28:45") + summary = xmodule.course_module.CourseSummary(test_course.id, end=bad_end_date) + self.assertTrue(summary.has_ended()) + + @ddt.ddt class IsNewCourseTestCase(unittest.TestCase): """Make sure the property is_new works on courses""" -- GitLab