Commit 0c1ebd8d by Brian Wilson

add toylab test data and test changes, including fix to jump_to

parent 9bfa8002
......@@ -30,7 +30,9 @@ class HtmlModule(XModule):
def get_html(self):
# cdodge: perform link substitutions for any references to course static content (e.g. images)
return rewrite_links(self.html, self.rewrite_content_links)
output = rewrite_links(self.html, self.rewrite_content_links)
log.info(' HTMLModule converting markup "{0}" to "{1}"'.format(self.html, output))
return output
def __init__(self, system, location, definition, descriptor,
instance_state=None, shared_state=None, **kwargs):
......
<b>Lab 2A: Superposition Experiment</b>
<<<<<<< Updated upstream
<p>Isn't the toy course great?</p>
<p>Let's add some markup that uses non-ascii characters.
......@@ -7,3 +8,6 @@ For example, we should be able to write words like encyclop&aelig;dia, or foreig
Looking beyond latin-1, we should handle math symbols: &pi;r&sup2 &le; &#8734.
And it shouldn't matter if we use entities or numeric codes &mdash; &Omega; &ne; &pi; &equiv; &#937; &#8800; &#960;.
</p>
=======
<p>Isn't the toy course great? — &le;</p>
>>>>>>> Stashed changes
import copy
import json
import os
import sys
import time
from nose import SkipTest
from path import path
from pprint import pprint
from urlparse import urlsplit, urlunsplit
from django.contrib.auth.models import User, Group
from django.core.handlers.wsgi import WSGIRequest
from django.test import TestCase
from django.test.client import Client, RequestFactory
from django.test.client import RequestFactory
from django.conf import settings
from django.core.urlresolvers import reverse
from mock import patch, Mock
from override_settings import override_settings
import xmodule.modulestore.django
......@@ -29,6 +23,7 @@ from student.models import Registration
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import Location
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.xml import XMLModuleStore
from xmodule.timeparse import stringify_time
def parse_json(response):
......@@ -76,10 +71,21 @@ def xml_store_config(data_dir):
}
}
def my_xml_store_config(data_dir):
return {
'default': {
'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore',
'OPTIONS': {
'data_dir': data_dir,
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
}
}
}
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR)
# TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR)
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
MY_TEST_DATA_XML_MODULESTORE = my_xml_store_config(TEST_DATA_DIR)
REAL_DATA_DIR = settings.GITHUB_REPO_ROOT
REAL_DATA_MODULESTORE = mongo_store_config(REAL_DATA_DIR)
......@@ -252,34 +258,93 @@ class PageLoader(ActivateLoginTestCase):
#print descriptor.__class__, descriptor.location
resp = self.client.get(reverse('jump_to',
kwargs={'course_id': course_id,
'location': descriptor.location.url()}))
'location': descriptor.location.url()}), follow=True)
msg = str(resp.status_code)
if resp.status_code != 200:
msg = "ERROR " + msg # + ": " + str(resp.request['PATH_INFO'])
all_ok = False
num_bad += 1
elif resp.redirect_chain[0][1] != 302:
msg = "ERROR " + msg
all_ok = False
num_bad += 1
print msg
# self.assertTrue(all_ok) # fail fast
if resp.status_code != 302:
print "{0}/{1} good".format(n - num_bad, n)
self.assertTrue(all_ok)
def check_xml_pages_load(self, course_name, data_dir, modstore):
"""Make all locations in course load"""
print "Checking course {0} in {1}".format(course_name, data_dir)
default_class='xmodule.hidden_module.HiddenDescriptor' # 'xmodule.raw_module.RawDescriptor',
load_error_modules=True
module_store = XMLModuleStore(
data_dir,
default_class=default_class,
course_dirs=[course_name],
load_error_modules=load_error_modules,
)
# for course_id in module_store.modules.keys():
# for module in module_store.modules[course_id].itervalues():
#
# if 'data' in module.definition:
# store.update_item(module.location, module.definition['data'])
# if 'children' in module.definition:
# store.update_children(module.location, module.definition['children'])
# # NOTE: It's important to use own_metadata here to avoid writing
# # inherited metadata everywhere.
# store.update_metadata(module.location, dict(module.own_metadata))
# enroll in the course before trying to access pages
courses = module_store.get_courses()
self.assertEqual(len(courses), 1)
course = courses[0]
self.enroll(course)
course_id = course.id
n = 0
num_bad = 0
all_ok = True
for descriptor in module_store.modules[course_id].itervalues():
n += 1
print "Checking ", descriptor.location.url()
#print descriptor.__class__, descriptor.location
resp = self.client.get(reverse('jump_to',
kwargs={'course_id': course_id,
'location': descriptor.location.url()}), follow=True)
msg = str(resp.status_code)
if resp.status_code != 200:
msg = "ERROR " + msg # + ": " + str(resp.request['PATH_INFO'])
all_ok = False
num_bad += 1
elif resp.redirect_chain[0][1] != 302:
msg = "ERROR " + msg
all_ok = False
num_bad += 1
print msg
self.assertTrue(all_ok) # fail fast
# self.assertTrue(all_ok) # fail fast
print "{0}/{1} good".format(n - num_bad, n)
self.assertTrue(all_ok)
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
#@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@override_settings(MODULESTORE=MY_TEST_DATA_XML_MODULESTORE)
class TestCoursesLoadTestCase(PageLoader):
'''Check that all pages in test courses load properly'''
def setUp(self):
ActivateLoginTestCase.setUp(self)
xmodule.modulestore.django._MODULESTORES = {}
xmodule.modulestore.django.modulestore().collection.drop()
# xmodule.modulestore.django.modulestore().collection.drop()
# store = xmodule.modulestore.django.modulestore()
# is there a way to empty the store?
def test_toy_course_loads(self):
self.check_pages_load('toy', TEST_DATA_DIR, modulestore())
self.check_xml_pages_load('toy', TEST_DATA_DIR, modulestore())
def test_full_course_loads(self):
self.check_pages_load('full', TEST_DATA_DIR, modulestore())
# def test_full_course_loads(self):
# self.check_pages_load('full', TEST_DATA_DIR, modulestore())
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
......
......@@ -293,7 +293,6 @@ def index(request, course_id, chapter=None, section=None,
return result
@ensure_csrf_cookie
def jump_to(request, course_id, location):
'''
......@@ -318,12 +317,18 @@ def jump_to(request, course_id, location):
except NoPathToItem:
raise Http404("This location is not in any class: {0}".format(location))
# choose the appropriate view (and provide the necessary args) based on the
# args provided by the redirect.
# Rely on index to do all error handling and access control.
return redirect('courseware_position',
course_id=course_id,
chapter=chapter,
section=section,
position=position)
if chapter is None:
return redirect('courseware', course_id=course_id)
elif section is None:
return redirect('courseware_chapter', course_id=course_id, chapter=chapter)
elif position is None:
return redirect('courseware_section', course_id=course_id, chapter=chapter, section=section)
else:
return redirect('courseware_position', course_id=course_id, chapter=chapter, section=section, position=position)
@ensure_csrf_cookie
def course_info(request, course_id):
"""
......
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