Commit 93fbea44 by Jesse Shapiro Committed by GitHub

Merge pull request #104 from open-craft/haikuginger/enforce-types

Enforcing XBlock variable types
parents c4ff2512 e489e061
...@@ -63,6 +63,7 @@ class DragAndDropBlock( ...@@ -63,6 +63,7 @@ class DragAndDropBlock(
help=_("The title of the drag and drop problem. The title is displayed to learners."), help=_("The title of the drag and drop problem. The title is displayed to learners."),
scope=Scope.settings, scope=Scope.settings,
default=_("Drag and Drop"), default=_("Drag and Drop"),
enforce_type=True,
) )
mode = String( mode = String(
...@@ -78,7 +79,8 @@ class DragAndDropBlock( ...@@ -78,7 +79,8 @@ class DragAndDropBlock(
{"display_name": _("Standard"), "value": Constants.STANDARD_MODE}, {"display_name": _("Standard"), "value": Constants.STANDARD_MODE},
{"display_name": _("Assessment"), "value": Constants.ASSESSMENT_MODE}, {"display_name": _("Assessment"), "value": Constants.ASSESSMENT_MODE},
], ],
default=Constants.STANDARD_MODE default=Constants.STANDARD_MODE,
enforce_type=True,
) )
max_attempts = Integer( max_attempts = Integer(
...@@ -89,6 +91,7 @@ class DragAndDropBlock( ...@@ -89,6 +91,7 @@ class DragAndDropBlock(
), ),
scope=Scope.settings, scope=Scope.settings,
default=None, default=None,
enforce_type=True,
) )
show_title = Boolean( show_title = Boolean(
...@@ -96,6 +99,7 @@ class DragAndDropBlock( ...@@ -96,6 +99,7 @@ class DragAndDropBlock(
help=_("Display the title to the learner?"), help=_("Display the title to the learner?"),
scope=Scope.settings, scope=Scope.settings,
default=True, default=True,
enforce_type=True,
) )
question_text = String( question_text = String(
...@@ -103,6 +107,7 @@ class DragAndDropBlock( ...@@ -103,6 +107,7 @@ class DragAndDropBlock(
help=_("The description of the problem or instructions shown to the learner."), help=_("The description of the problem or instructions shown to the learner."),
scope=Scope.settings, scope=Scope.settings,
default="", default="",
enforce_type=True,
) )
show_question_header = Boolean( show_question_header = Boolean(
...@@ -110,6 +115,7 @@ class DragAndDropBlock( ...@@ -110,6 +115,7 @@ class DragAndDropBlock(
help=_('Display the heading "Problem" above the problem text?'), help=_('Display the heading "Problem" above the problem text?'),
scope=Scope.settings, scope=Scope.settings,
default=True, default=True,
enforce_type=True,
) )
weight = Float( weight = Float(
...@@ -117,6 +123,7 @@ class DragAndDropBlock( ...@@ -117,6 +123,7 @@ class DragAndDropBlock(
help=_("Defines the number of points the problem is worth."), help=_("Defines the number of points the problem is worth."),
scope=Scope.settings, scope=Scope.settings,
default=1, default=1,
enforce_type=True,
) )
item_background_color = String( item_background_color = String(
...@@ -124,6 +131,7 @@ class DragAndDropBlock( ...@@ -124,6 +131,7 @@ class DragAndDropBlock(
help=_("The background color of draggable items in the problem (example: 'blue' or '#0000ff')."), help=_("The background color of draggable items in the problem (example: 'blue' or '#0000ff')."),
scope=Scope.settings, scope=Scope.settings,
default="", default="",
enforce_type=True,
) )
item_text_color = String( item_text_color = String(
...@@ -131,13 +139,15 @@ class DragAndDropBlock( ...@@ -131,13 +139,15 @@ class DragAndDropBlock(
help=_("Text color to use for draggable items (example: 'white' or '#ffffff')."), help=_("Text color to use for draggable items (example: 'white' or '#ffffff')."),
scope=Scope.settings, scope=Scope.settings,
default="", default="",
enforce_type=True,
) )
max_items_per_zone = Integer( max_items_per_zone = Integer(
display_name=_("Maximum items per zone"), display_name=_("Maximum items per zone"),
help=_("This setting limits the number of items that can be dropped into a single zone."), help=_("This setting limits the number of items that can be dropped into a single zone."),
scope=Scope.settings, scope=Scope.settings,
default=None default=None,
enforce_type=True,
) )
data = Dict( data = Dict(
...@@ -149,24 +159,28 @@ class DragAndDropBlock( ...@@ -149,24 +159,28 @@ class DragAndDropBlock(
), ),
scope=Scope.content, scope=Scope.content,
default=DEFAULT_DATA, default=DEFAULT_DATA,
enforce_type=True,
) )
item_state = Dict( item_state = Dict(
help=_("Information about current positions of items that a learner has dropped on the target image."), help=_("Information about current positions of items that a learner has dropped on the target image."),
scope=Scope.user_state, scope=Scope.user_state,
default={}, default={},
enforce_type=True,
) )
attempts = Integer( attempts = Integer(
help=_("Number of attempts learner used"), help=_("Number of attempts learner used"),
scope=Scope.user_state, scope=Scope.user_state,
default=0 default=0,
enforce_type=True,
) )
completed = Boolean( completed = Boolean(
help=_("Indicates whether a learner has completed the problem at least once"), help=_("Indicates whether a learner has completed the problem at least once"),
scope=Scope.user_state, scope=Scope.user_state,
default=False, default=False,
enforce_type=True,
) )
grade = Float( grade = Float(
...@@ -178,7 +192,8 @@ class DragAndDropBlock( ...@@ -178,7 +192,8 @@ class DragAndDropBlock(
raw_earned = Float( raw_earned = Float(
help=_("Keeps maximum score achieved by student as a raw value between 0 and 1."), help=_("Keeps maximum score achieved by student as a raw value between 0 and 1."),
scope=Scope.user_state, scope=Scope.user_state,
default=0 default=0,
enforce_type=True,
) )
block_settings_key = 'drag-and-drop-v2' block_settings_key = 'drag-and-drop-v2'
......
...@@ -3,6 +3,7 @@ reports=no ...@@ -3,6 +3,7 @@ reports=no
[FORMAT] [FORMAT]
max-line-length=120 max-line-length=120
max-module-lines=1500
[MESSAGES CONTROL] [MESSAGES CONTROL]
disable= disable=
......
...@@ -236,6 +236,17 @@ class BasicTests(TestCaseMixin, unittest.TestCase): ...@@ -236,6 +236,17 @@ class BasicTests(TestCaseMixin, unittest.TestCase):
self.assertIsNone(self.block.max_items_per_zone) self.assertIsNone(self.block.max_items_per_zone)
def test_studio_submit_coerce_to_integer(self):
# Validate that numbers submitted as strings are being
# coerced to integers rather than being saved as strings
def modify_submission(submission):
submission['max_attempts'] = '1234567890'
body = self._make_submission(modify_submission)
self.call_handler('studio_submit', body)
self.assertEqual(self.block.max_attempts, 1234567890)
self.assertEqual(type(self.block.max_attempts), int)
def test_expand_static_url(self): def test_expand_static_url(self):
""" Test the expand_static_url handler needed in Studio when changing the image """ """ Test the expand_static_url handler needed in Studio when changing the image """
res = self.call_handler('expand_static_url', '/static/blah.png') res = self.call_handler('expand_static_url', '/static/blah.png')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment