Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/workbench.*
/dist
/templates
/var
*.iml
.idea/*
dump.rdb
problem_builder.tests.*
18 changes: 17 additions & 1 deletion problem_builder/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kelketek Now that this method does more than simply returns a static list, do you think it would make sense to add a unit test for it? I'm not sure how easy it is, but I'm guessing you could fake the modules that contain VideoDescriptor and ImageModal in tests.


@property
def has_question(self):
Expand Down
35 changes: 34 additions & 1 deletion problem_builder/tests/unit/test_step.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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'
]
)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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 .
6 changes: 6 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", )

Expand Down