From 911a38bd33a48c9e90c49037aa8250a311b4db28 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 15 Jan 2014 14:02:08 -0500 Subject: [PATCH 1/2] Change default start date for About pages So that About pages will display in the LMS if the user is not logged in --- common/lib/xmodule/xmodule/html_module.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py index 73b5baf2d6c6..2f87053abdbe 100644 --- a/common/lib/xmodule/xmodule/html_module.py +++ b/common/lib/xmodule/xmodule/html_module.py @@ -3,11 +3,14 @@ import logging import os import sys +from datetime import datetime from lxml import etree from path import path +from pytz import UTC from pkg_resources import resource_string from xblock.fields import Scope, String, Boolean +from xmodule.fields import Date from xmodule.editing_module import EditingDescriptor from xmodule.html_checker import check_html from xmodule.stringify import stringify_children @@ -227,6 +230,12 @@ class AboutFields(object): default="", scope=Scope.content ) + # this exists purely to override the default start date + start = Date( + help="placeholder to make sure that About is always active", + default=datetime.fromtimestamp(0, UTC), + scope=Scope.settings, + ) class AboutModule(AboutFields, HtmlModule): From 39a6324ccfb0023c15c1530cb2ea12ec8ade96f0 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 15 Jan 2014 14:47:53 -0500 Subject: [PATCH 2/2] add tests for about page --- common/lib/xmodule/xmodule/x_module.py | 3 +- lms/djangoapps/courseware/tests/test_about.py | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lms/djangoapps/courseware/tests/test_about.py diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index e7bc5c47fbd8..e9eaab66f9f2 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -960,7 +960,8 @@ def get_field_provenance(self, xblock, field): def render(self, block, view_name, context=None): if view_name == 'student_view': - assert block.xmodule_runtime is not None + assert block.xmodule_runtime is not None, \ + "{block} xmodule runtime must not be None".format(block=block) if isinstance(block, (XModule, XModuleDescriptor)): to_render = block._xmodule else: diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py new file mode 100644 index 000000000000..a999ad9162f5 --- /dev/null +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -0,0 +1,30 @@ +from django.test.utils import override_settings +from django.core.urlresolvers import reverse + +from .helpers import LoginEnrollmentTestCase +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + + +@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) +class AboutTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): + def setUp(self): + self.course = CourseFactory.create() + self.about = ItemFactory.create( + category="about", parent_location=self.course.location, + data="OOGIE BLOOGIE", display_name="overview" + ) + + def test_logged_in(self): + self.setup_user() + url = reverse('about_course', args=[self.course.id]) + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) + self.assertIn("OOGIE BLOOGIE", resp.content) + + def test_anonymous_user(self): + url = reverse('about_course', args=[self.course.id]) + resp = self.client.get(url) + self.assertEqual(resp.status_code, 200) + self.assertIn("OOGIE BLOOGIE", resp.content)