From 0c1ebd8dfb3a10f0b6321d72c38adca02de28e1a Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Fri, 30 Nov 2012 19:05:26 -0500 Subject: [PATCH] add toylab test data and test changes, including fix to jump_to --- common/lib/xmodule/xmodule/html_module.py | 4 +- common/test/data/toy/html/secret/toylab.html | 4 + lms/djangoapps/courseware/tests/tests.py | 101 +++++++++++++++---- lms/djangoapps/courseware/views.py | 17 ++-- 4 files changed, 101 insertions(+), 25 deletions(-) diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py index 4f10cc84f1..eea747e332 100644 --- a/common/lib/xmodule/xmodule/html_module.py +++ b/common/lib/xmodule/xmodule/html_module.py @@ -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): diff --git a/common/test/data/toy/html/secret/toylab.html b/common/test/data/toy/html/secret/toylab.html index 760482c4a0..b2a4599cc6 100644 --- a/common/test/data/toy/html/secret/toylab.html +++ b/common/test/data/toy/html/secret/toylab.html @@ -1,5 +1,6 @@ Lab 2A: Superposition Experiment +<<<<<<< Updated upstream

Isn't the toy course great?

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ædia, or foreig Looking beyond latin-1, we should handle math symbols: πr² ≤ ∞. And it shouldn't matter if we use entities or numeric codes — Ω ≠ π ≡ Ω ≠ π.

+======= +

Isn't the toy course great? — ≤

+>>>>>>> Stashed changes diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 8239eadfd9..defbf426cc 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -1,21 +1,15 @@ -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 != 302: + 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) + + 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 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) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 73d40b05c5..276af80ca9 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -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): """