Exemple #1
0
 def test_close_context(self):
     handler = ContextHandler()
     handler.bind(SimpleWidget)
     widget = SimpleWidget()
     widget.storeSpecificSettings = Mock()
     handler.initialize(widget)
     widget.schema_only_setting = 0xD06F00D
     widget.current_context = handler.new_context()
     handler.close_context(widget)
     self.assertEqual(widget.schema_only_setting, 0xD06F00D)
    def test_schema_only_settings(self):
        handler = ContextHandler()
        with override_default_settings(SimpleWidget, handler=ContextHandler):
            handler.bind(SimpleWidget)

        # fast_save should not update defaults
        widget = SimpleWidget()
        handler.initialize(widget)
        context = widget.current_context = handler.new_context()
        widget.context_settings.append(context)
        handler.fast_save(widget, 'schema_only_context_setting', 5)
        self.assertEqual(
            handler.known_settings['schema_only_context_setting'].default, None)
        handler.fast_save(widget, 'component.schema_only_context_setting', 5)
        self.assertEqual(
            handler.known_settings['component.schema_only_context_setting'].default, "only")

        # update_defaults should not update defaults
        widget.schema_only_context_setting = 5
        handler.update_defaults(widget)
        self.assertEqual(
            handler.known_settings['schema_only_context_setting'].default, None)
        widget.component.schema_only_setting = 5
        self.assertEqual(
            handler.known_settings['component.schema_only_context_setting'].default, "only")

        # close_context should pack setting
        widget.schema_only_context_setting = 5
        widget.component.context_setting = 5
        widget.component.schema_only_context_setting = 5
        handler.close_context(widget)
        global_values = handler.global_contexts[0].values
        self.assertTrue('context_setting' in global_values)
        self.assertFalse('schema_only_context_setting' in global_values)
        self.assertTrue('context_setting' in global_values["component"])
        self.assertFalse('schema_only_context_setting' in global_values["component"])