diff --git a/common/lib/xmodule/xmodule/modulestore/tests/__init__.py b/common/lib/xmodule/xmodule/modulestore/tests/__init__.py index 2759f2540c34..e69de29bb2d1 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/__init__.py @@ -1,10 +0,0 @@ -from path import path - -# from ~/mitx_all/mitx/common/lib/xmodule/xmodule/modulestore/tests/ -# to ~/mitx_all/mitx/common/test -TEST_DIR = path(__file__).abspath().dirname() -for i in range(5): - TEST_DIR = TEST_DIR.dirname() -TEST_DIR = TEST_DIR / 'test' - -DATA_DIR = TEST_DIR / 'data' diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index c149724cc7ec..69ba9ad94b92 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -1,18 +1,18 @@ -import pymongo +from pprint import pprint from nose.tools import assert_equals, assert_raises, assert_not_equals, assert_false -from pprint import pprint +import pymongo +from uuid import uuid4 from xblock.core import Scope from xblock.runtime import KeyValueStore, InvalidScopeError +from xmodule.tests import DATA_DIR from xmodule.modulestore import Location from xmodule.modulestore.mongo import MongoModuleStore, MongoKeyValueStore from xmodule.modulestore.xml_importer import import_from_xml -from .test_modulestore import check_path_to_location -from . import DATA_DIR -from uuid import uuid4 +from xmodule.modulestore.tests.test_modulestore import check_path_to_location HOST = 'localhost' diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py b/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py index c3b7ea58bc58..181985061478 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_xml.py @@ -1,12 +1,12 @@ import os.path +from nose.tools import assert_raises + from xmodule.course_module import CourseDescriptor from xmodule.modulestore.xml import XMLModuleStore -from nose.tools import assert_raises - -from .test_modulestore import check_path_to_location -from . import DATA_DIR +from xmodule.tests import DATA_DIR +from xmodule.modulestore.tests.test_modulestore import check_path_to_location class TestXMLModuleStore(object): diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_xml_exporter.py b/common/lib/xmodule/xmodule/modulestore/tests/test_xml_exporter.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py index c9d6e96761d9..ebf906787f1a 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py @@ -38,7 +38,7 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d Export all modules from `modulestore` and content from `contentstore` as xml to `root_dir`. `modulestore`: A `ModuleStore` object that is the source of the modules to export - `contentstore`: A `ContentStore` object that is the source of the content to export + `contentstore`: A `ContentStore` object that is the source of the content to export, can be None `course_location`: The `Location` of the `CourseModuleDescriptor` to export `root_dir`: The directory to write the exported xml to `course_dir`: The name of the directory inside `root_dir` to write the course content to @@ -46,7 +46,12 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d alongside the public content in the course. """ - course = modulestore.get_item(course_location) + # we use get_instance instead of get_item to support modulestores + # that can't guarantee that definitions are unique + course = modulestore.get_instance( + course_location.course_id, + course_location + ) fs = OSFS(root_dir) export_fs = fs.makeopendir(course_dir) @@ -56,7 +61,8 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d course_xml.write(xml) # export the static assets - contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/') + if contentstore: + contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/') # export the static tabs export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html') diff --git a/common/lib/xmodule/xmodule/tests/__init__.py b/common/lib/xmodule/xmodule/tests/__init__.py index f599e0dd3bb9..1f5f1ed691ce 100644 --- a/common/lib/xmodule/xmodule/tests/__init__.py +++ b/common/lib/xmodule/xmodule/tests/__init__.py @@ -7,19 +7,24 @@ """ -import unittest +import json import os +import unittest + import fs import fs.osfs - import numpy - -import json +from mock import Mock +from path import path import calc -import xmodule -from xmodule.x_module import ModuleSystem -from mock import Mock +from xmodule.x_module import ModuleSystem, XModuleDescriptor + + +# Location of common test DATA directory +# '../../../../edx-platform/common/test/data/' +MODULE_DIR = path(__file__).dirname() +DATA_DIR = path.joinpath(*MODULE_DIR.splitall()[:-4]) / 'test/data/' open_ended_grading_interface = { @@ -67,7 +72,7 @@ def setUp(self): pass def test_load_class(self): - vc = xmodule.x_module.XModuleDescriptor.load_class('video') + vc = XModuleDescriptor.load_class('video') vc_str = "" self.assertEqual(str(vc), vc_str) diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py index 4fd0ddccf7bd..8f703239a9d2 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -1,8 +1,19 @@ +""" +Tests for the various pieces of the CombinedOpenEndedGrading system + +OpenEndedChild +OpenEndedModule + +""" + +from datetime import datetime import json -from mock import Mock, MagicMock, ANY +import logging import unittest -from test_util_open_ended import MockQueryDict, DummyModulestore +from lxml import etree +from mock import Mock, MagicMock, ANY +from pytz import UTC from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild from xmodule.open_ended_grading_classes.open_ended_module import OpenEndedModule @@ -10,30 +21,16 @@ from xmodule.open_ended_grading_classes.grading_service_module import GradingServiceError from xmodule.combined_open_ended_module import CombinedOpenEndedModule from xmodule.modulestore import Location - -from lxml import etree +from xmodule.tests import get_test_system, test_util_open_ended +from xmodule.tests.test_util_open_ended import MockQueryDict, DummyModulestore import capa.xqueue_interface as xqueue_interface -from datetime import datetime -from pytz import UTC -import logging -log = logging.getLogger(__name__) -from . import get_test_system +log = logging.getLogger(__name__) ORG = 'edX' COURSE = 'open_ended' # name of directory with course data -import test_util_open_ended - -""" -Tests for the various pieces of the CombinedOpenEndedGrading system - -OpenEndedChild -OpenEndedModule - -""" - class OpenEndedChildTest(unittest.TestCase): """ diff --git a/common/lib/xmodule/xmodule/tests/test_conditional.py b/common/lib/xmodule/xmodule/tests/test_conditional.py index b28d23636937..95472a62ede9 100644 --- a/common/lib/xmodule/xmodule/tests/test_conditional.py +++ b/common/lib/xmodule/xmodule/tests/test_conditional.py @@ -1,22 +1,21 @@ +from ast import literal_eval import json import unittest + from fs.memoryfs import MemoryFS -from ast import literal_eval from mock import Mock, patch from xmodule.error_module import NonStaffErrorDescriptor from xmodule.modulestore import Location from xmodule.modulestore.xml import ImportSystem, XMLModuleStore from xmodule.conditional_module import ConditionalModule +from xmodule.tests import DATA_DIR, get_test_system -from xmodule.tests.test_export import DATA_DIR ORG = 'test_org' COURSE = 'conditional' # name of directory with course data -from . import get_test_system - class DummySystem(ImportSystem): diff --git a/common/lib/xmodule/xmodule/tests/test_export.py b/common/lib/xmodule/xmodule/tests/test_export.py index 91ef1bae5750..d9b80422e99b 100644 --- a/common/lib/xmodule/xmodule/tests/test_export.py +++ b/common/lib/xmodule/xmodule/tests/test_export.py @@ -2,28 +2,19 @@ Tests of XML export """ +from datetime import datetime, timedelta, tzinfo +from tempfile import mkdtemp import unittest -import pytz +import shutil -from datetime import datetime, timedelta, tzinfo +import pytz from fs.osfs import OSFS from path import path -from tempfile import mkdtemp -import shutil +from xmodule.modulestore import Location from xmodule.modulestore.xml import XMLModuleStore from xmodule.modulestore.xml_exporter import EdxJSONEncoder - -from xmodule.modulestore import Location - -# from ~/mitx_all/mitx/common/lib/xmodule/xmodule/tests/ -# to ~/mitx_all/mitx/common/test -TEST_DIR = path(__file__).abspath().dirname() -for i in range(4): - TEST_DIR = TEST_DIR.dirname() -TEST_DIR = TEST_DIR / 'test' - -DATA_DIR = TEST_DIR / 'data' +from xmodule.tests import DATA_DIR def strip_filenames(descriptor): diff --git a/common/lib/xmodule/xmodule/tests/test_import.py b/common/lib/xmodule/xmodule/tests/test_import.py index fb1bed2d3ab0..b6758dc9179e 100644 --- a/common/lib/xmodule/xmodule/tests/test_import.py +++ b/common/lib/xmodule/xmodule/tests/test_import.py @@ -1,20 +1,21 @@ # -*- coding: utf-8 -*- +import datetime import unittest -from fs.memoryfs import MemoryFS +from fs.memoryfs import MemoryFS from lxml import etree from mock import Mock, patch +from django.utils.timezone import UTC + from xmodule.xml_module import is_pointer_tag from xmodule.modulestore import Location from xmodule.modulestore.xml import ImportSystem, XMLModuleStore from xmodule.modulestore.inheritance import compute_inherited_metadata from xmodule.fields import Date +from xmodule.tests import DATA_DIR -from .test_export import DATA_DIR -import datetime -from django.utils.timezone import UTC ORG = 'test_org' COURSE = 'test_course' diff --git a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py index 63fb4631c982..c717d52d3146 100644 --- a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py @@ -1,7 +1,6 @@ -from .import get_test_system from xmodule.modulestore import Location from xmodule.modulestore.xml import XMLModuleStore -from xmodule.tests.test_export import DATA_DIR +from xmodule.tests import DATA_DIR, get_test_system OPEN_ENDED_GRADING_INTERFACE = { 'url': 'blah/', @@ -42,7 +41,7 @@ class DummyModulestore(object): def setup_modulestore(self, name): self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) - def get_course(self, name): + def get_course(self, _): """Get a test course by directory name. If there's more than one, error.""" courses = self.modulestore.get_courses() return courses[0]