diff --git a/.gitignore b/.gitignore index 3bd816cc..3737045f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ /workbench.* /dist /templates +/var *.iml .idea/* +dump.rdb problem_builder.tests.* diff --git a/problem_builder/step.py b/problem_builder/step.py index 43a351b3..e04ee057 100644 --- a/problem_builder/step.py +++ b/problem_builder/step.py @@ -127,11 +127,27 @@ def allowed_nested_blocks(self): NestedXBlockSpec allows explicitly setting disabled/enabled state, disabled reason (if any) and single/multiple instances """ + additional_blocks = [] + try: + from xmodule.video_module.video_module import VideoDescriptor + additional_blocks.append(NestedXBlockSpec( + VideoDescriptor, category='video', label=_(u"Video") + )) + except ImportError: + pass + try: + from imagemodal import ImageModal + additional_blocks.append(NestedXBlockSpec( + ImageModal, category='imagemodal', label=_(u"Image Modal") + )) + except ImportError: + pass + return [ NestedXBlockSpec(AnswerBlock, boilerplate='studio_default'), MCQBlock, RatingBlock, MRQBlock, HtmlBlockShim, AnswerRecapBlock, MentoringTableBlock, - ] + ] + additional_blocks @property def has_question(self): diff --git a/problem_builder/tests/unit/test_step.py b/problem_builder/tests/unit/test_step.py index e22df630..425f82f9 100644 --- a/problem_builder/tests/unit/test_step.py +++ b/problem_builder/tests/unit/test_step.py @@ -1,7 +1,9 @@ import unittest +from xblock.field_data import DictFieldData +from problem_builder.step import MentoringStepBlock from problem_builder.mixins import QuestionMixin, StepParentMixin -from mock import Mock +from mock import Mock, patch class Parent(StepParentMixin): @@ -92,3 +94,34 @@ def test_lonely_child_is_true_if_parent_have_more_steps(self): self.assertFalse(step1.lonely_child) self.assertFalse(step2.lonely_child) + + +class TestMentoringStep(unittest.TestCase): + + def get_allowed_blocks(self, block): + return [ + getattr(allowed_block, 'category', getattr(allowed_block, 'CATEGORY', None)) + for allowed_block in block.allowed_nested_blocks + ] + + def test_allowed_nested_blocks(self): + block = MentoringStepBlock(Mock(), DictFieldData({}), Mock()) + self.assertEqual( + self.get_allowed_blocks(block), + ['pb-answer', 'pb-mcq', 'pb-rating', 'pb-mrq', 'html', 'pb-answer-recap', 'pb-table'] + ) + from sys import modules + xmodule_mock = Mock() + fake_modules = { + 'xmodule': xmodule_mock, + 'xmodule.video_module': xmodule_mock.video_module, + 'xmodule.video_module.video_module': xmodule_mock.video_module.video_module, + 'imagemodal': Mock() + } + with patch.dict(modules, fake_modules): + self.assertEqual( + self.get_allowed_blocks(block), [ + 'pb-answer', 'pb-mcq', 'pb-rating', 'pb-mrq', 'html', 'pb-answer-recap', + 'pb-table', 'video', 'imagemodal' + ] + ) diff --git a/requirements.txt b/requirements.txt index 977de8f5..ce2cb574 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ddt mock unicodecsv==0.9.4 --e git+https://github.com/edx/xblock-utils.git@588f7fd3ee88847c57cf09d10e81caa6b267ec51#egg=xblock-utils +-e git+https://github.com/edx/xblock-utils.git@b4f9b51146c7fafa12f41d54af752b8f1516dffd#egg=xblock-utils -e . diff --git a/run_tests.py b/run_tests.py index 919fd2dd..d34ddff9 100755 --- a/run_tests.py +++ b/run_tests.py @@ -24,6 +24,12 @@ # Configure a range of ports in case the default port of 8081 is in use os.environ.setdefault("DJANGO_LIVE_TEST_SERVER_ADDRESS", "localhost:8081-8099") + try: + os.mkdir('var') + except OSError: + # May already exist. + pass + from django.conf import settings settings.INSTALLED_APPS += ("problem_builder", )