From 06001c8c1ecf970565788dba8957a835b3b5f4b7 Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Wed, 6 Mar 2013 17:10:15 +0200 Subject: [PATCH 1/2] fix test_logic --- .../lib/xmodule/xmodule/tests/test_logic.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_logic.py b/common/lib/xmodule/xmodule/tests/test_logic.py index 6b9a636590..018b40427e 100644 --- a/common/lib/xmodule/xmodule/tests/test_logic.py +++ b/common/lib/xmodule/xmodule/tests/test_logic.py @@ -3,20 +3,23 @@ import json import unittest -from xmodule.poll_module import PollModule -from xmodule.conditional_module import ConditionalModule +from xmodule.poll_module import PollDescriptor +from xmodule.conditional_module import ConditionalDescriptor class LogicTest(unittest.TestCase): """Base class for testing xmodule logic.""" - xmodule_class = None + descriptor_class = None raw_model_data = {} def setUp(self): + class EmptyClass: pass + self.system = None self.location = None - self.descriptor = None + self.descriptor = EmptyClass() + self.xmodule_class = self.descriptor_class.module_class self.xmodule = self.xmodule_class(self.system, self.location, self.descriptor, self.raw_model_data) @@ -25,7 +28,7 @@ class LogicTest(unittest.TestCase): class PollModuleTest(LogicTest): - xmodule_class = PollModule + descriptor_class = PollDescriptor raw_model_data = { 'poll_answers': {'Yes': 1, 'Dont_know': 0, 'No': 0}, 'voted': False, @@ -50,16 +53,14 @@ class PollModuleTest(LogicTest): class ConditionalModuleTest(LogicTest): - xmodule_class = ConditionalModule - raw_model_data = { - 'contents': 'Some content' - } + descriptor_class = ConditionalDescriptor def test_ajax_request(self): # Mock is_condition_satisfied self.xmodule.is_condition_satisfied = lambda: True + setattr(self.xmodule.descriptor, 'get_children', lambda: []) response = self.ajax_request('No', {}) html = response['html'] - self.assertEqual(html, 'Some content') + self.assertEqual(html, []) From 493421c1ec0f78f9a0793a6fd76b302445c4e064 Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Wed, 6 Mar 2013 19:52:18 +0200 Subject: [PATCH 2/2] fix `test_conditional`, add new conditional to "conditional_and_poll" test course --- .../xmodule/xmodule/tests/test_conditional.py | 18 +++++++++------ .../conditional/condone.xml | 3 +++ .../course/2013_Spring.xml | 6 +++++ .../conditional_and_poll/html/secret_page.xml | 4 ++++ .../problem/choiceprob.xml | 22 +++++++++++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 common/test/data/conditional_and_poll/conditional/condone.xml create mode 100644 common/test/data/conditional_and_poll/html/secret_page.xml create mode 100644 common/test/data/conditional_and_poll/problem/choiceprob.xml diff --git a/common/lib/xmodule/xmodule/tests/test_conditional.py b/common/lib/xmodule/xmodule/tests/test_conditional.py index d4d5a1d2e1..1d63577073 100644 --- a/common/lib/xmodule/xmodule/tests/test_conditional.py +++ b/common/lib/xmodule/xmodule/tests/test_conditional.py @@ -70,7 +70,7 @@ class ConditionalModuleTest(unittest.TestCase): """Make sure that conditional module works""" print "Starting import" - course = self.get_course('conditional') + course = self.get_course('conditional_and_poll') print "Course: ", course print "id: ", course.id @@ -82,7 +82,9 @@ class ConditionalModuleTest(unittest.TestCase): location = descriptor.location return descriptor.xmodule(test_system) - location = Location(["i4x", "edX", "cond_test", "conditional", "condone"]) + # edx - HarvardX + # cond_test - ER22x + location = Location(["i4x", "HarvardX", "ER22x", "conditional", "condone"]) def replace_urls(text, staticfiles_prefix=None, replace_prefix='/static/', course_namespace=None): return text @@ -91,14 +93,14 @@ class ConditionalModuleTest(unittest.TestCase): module = inner_get_module(location) print "module: ", module - print "module.condition: ", module.condition + print "module.conditions_map: ", module.conditions_map print "module children: ", module.get_children() print "module display items (children): ", module.get_display_items() html = module.get_html() print "html type: ", type(html) print "html: ", html - html_expect = "{'ajax_url': 'courses/course_id/modx/a_location', 'element_id': 'i4x-edX-cond_test-conditional-condone', 'id': 'i4x://edX/cond_test/conditional/condone'}" + html_expect = "{'ajax_url': 'courses/course_id/modx/a_location', 'element_id': 'i4x-HarvardX-ER22x-conditional-condone', 'id': 'i4x://HarvardX/ER22x/conditional/condone', 'depends': 'i4x-HarvardX-ER22x-problem-choiceprob'}" self.assertEqual(html, html_expect) gdi = module.get_display_items() @@ -106,11 +108,13 @@ class ConditionalModuleTest(unittest.TestCase): ajax = json.loads(module.handle_ajax('', '')) print "ajax: ", ajax - self.assertTrue('ConditionalModule' in ajax['html']) + html = ajax['html'] + self.assertFalse(any(['This is a secret' in item for item in html])) # now change state of the capa problem to make it completed - inner_get_module(Location('i4x://edX/cond_test/problem/choiceprob')).attempts = 1 + inner_get_module(Location('i4x://HarvardX/ER22x/problem/choiceprob')).attempts = 1 ajax = json.loads(module.handle_ajax('', '')) print "post-attempt ajax: ", ajax - self.assertTrue('This is a secret' in ajax['html']) + html = ajax['html'] + self.assertTrue(any(['This is a secret' in item for item in html])) diff --git a/common/test/data/conditional_and_poll/conditional/condone.xml b/common/test/data/conditional_and_poll/conditional/condone.xml new file mode 100644 index 0000000000..80b061e244 --- /dev/null +++ b/common/test/data/conditional_and_poll/conditional/condone.xml @@ -0,0 +1,3 @@ + + + diff --git a/common/test/data/conditional_and_poll/course/2013_Spring.xml b/common/test/data/conditional_and_poll/course/2013_Spring.xml index cb6e7c1217..2eea422a2f 100644 --- a/common/test/data/conditional_and_poll/course/2013_Spring.xml +++ b/common/test/data/conditional_and_poll/course/2013_Spring.xml @@ -2,5 +2,11 @@ Take note of this name exactly, you'll need to use it everywhere. --> + + + + + + diff --git a/common/test/data/conditional_and_poll/html/secret_page.xml b/common/test/data/conditional_and_poll/html/secret_page.xml new file mode 100644 index 0000000000..63be3cfa8d --- /dev/null +++ b/common/test/data/conditional_and_poll/html/secret_page.xml @@ -0,0 +1,4 @@ + +

This is a secret!

+ + diff --git a/common/test/data/conditional_and_poll/problem/choiceprob.xml b/common/test/data/conditional_and_poll/problem/choiceprob.xml new file mode 100644 index 0000000000..fa91954977 --- /dev/null +++ b/common/test/data/conditional_and_poll/problem/choiceprob.xml @@ -0,0 +1,22 @@ + + + +

Consider a hypothetical magnetic field pointing out of your computer screen. Now imagine an electron traveling from right to left in the plane of your screen. A diagram of this situation is show below…

+
+ +

a. The magnitude of the force experienced by the electron is proportional the product of which of the following? (Select all that apply.)

+ + + + +Magnetic field strength… +Electric field strength… +Electric charge of the electron… +Radius of the electron… +Mass of the electron… +Velocity of the electron… + + + + +