Commit 22675a3f by Sven Marnach

Move register_temp_plugin decorator from setUp() to individual test methods.

The tests will fail otherwise with the latest version of XBlock.
parent 99ccc45e
...@@ -29,12 +29,12 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -29,12 +29,12 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
""" """
Test the Studio View created for EditableXBlock Test the Studio View created for EditableXBlock
""" """
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def setUp(self): def set_up_root_block(self):
super(TestEditableXBlock_StudioView, self).setUp()
self.set_scenario_xml('<editable />') self.set_scenario_xml('<editable />')
self.go_to_view("studio_view") self.go_to_view("studio_view")
self.fix_js_environment() self.fix_js_environment()
return self.load_root_xblock()
def assert_unchanged(self, block, orig_field_values=None, explicitly_set=False): def assert_unchanged(self, block, orig_field_values=None, explicitly_set=False):
""" """
...@@ -48,21 +48,23 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -48,21 +48,23 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
self.assertEqual(getattr(block, field_name), expected_value) self.assertEqual(getattr(block, field_name), expected_value)
self.assertEqual(block.fields[field_name].is_set_on(block), explicitly_set) self.assertEqual(block.fields[field_name].is_set_on(block), explicitly_set)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_no_changes_with_defaults(self): def test_no_changes_with_defaults(self):
""" """
If we load the edit form and then save right away, there should be no changes. If we load the edit form and then save right away, there should be no changes.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
orig_values = {field_name: getattr(block, field_name) for field_name in EditableXBlock.editable_fields} orig_values = {field_name: getattr(block, field_name) for field_name in EditableXBlock.editable_fields}
self.click_save() self.click_save()
self.assert_unchanged(block, orig_values) self.assert_unchanged(block, orig_values)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_no_changes_with_values_set(self): def test_no_changes_with_values_set(self):
""" """
If the XBlock already has explicit values set, and we load the edit form and then save If the XBlock already has explicit values set, and we load the edit form and then save
right away, there should be no changes. right away, there should be no changes.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
block.color = "green" block.color = "green"
block.count = 5 block.count = 5
block.comment = "Hello" block.comment = "Hello"
...@@ -76,12 +78,13 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -76,12 +78,13 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
block = self.load_root_xblock() # Need to reload the block to bypass its cache block = self.load_root_xblock() # Need to reload the block to bypass its cache
self.assert_unchanged(block, orig_values, explicitly_set=True) self.assert_unchanged(block, orig_values, explicitly_set=True)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_explicit_overrides(self): def test_explicit_overrides(self):
""" """
Test that we can override the defaults with the same value as the default, and that the Test that we can override the defaults with the same value as the default, and that the
value will be saved explicitly. value will be saved explicitly.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
self.assert_unchanged(block) self.assert_unchanged(block)
field_names = EditableXBlock.editable_fields field_names = EditableXBlock.editable_fields
...@@ -99,11 +102,12 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -99,11 +102,12 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
self.click_save() self.click_save()
self.assert_unchanged(block, explicitly_set=True) self.assert_unchanged(block, explicitly_set=True)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_set_and_reset(self): def test_set_and_reset(self):
""" """
Test that we can set values, save, then reset to defaults. Test that we can set values, save, then reset to defaults.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
self.assert_unchanged(block) self.assert_unchanged(block)
for field_name in EditableXBlock.editable_fields: for field_name in EditableXBlock.editable_fields:
...@@ -126,6 +130,7 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -126,6 +130,7 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
block = self.load_root_xblock() # Need to reload the block to bypass its cache block = self.load_root_xblock() # Need to reload the block to bypass its cache
self.assert_unchanged(block) self.assert_unchanged(block)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_invalid_data(self): def test_invalid_data(self):
""" """
Test that we get notified when there's a problem with our data. Test that we get notified when there's a problem with our data.
...@@ -136,6 +141,8 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest): ...@@ -136,6 +141,8 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
self.assertEqual(notification[1]["title"], "Unable to update settings") self.assertEqual(notification[1]["title"], "Unable to update settings")
self.assertEqual(notification[1]["message"], expected_message) self.assertEqual(notification[1]["message"], expected_message)
block = self.set_up_root_block()
color_control = self.get_element_for_field('color') color_control = self.get_element_for_field('color')
color_control.clear() color_control.clear()
color_control.send_keys('orange') color_control.send_keys('orange')
...@@ -210,7 +217,7 @@ class FancyXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -210,7 +217,7 @@ class FancyXBlock(StudioEditableXBlockMixin, XBlock):
list_values_provider=fancy_list_values_provider_b, list_values_provider=fancy_list_values_provider_b,
default=["alex"], default=["alex"],
) )
string_normal = String(display_name="Normal String Field") string_normal = String(display_name="Normal String Field")
string_values = String(display_name="String Field With Values", default="A", values=("A", "B", "C", "D")) string_values = String(display_name="String Field With Values", default="A", values=("A", "B", "C", "D"))
string_values_provider = String( string_values_provider = String(
...@@ -248,30 +255,32 @@ class TestFancyXBlock_StudioView(StudioEditableBaseTest): ...@@ -248,30 +255,32 @@ class TestFancyXBlock_StudioView(StudioEditableBaseTest):
""" """
Test the Studio View created for FancyXBlock Test the Studio View created for FancyXBlock
""" """
@XBlock.register_temp_plugin(FancyXBlock, "fancy")
def setUp(self): def set_up_root_block(self):
super(TestFancyXBlock_StudioView, self).setUp() self.set_scenario_xml('<fancy />')
self.set_scenario_xml("<fancy/>")
self.go_to_view("studio_view") self.go_to_view("studio_view")
self.fix_js_environment() self.fix_js_environment()
return self.load_root_xblock()
@XBlock.register_temp_plugin(FancyXBlock, "fancy")
def test_no_changes_with_defaults(self): def test_no_changes_with_defaults(self):
""" """
If we load the edit form and then save right away, there should be no changes. If we load the edit form and then save right away, there should be no changes.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
orig_values = {field_name: getattr(block, field_name) for field_name in FancyXBlock.editable_fields} orig_values = {field_name: getattr(block, field_name) for field_name in FancyXBlock.editable_fields}
self.click_save() self.click_save()
for field_name in FancyXBlock.editable_fields: for field_name in FancyXBlock.editable_fields:
self.assertEqual(getattr(block, field_name), orig_values[field_name]) self.assertEqual(getattr(block, field_name), orig_values[field_name])
self.assertFalse(block.fields[field_name].is_set_on(block)) self.assertFalse(block.fields[field_name].is_set_on(block))
@XBlock.register_temp_plugin(FancyXBlock, "fancy")
def test_no_changes_with_values_set(self): def test_no_changes_with_values_set(self):
""" """
If the XBlock already has explicit values set, and we load the edit form and then save If the XBlock already has explicit values set, and we load the edit form and then save
right away, there should be no changes. right away, there should be no changes.
""" """
block = self.load_root_xblock() block = self.set_up_root_block()
block.bool_normal = True block.bool_normal = True
block.dict_normal = {"more": "cowbell"} block.dict_normal = {"more": "cowbell"}
block.float_normal = 17.0 block.float_normal = 17.0
......
...@@ -31,18 +31,16 @@ class TestChildIsInstance(unittest.TestCase): ...@@ -31,18 +31,16 @@ class TestChildIsInstance(unittest.TestCase):
""" """
Test child_isinstance helper method, in the workbench runtime. Test child_isinstance helper method, in the workbench runtime.
""" """
@XBlock.register_temp_plugin(GoldenRetrieverXBlock, "gr") @XBlock.register_temp_plugin(GoldenRetrieverXBlock, "gr")
@XBlock.register_temp_plugin(CatXBlock, "cat") @XBlock.register_temp_plugin(CatXBlock, "cat")
@XBlock.register_temp_plugin(BasicXBlock, "block") @XBlock.register_temp_plugin(BasicXBlock, "block")
def setUp(self):
super(TestChildIsInstance, self).setUp()
self.runtime = WorkbenchRuntime()
self.root_id = self.runtime.parse_xml_string('<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
def test_child_isinstance(self): def test_child_isinstance(self):
""" """
Check that child_isinstance() works on direct children Check that child_isinstance() works on direct children
""" """
self.runtime = WorkbenchRuntime()
self.root_id = self.runtime.parse_xml_string('<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
root = self.runtime.get_block(self.root_id) root = self.runtime.get_block(self.root_id)
self.assertFalse(child_isinstance(root, root.children[0], DogXBlock)) self.assertFalse(child_isinstance(root, root.children[0], DogXBlock))
self.assertFalse(child_isinstance(root, root.children[0], GoldenRetrieverXBlock)) self.assertFalse(child_isinstance(root, root.children[0], GoldenRetrieverXBlock))
...@@ -56,10 +54,15 @@ class TestChildIsInstance(unittest.TestCase): ...@@ -56,10 +54,15 @@ class TestChildIsInstance(unittest.TestCase):
self.assertTrue(child_isinstance(root, root.children[2], DogXBlock)) self.assertTrue(child_isinstance(root, root.children[2], DogXBlock))
self.assertTrue(child_isinstance(root, root.children[2], GoldenRetrieverXBlock)) self.assertTrue(child_isinstance(root, root.children[2], GoldenRetrieverXBlock))
@XBlock.register_temp_plugin(GoldenRetrieverXBlock, "gr")
@XBlock.register_temp_plugin(CatXBlock, "cat")
@XBlock.register_temp_plugin(BasicXBlock, "block")
def test_child_isinstance_descendants(self): def test_child_isinstance_descendants(self):
""" """
Check that child_isinstance() works on deeper descendants Check that child_isinstance() works on deeper descendants
""" """
self.runtime = WorkbenchRuntime()
self.root_id = self.runtime.parse_xml_string('<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
root = self.runtime.get_block(self.root_id) root = self.runtime.get_block(self.root_id)
block = root.runtime.get_block(root.children[0]) block = root.runtime.get_block(root.children[0])
self.assertIsInstance(block, BasicXBlock) self.assertIsInstance(block, BasicXBlock)
......
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