Tests of the localized start dates
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
Tests courseware views.py
|
||||
"""
|
||||
import unittest
|
||||
from mock import MagicMock, patch
|
||||
from datetime import datetime
|
||||
|
||||
from mock import MagicMock, patch
|
||||
from pytz import UTC
|
||||
|
||||
from django.test import TestCase
|
||||
@@ -30,15 +31,16 @@ from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
|
||||
from course_modes.models import CourseMode
|
||||
import shoppingcart
|
||||
|
||||
from util.tests.test_date_utils import fake_ugettext, fake_pgettext
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
class TestJumpTo(TestCase):
|
||||
"""
|
||||
Check the jumpto link for a course.
|
||||
Check the jumpto link for a course.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
|
||||
# Use toy course from XML
|
||||
self.course_name = 'edX/toy/2012_Fall'
|
||||
|
||||
@@ -71,7 +73,9 @@ class TestJumpTo(TestCase):
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
class ViewsTestCase(TestCase):
|
||||
""" Tests for views.py methods. """
|
||||
"""
|
||||
Tests for views.py methods.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.user = User.objects.create(username='dummy', password='123456',
|
||||
email='test@mit.edu')
|
||||
@@ -366,3 +370,57 @@ class TestAccordionDueDate(BaseDueDateTests):
|
||||
return views.render_accordion(
|
||||
self.request, course, course.get_children()[0].id, None, None
|
||||
)
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
class StartDateTests(ModuleStoreTestCase):
|
||||
"""
|
||||
Test that start dates are properly localized and displayed on the student
|
||||
dashboard.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.request_factory = RequestFactory()
|
||||
self.user = UserFactory.create()
|
||||
self.request = self.request_factory.get("foo")
|
||||
self.request.user = self.user
|
||||
|
||||
def set_up_course(self):
|
||||
"""
|
||||
Create a stock course with a specific due date.
|
||||
|
||||
:param course_kwargs: All kwargs are passed to through to the :class:`CourseFactory`
|
||||
"""
|
||||
course = CourseFactory(start=datetime(2013, 9, 16, 7, 17, 28))
|
||||
course = modulestore().get_instance(course.id, course.location) # pylint: disable=no-member
|
||||
return course
|
||||
|
||||
def get_about_text(self, course_id):
|
||||
"""
|
||||
Get the text of the /about page for the course.
|
||||
"""
|
||||
text = views.course_about(self.request, course_id).content
|
||||
return text
|
||||
|
||||
@patch('util.date_utils.pgettext', fake_pgettext(translations={
|
||||
("abbreviated month name", "Sep"): "SEPTEMBER",
|
||||
}))
|
||||
@patch('util.date_utils.ugettext', fake_ugettext(translations={
|
||||
"SHORT_DATE_FORMAT": "%Y-%b-%d",
|
||||
}))
|
||||
def test_format_localized_in_studio_course(self):
|
||||
course = self.set_up_course()
|
||||
text = self.get_about_text(course.id)
|
||||
# The start date is set in the set_up_course function above.
|
||||
self.assertIn("2013-SEPTEMBER-16", text)
|
||||
|
||||
@patch('util.date_utils.pgettext', fake_pgettext(translations={
|
||||
("abbreviated month name", "Jul"): "JULY",
|
||||
}))
|
||||
@patch('util.date_utils.ugettext', fake_ugettext(translations={
|
||||
"SHORT_DATE_FORMAT": "%Y-%b-%d",
|
||||
}))
|
||||
def test_format_localized_in_xml_course(self):
|
||||
text = self.get_about_text('edX/toy/TT_2012_Fall')
|
||||
# The start date is set in common/test/data/two_toys/policies/TT_2012_Fall/policy.json
|
||||
self.assertIn("2015-JULY-17", text)
|
||||
|
||||
Reference in New Issue
Block a user