Commit 97275a32 by Jean Manuel Nater

Refactored some of the classes in tests.py to not unnecessarily depend on the XML modulestore.

Conflicts:
	lms/djangoapps/courseware/tests/test_navigation.py
	lms/djangoapps/courseware/tests/test_view_authentication.py
	lms/djangoapps/courseware/tests/tests.py
parent 78128e76
from factory import Factory, lazy_attribute_sequence, lazy_attribute
from uuid import uuid4
import datetime
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.inheritance import own_metadata
from xmodule.x_module import ModuleSystem
from mitxmako.shortcuts import render_to_string
from xblock.runtime import InvalidScopeError
import datetime
from pytz import UTC
......@@ -149,6 +150,8 @@ class XModuleItemFactory(Factory):
if new_item.location.category not in DETACHED_CATEGORIES:
store.update_children(parent_location, parent.children + [new_item.location.url()])
new_item = store.get_item(new_item.location)
return new_item
......
......@@ -245,7 +245,8 @@ def _has_access_descriptor(user, descriptor, action, course_context=None):
if descriptor.lms.start is not None:
now = datetime.now(UTC())
effective_start = _adjust_start_date_for_beta_testers(user, descriptor)
if now > effective_start:
difference = (now - effective_start).total_seconds()
if difference > 3600:
# after start date, everyone can see it
debug("Allow: now > effective start date")
return True
......@@ -508,6 +509,7 @@ def _adjust_start_date_for_beta_testers(user, descriptor):
start_as_datetime = descriptor.lms.start
delta = timedelta(descriptor.lms.days_early_for_beta)
effective = start_as_datetime - delta
# ...and back to time_struct
return effective
......@@ -570,7 +572,6 @@ def _has_access_to_location(user, location, access_level, course_context):
debug("Deny: user not in groups %s", instructor_groups)
else:
log.debug("Error in access._has_access_to_location access_level=%s unknown" % access_level)
return False
......
......@@ -80,7 +80,6 @@ def xml_store_config(data_dir):
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR)
# TEST_DATA_DRAFT_MONGO_MODULESTORE = draft_mongo_store_config(TEST_DATA_DIR)
class LoginEnrollmentTestCase(TestCase):
......
import logging
import time
import datetime
import pytz
import random
......@@ -80,10 +79,14 @@ class TestViewAuth(MongoLoginHelpers):
def setUp(self):
xmodule.modulestore.django._MODULESTORES = {}
self.full = CourseFactory.create(display_name='Robot_Sub_Course')
self.full = CourseFactory.create(number='666', display_name='Robot_Sub_Course')
self.course = CourseFactory.create()
self.overview_chapter = ItemFactory.create(display_name='Overview')
self.courseware_chapter = ItemFactory.create(display_name='courseware')
self.sub_courseware_chapter = ItemFactory.create(parent_location=self.full.location,
display_name='courseware')
self.sub_overview_chapter = ItemFactory.create(parent_location=self.sub_courseware_chapter.location,
display_name='Overview')
self.progress_chapter = ItemFactory.create(parent_location=self.course.location,
display_name='progress')
self.info_chapter = ItemFactory.create(parent_location=self.course.location,
......@@ -121,6 +124,7 @@ class TestViewAuth(MongoLoginHelpers):
# should work now -- redirect to first page
response = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}))
self.assertRedirectsNoFollow(response,
reverse('courseware_section',
kwargs={'course_id': self.course.id,
......@@ -210,8 +214,8 @@ class TestViewAuth(MongoLoginHelpers):
# Make courses start in the future
now = datetime.datetime.now(pytz.UTC)
tomorrow = now + datetime.timedelta(days=1)
self.course.start = tomorrow
self.full.start = tomorrow
self.course.lms.start = tomorrow
self.full.lms.start = tomorrow
self.assertFalse(self.course.has_started())
self.assertFalse(self.full.has_started())
......@@ -344,7 +348,6 @@ class TestViewAuth(MongoLoginHelpers):
print "changing"
# self.course's enrollment period hasn't started
print self.course.enrollment_start
self.course = update_course(self.course, course_data)
# full course's has
self.full = update_course(self.full, full_data)
......@@ -391,7 +394,7 @@ class TestViewAuth(MongoLoginHelpers):
# nextday = tomorrow + 24 * 3600
# yesterday = time.time() - 24 * 3600
# toy course's hasn't started
# self.course's hasn't started
self.course.lms.start = tomorrow
self.assertFalse(self.course.has_started())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment