Commit d1dc8c91 by David Baumgold

Add README to tilde fixture, fix pylint/pep8 issues

parent 83b0eda4
"""
Tests around our XML modulestore, including importing
well-formed and not-well-formed XML.
"""
import os.path import os.path
import unittest import unittest
from glob import glob from glob import glob
...@@ -12,6 +16,7 @@ from xmodule.modulestore import Location, XML_MODULESTORE_TYPE ...@@ -12,6 +16,7 @@ from xmodule.modulestore import Location, XML_MODULESTORE_TYPE
from .test_modulestore import check_path_to_location from .test_modulestore import check_path_to_location
from xmodule.tests import DATA_DIR from xmodule.tests import DATA_DIR
def glob_tildes_at_end(path): def glob_tildes_at_end(path):
""" """
A wrapper for the `glob.glob` function, but it always returns A wrapper for the `glob.glob` function, but it always returns
...@@ -24,6 +29,9 @@ def glob_tildes_at_end(path): ...@@ -24,6 +29,9 @@ def glob_tildes_at_end(path):
class TestXMLModuleStore(unittest.TestCase): class TestXMLModuleStore(unittest.TestCase):
"""
Test around the XML modulestore
"""
def test_path_to_location(self): def test_path_to_location(self):
"""Make sure that path_to_location works properly""" """Make sure that path_to_location works properly"""
...@@ -57,7 +65,7 @@ class TestXMLModuleStore(unittest.TestCase): ...@@ -57,7 +65,7 @@ class TestXMLModuleStore(unittest.TestCase):
assert errors == [] assert errors == []
@patch("xmodule.modulestore.xml.glob.glob", side_effect=glob_tildes_at_end) @patch("xmodule.modulestore.xml.glob.glob", side_effect=glob_tildes_at_end)
def test_tilde_files_ignored(self, fake_glob): def test_tilde_files_ignored(self, _fake_glob):
modulestore = XMLModuleStore(DATA_DIR, course_dirs=['tilde'], load_error_modules=False) modulestore = XMLModuleStore(DATA_DIR, course_dirs=['tilde'], load_error_modules=False)
course_module = modulestore.modules['edX/tilde/2012_Fall'] course_module = modulestore.modules['edX/tilde/2012_Fall']
about_location = Location({ about_location = Location({
...@@ -70,4 +78,3 @@ class TestXMLModuleStore(unittest.TestCase): ...@@ -70,4 +78,3 @@ class TestXMLModuleStore(unittest.TestCase):
about_module = course_module[about_location] about_module = course_module[about_location]
self.assertIn("GREEN", about_module.data) self.assertIn("GREEN", about_module.data)
self.assertNotIn("RED", about_module.data) self.assertNotIn("RED", about_module.data)
...@@ -405,8 +405,9 @@ class XMLModuleStore(ModuleStoreReadBase): ...@@ -405,8 +405,9 @@ class XMLModuleStore(ModuleStoreReadBase):
try: try:
course_descriptor = self.load_course(course_dir, errorlog.tracker) course_descriptor = self.load_course(course_dir, errorlog.tracker)
except Exception as e: except Exception as e:
msg = "ERROR: Failed to load course '{0}': {1}".format(course_dir.encode("utf-8"), msg = "ERROR: Failed to load course '{0}': {1}".format(
unicode(e)) course_dir.encode("utf-8"), unicode(e)
)
log.exception(msg) log.exception(msg)
errorlog.tracker(msg) errorlog.tracker(msg)
...@@ -568,7 +569,7 @@ class XMLModuleStore(ModuleStoreReadBase): ...@@ -568,7 +569,7 @@ class XMLModuleStore(ModuleStoreReadBase):
if not os.path.isfile(filepath): if not os.path.isfile(filepath):
continue continue
if filepath.endswith('~'): # skip *~ files if filepath.endswith('~'): # skip *~ files
continue continue
with open(filepath) as f: with open(filepath) as f:
......
"""
Tests that check that we ignore the appropriate files when importing courses.
"""
import unittest import unittest
from path import path
from mock import Mock from mock import Mock
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.xml_importer import import_static_content from xmodule.modulestore.xml_importer import import_static_content
...@@ -7,8 +9,9 @@ from xmodule.tests import DATA_DIR ...@@ -7,8 +9,9 @@ from xmodule.tests import DATA_DIR
class IgnoredFilesTestCase(unittest.TestCase): class IgnoredFilesTestCase(unittest.TestCase):
"Tests for ignored files"
def test_ignore_tilde_static_files(self): def test_ignore_tilde_static_files(self):
course_dir= DATA_DIR / "tilde" course_dir = DATA_DIR / "tilde"
loc = Location("edX", "tilde", "Fall_2012") loc = Location("edX", "tilde", "Fall_2012")
content_store = Mock() content_store = Mock()
content_store.generate_thumbnail.return_value = ("content", "location") content_store.generate_thumbnail.return_value = ("content", "location")
......
DO NOT DELETE TILDE FILES
This course simulates an export that has been edited by hand, where the editor's
text editor has left behind some backup files (about/index.html~ and
static/example.txt~). Normally, we do not commit files that end with tildes to
the repository, for precisely this reason -- they are backup files, and do
not belong with the content. However, in this case, we *need* these backup files
to be committed to the repository, so that we can exercise logic in the codebase
that checks for these sort of editor backup files and skips them on export.
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