From f10c4c06b61e3691658c08e274d78a7257acadf6 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Thu, 19 Jul 2012 18:21:45 -0400 Subject: [PATCH] Start adding tests for mongo modulestore * fix up toy course to match current format * fix github sync test that referred to toy course --- .../xmodule/modulestore/tests/test_mongo.py | 45 +++++++- common/test/data/toy/course.xml | 2 +- common/test/data/toy/html/Lab2A.html | 105 ------------------ common/test/data/toy/html/toylab.html | 3 + 4 files changed, 43 insertions(+), 112 deletions(-) delete mode 100644 common/test/data/toy/html/Lab2A.html create mode 100644 common/test/data/toy/html/toylab.html diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index ffcbe1717d..55e573677f 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -1,28 +1,61 @@ +import pymongo + from nose.tools import assert_equals, assert_raises, assert_not_equals, with_setup +from path import path + from xmodule.modulestore import Location from xmodule.modulestore.exceptions import InvalidLocationError from xmodule.modulestore.mongo import MongoModuleStore +from xmodule.modulestore.xml_importer import import_from_xml + +# 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' -host = 'localhost' -db = 'xmodule' -collection = 'modulestore' -fs_root = None # TODO (vshnayder): will need a real fs_root for testing load_item -default_class = 'xmodule.raw_module.RawDescriptor' +HOST = 'localhost' +PORT = 27017 +DB = 'test' +COLLECTION = 'modulestore' +FS_ROOT = DATA_DIR # TODO (vshnayder): will need a real fs_root for testing load_item +DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor' +connection = None + +def setup(): + global connection + connection = pymongo.connection.Connection(HOST, PORT) + + def setup_func(): # connect to the db global store - store = MongoModuleStore(host, db, collection, fs_root, default_class=default_class) + store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, default_class=DEFAULT_CLASS) + print 'data_dir: {0}'.format(DATA_DIR) + import_from_xml(store, DATA_DIR) def teardown_func(): global store store = None + # Destroy the test db. + connection.drop_database(DB) + @with_setup(setup_func, teardown_func) def test_init(): '''Just make sure the db loads''' pass +@with_setup(setup_func, teardown_func) +def test_get_courses(): + '''Make sure the course objects loaded properly''' + courses = store.get_courses() + print courses + diff --git a/common/test/data/toy/course.xml b/common/test/data/toy/course.xml index ba4b295c2e..391eb68e2b 100644 --- a/common/test/data/toy/course.xml +++ b/common/test/data/toy/course.xml @@ -2,7 +2,7 @@ diff --git a/common/test/data/toy/html/Lab2A.html b/common/test/data/toy/html/Lab2A.html deleted file mode 100644 index 7fe52cc1be..0000000000 --- a/common/test/data/toy/html/Lab2A.html +++ /dev/null @@ -1,105 +0,0 @@ - - -Lab 2A: Superposition Experiment - -

Note: This part of the lab is just to develop your intuition about -superposition. There are no responses that need to be checked. - -

Circuits with multiple sources can be hard to analyze as-is. For example, what is the voltage -between the two terminals on the right of Figure 1? - -
- -Figure 1. Example multi-source circuit -
- -

We can use superposition to make the analysis much easier. -The circuit in Figure 1 can be decomposed into two separate -subcircuits: one involving only the voltage source and one involving only the -current source. We'll analyze each circuit separately and combine the -results using superposition. Recall that to decompose a circuit for -analysis, we'll pick each source in turn and set all the other sources -to zero (i.e., voltage sources become short circuits and current -sources become open circuits). The circuit above has two sources, so -the decomposition produces two subcircuits, as shown in Figure 2. - -
-
- -(a) Subcircuit for analyzing contribution of voltage source - - -(b) Subcircuit for analyzing contribution of current source -
-
Figure 2. Decomposition of Figure 1 into subcircuits -
- -
Let's use the DC analysis capability of the schematic tool to see superposition -in action. The sliders below control the resistances of R1, R2, R3 and R4 in all -the diagrams. As you move the sliders, the schematic tool will adjust the appropriate -resistance, perform a DC analysis and display the node voltages on the diagrams. Here's -what you want to observe as you play with the sliders: - - - -
-
- -
- - - - - - - - - - - - - - - - - -
R1 -
-
R2 -
-
R3 -
-
R4 -
-
-
-
diff --git a/common/test/data/toy/html/toylab.html b/common/test/data/toy/html/toylab.html new file mode 100644 index 0000000000..81df84bd63 --- /dev/null +++ b/common/test/data/toy/html/toylab.html @@ -0,0 +1,3 @@ +Lab 2A: Superposition Experiment + +

Isn't the toy course great?