From cc091f833a0f3c18ad287548d34946b8cf653b2b Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 6 Feb 2014 16:41:21 -0500 Subject: [PATCH] Add test for ignoring tilde files on import of extra content --- .../xmodule/modulestore/tests/test_xml.py | 33 +++++++++++++++++-- common/test/data/tilde/about/index.html | 1 + common/test/data/tilde/about/index.html~ | 1 + common/test/data/tilde/course.xml | 1 + common/test/data/tilde/course/2012_Fall.xml | 2 ++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 common/test/data/tilde/about/index.html create mode 100644 common/test/data/tilde/about/index.html~ create mode 100644 common/test/data/tilde/course.xml create mode 100644 common/test/data/tilde/course/2012_Fall.xml diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py b/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py index 9e15440f11..bdde8b8e6c 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py @@ -1,16 +1,29 @@ import os.path +import unittest +from glob import glob +from mock import patch from nose.tools import assert_raises, assert_equals # pylint: disable=E0611 from xmodule.course_module import CourseDescriptor from xmodule.modulestore.xml import XMLModuleStore -from xmodule.modulestore import XML_MODULESTORE_TYPE +from xmodule.modulestore import Location, XML_MODULESTORE_TYPE from .test_modulestore import check_path_to_location from xmodule.tests import DATA_DIR +def glob_tildes_at_end(path): + """ + A wrapper for the `glob.glob` function, but it always returns + files that end in a tilde (~) at the end of the list of results. + """ + result = glob(path) + with_tildes = [f for f in result if f.endswith("~")] + no_tildes = [f for f in result if not f.endswith("~")] + return no_tildes + with_tildes -class TestXMLModuleStore(object): + +class TestXMLModuleStore(unittest.TestCase): def test_path_to_location(self): """Make sure that path_to_location works properly""" @@ -42,3 +55,19 @@ class TestXMLModuleStore(object): location = CourseDescriptor.id_to_location("edX/toy/2012_Fall") errors = modulestore.get_item_errors(location) assert errors == [] + + @patch("xmodule.modulestore.xml.glob.glob", side_effect=glob_tildes_at_end) + def test_tilde_files_ignored(self, fake_glob): + modulestore = XMLModuleStore(DATA_DIR, course_dirs=['tilde'], load_error_modules=False) + course_module = modulestore.modules['edX/tilde/2012_Fall'] + about_location = Location({ + 'tag': 'i4x', + 'org': 'edX', + 'course': 'tilde', + 'category': 'about', + 'name': 'index', + }) + about_module = course_module[about_location] + self.assertIn("GREEN", about_module.data) + self.assertNotIn("RED", about_module.data) + diff --git a/common/test/data/tilde/about/index.html b/common/test/data/tilde/about/index.html new file mode 100644 index 0000000000..d991f425fb --- /dev/null +++ b/common/test/data/tilde/about/index.html @@ -0,0 +1 @@ +GREEN diff --git a/common/test/data/tilde/about/index.html~ b/common/test/data/tilde/about/index.html~ new file mode 100644 index 0000000000..f24fc29aa6 --- /dev/null +++ b/common/test/data/tilde/about/index.html~ @@ -0,0 +1 @@ +RED diff --git a/common/test/data/tilde/course.xml b/common/test/data/tilde/course.xml new file mode 100644 index 0000000000..0489d7eed4 --- /dev/null +++ b/common/test/data/tilde/course.xml @@ -0,0 +1 @@ + diff --git a/common/test/data/tilde/course/2012_Fall.xml b/common/test/data/tilde/course/2012_Fall.xml new file mode 100644 index 0000000000..c9d2e8702d --- /dev/null +++ b/common/test/data/tilde/course/2012_Fall.xml @@ -0,0 +1,2 @@ + +