From ce4b130113f0d8a587b03b3b15003b47b1e3af46 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Mon, 6 Jan 2014 16:25:20 -0500 Subject: [PATCH] Set default section start date to Jan 1, 2030 STUD-1072 --- CHANGELOG.rst | 2 ++ .../contentstore/tests/test_item.py | 23 ++++++++++++------- common/lib/xmodule/xmodule/course_module.py | 4 +--- .../xmodule/modulestore/inheritance.py | 2 +- .../xmodule/modulestore/tests/factories.py | 2 -- .../xmodule/tests/test_course_module.py | 14 ++++++++--- .../lib/xmodule/xmodule/tests/test_import.py | 6 +++-- .../django_comment_client/tests/test_utils.py | 11 +++++++-- 8 files changed, 43 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d60e25d427..2f4d119c00 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes, in roughly chronological order, most recent first. Add your entries at or near the top. Include a label indicating the component affected. +Studio: Newly-created courses default to being published on Jan 1, 2030 + Studio: Added pagination to the Files & Uploads page. Blades: Video player improvements: diff --git a/cms/djangoapps/contentstore/tests/test_item.py b/cms/djangoapps/contentstore/tests/test_item.py index 6cf2b6995b..acfa4b491c 100644 --- a/cms/djangoapps/contentstore/tests/test_item.py +++ b/cms/djangoapps/contentstore/tests/test_item.py @@ -1,7 +1,7 @@ """Tests for items views.""" import json -import datetime +from datetime import datetime import ddt from mock import Mock, patch @@ -149,6 +149,13 @@ class TestCreateItem(ItemTest): resp = self.create_xblock(category='problem', boilerplate='nosuchboilerplate.yaml') self.assertEqual(resp.status_code, 200) + def test_create_with_future_date(self): + self.assertEqual(self.course.start, datetime(2030, 1, 1, tzinfo=UTC)) + resp = self.create_xblock(category='chapter') + locator = self.response_locator(resp) + obj = self.get_item_from_modulestore(locator) + self.assertEqual(obj.start, datetime(2030, 1, 1, tzinfo=UTC)) + class TestEditItem(ItemTest): """ @@ -214,14 +221,14 @@ class TestEditItem(ItemTest): data={'metadata': {'due': '2010-11-22T04:00Z'}} ) sequential = self.get_item_from_modulestore(self.seq_locator) - self.assertEqual(sequential.due, datetime.datetime(2010, 11, 22, 4, 0, tzinfo=UTC)) + self.assertEqual(sequential.due, datetime(2010, 11, 22, 4, 0, tzinfo=UTC)) self.client.ajax_post( self.seq_update_url, data={'metadata': {'start': '2010-09-12T14:00Z'}} ) sequential = self.get_item_from_modulestore(self.seq_locator) - self.assertEqual(sequential.due, datetime.datetime(2010, 11, 22, 4, 0, tzinfo=UTC)) - self.assertEqual(sequential.start, datetime.datetime(2010, 9, 12, 14, 0, tzinfo=UTC)) + self.assertEqual(sequential.due, datetime(2010, 11, 22, 4, 0, tzinfo=UTC)) + self.assertEqual(sequential.start, datetime(2010, 9, 12, 14, 0, tzinfo=UTC)) def test_delete_child(self): """ @@ -326,7 +333,7 @@ class TestEditItem(ItemTest): published = self.get_item_from_modulestore(self.problem_locator, False) self.assertIsNone(published.due) draft = self.get_item_from_modulestore(self.problem_locator, True) - self.assertEqual(draft.due, datetime.datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) + self.assertEqual(draft.due, datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) def test_make_public_with_update(self): """ Update a problem and make it public at the same time. """ @@ -338,7 +345,7 @@ class TestEditItem(ItemTest): } ) published = self.get_item_from_modulestore(self.problem_locator, False) - self.assertEqual(published.due, datetime.datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) + self.assertEqual(published.due, datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) def test_make_private_with_update(self): """ Make a problem private and update it at the same time. """ @@ -357,7 +364,7 @@ class TestEditItem(ItemTest): with self.assertRaises(ItemNotFoundError): self.get_item_from_modulestore(self.problem_locator, False) draft = self.get_item_from_modulestore(self.problem_locator, True) - self.assertEqual(draft.due, datetime.datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) + self.assertEqual(draft.due, datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) def test_create_draft_with_update(self): """ Create a draft and update it at the same time. """ @@ -378,7 +385,7 @@ class TestEditItem(ItemTest): published = self.get_item_from_modulestore(self.problem_locator, False) self.assertIsNone(published.due) draft = self.get_item_from_modulestore(self.problem_locator, True) - self.assertEqual(draft.due, datetime.datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) + self.assertEqual(draft.due, datetime(2077, 10, 10, 4, 0, tzinfo=UTC)) @ddt.ddt diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 842a235bed..e8a27a4583 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -164,9 +164,7 @@ class CourseFields(object): enrollment_start = Date(help="Date that enrollment for this class is opened", scope=Scope.settings) enrollment_end = Date(help="Date that enrollment for this class is closed", scope=Scope.settings) start = Date(help="Start time when this module is visible", - # using now(UTC()) resulted in fractional seconds which screwed up comparisons and anyway w/b the - # time of first invocation of this stmt on the server - default=datetime.fromtimestamp(0, UTC()), + default=datetime(2030, 1, 1, tzinfo=UTC()), scope=Scope.settings) end = Date(help="Date that this class ends", scope=Scope.settings) advertised_start = String(help="Date that this course is advertised to start", scope=Scope.settings) diff --git a/common/lib/xmodule/xmodule/modulestore/inheritance.py b/common/lib/xmodule/xmodule/modulestore/inheritance.py index 8962447ec0..8fa46045a6 100644 --- a/common/lib/xmodule/xmodule/modulestore/inheritance.py +++ b/common/lib/xmodule/xmodule/modulestore/inheritance.py @@ -17,7 +17,7 @@ class InheritanceMixin(XBlockMixin): start = Date( help="Start time when this module is visible", - default=datetime.fromtimestamp(0, UTC), + default=datetime(2030, 1, 1, tzinfo=UTC), scope=Scope.settings ) due = Date(help="Date that this problem is due by", scope=Scope.settings) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py index 5fe0dc8849..2cbe7e6e22 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py @@ -55,8 +55,6 @@ class CourseFactory(XModuleFactory): # Write the data to the mongo datastore new_course = store.create_xmodule(location, metadata=kwargs.get('metadata', None)) - new_course.start = datetime.datetime.now(UTC).replace(microsecond=0) - # The rest of kwargs become attributes on the course: for k, v in kwargs.iteritems(): setattr(new_course, k, v) diff --git a/common/lib/xmodule/xmodule/tests/test_course_module.py b/common/lib/xmodule/xmodule/tests/test_course_module.py index bf83fbd17d..59cf686f9d 100644 --- a/common/lib/xmodule/xmodule/tests/test_course_module.py +++ b/common/lib/xmodule/xmodule/tests/test_course_module.py @@ -1,5 +1,5 @@ import unittest -import datetime +from datetime import datetime from fs.memoryfs import MemoryFS @@ -13,7 +13,15 @@ from django.utils.timezone import UTC ORG = 'test_org' COURSE = 'test_course' -NOW = datetime.datetime.strptime('2013-01-01T01:00:00', '%Y-%m-%dT%H:%M:00').replace(tzinfo=UTC()) +NOW = datetime.strptime('2013-01-01T01:00:00', '%Y-%m-%dT%H:%M:00').replace(tzinfo=UTC()) + + +class CourseFieldsTestCase(unittest.TestCase): + def test_default_start_date(self): + self.assertEqual( + xmodule.course_module.CourseFields.start.default, + datetime(2030, 1, 1, tzinfo=UTC()) + ) class DummySystem(ImportSystem): @@ -77,7 +85,7 @@ class IsNewCourseTestCase(unittest.TestCase): # Needed for test_is_newish datetime_patcher = patch.object( xmodule.course_module, 'datetime', - Mock(wraps=datetime.datetime) + Mock(wraps=datetime) ) mocked_datetime = datetime_patcher.start() mocked_datetime.now.return_value = NOW diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py index c1f4bb2ee2..969886345d 100644 --- a/common/lib/xmodule/xmodule/tests/test_import.py +++ b/common/lib/xmodule/xmodule/tests/test_import.py @@ -228,9 +228,11 @@ class ImportTestCase(BaseCourseTestCase): # Check that the child does not inherit a value for due child = descriptor.get_children()[0] self.assertEqual(child.due, None) + + # Check that the child hasn't started yet self.assertLessEqual( - child.start, - datetime.datetime.now(UTC()) + datetime.datetime.now(UTC()), + child.start ) def test_metadata_override_default(self): diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index acc0d4655f..d0f6996a4b 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -1,15 +1,16 @@ from datetime import datetime +from pytz import UTC from django.core.urlresolvers import reverse from django.test import TestCase from django.test.utils import override_settings from student.tests.factories import UserFactory, CourseEnrollmentFactory -from django_comment_common.models import Role, Permission from django_comment_client.tests.factories import RoleFactory import django_comment_client.utils as utils from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE + class DictionaryTestCase(TestCase): def test_extract(self): d = {'cats': 'meow', 'dogs': 'woof'} @@ -128,7 +129,13 @@ class CoursewareContextTestCase(ModuleStoreTestCase): @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class CategoryMapTestCase(ModuleStoreTestCase): def setUp(self): - self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") + self.course = CourseFactory.create( + org="TestX", number="101", display_name="Test Course", + # This test needs to use a course that has already started -- + # discussion topics only show up if the course has already started, + # and the default start date for courses is Jan 1, 2030. + start=datetime(2012, 2, 3, tzinfo=UTC) + ) # Courses get a default discussion topic on creation, so remove it self.course.discussion_topics = {} self.course.save()