예제 #1
0
 def test_CallOneFollowsChainOfCommandPattern(self):
     container = plugin.Container()
     container.add(CallOneTestPlugin('A', True),
                   CallOneTestPlugin('B', True),
                   CallOneTestPlugin('C', False))
     ctx = plugin.Context()
     container.call_one(ctx, 'read_input', 'input')
     self.assertEqual('B', ctx.input)
예제 #2
0
 def test_CallAllVisitsAllPlugins(self):
     container = plugin.Container()
     container.add(CallAllTestPlugin('A'), CallAllTestPlugin('B'),
                   CallAllTestPlugin('C'))
     ctx = plugin.Context()
     ctx.input = 'START'
     container.call_all(ctx, 'normalize_input')
     self.assertEqual('START|A|B|C', ctx.input)
예제 #3
0
 def test_HookMethodsInPluginsCanBeRun(self):
     container = plugin.Container()
     container.add(Dummy())
     config = MicronMethodConfig(dommy='yo')
     ctx = plugin.Context()
     ctx.config = config
     container.call_all(ctx, 'process_output')
     self.assertEqual('I made it, yo', ctx.output)
예제 #4
0
 def test_PluginsCanBeDuckTyped(self):
     container = plugin.Container()
     container.add(Ducky())
     config = MicronMethodConfig()
     ctx = plugin.Context()
     ctx.config = config
     container.call_all(ctx, 'normalize_input')
     container.call_all(ctx, 'process_output')
     self.assertEqual('Quack!', ctx.output)
예제 #5
0
 def test_callOneAcceptsSettingMonitorFieldToNoneValue(self):
     container = plugin.Container()
     container.add(CallOneTestPlugin('A', True),
                   CallOneTestPlugin('B', True),
                   CallOneTestPlugin(None, True))
     ctx = plugin.Context()
     self.assertFalse(ctx.is_assigned('input'))
     container.call_one(ctx, 'read_input', 'input')
     self.assertTrue(ctx.is_assigned('input'))
     self.assertEqual(None, ctx.input)
예제 #6
0
    def __call__(self):
        """Executes the MicronMethod.

        This method implements the very core of Micron request handling.
        Micron lets Flask take care of web server interaction, routing,
        context setup, etc. Flask will eventually call this method to
        render the route. That is when the Micron-specific request
        handling kicks in.

        :returns:
            The Flask Response object to return to the client.
        """
        self._enable_cookies_for_js_clients()
        ctx = plugin.Context()
        ctx.config = self.config.flattened
        ctx.function = self.function
        try:
            self.plugins.call_all(ctx, 'start_request')
            self.plugins.call_all(ctx, 'check_access')
            self.plugins.call_all(ctx, 'after_check_access')
            self.plugins.call_one(ctx, 'read_input', 'input')
            self.plugins.call_all(ctx, 'normalize_input')
            self.plugins.call_all(ctx, 'validate_input')
            self.plugins.call_one(ctx, 'call_function', 'output')
            self.plugins.call_all(ctx, 'process_output')
            self.plugins.call_one(ctx, 'create_response', 'response')
            self.plugins.call_all(ctx, 'process_response')
            self.plugins.call_all(ctx, 'end_request')
        except MicronError:
            (_, error, traceback_) = sys.exc_info()
            self._handle_error(ctx, error, traceback_)
        except Exception:
            (_, error, traceback_) = sys.exc_info()
            self._handle_error(ctx, UnhandledException(error), traceback_)

        return ctx.response
예제 #7
0
def _call_plugin(function, arg):
    ctx = plugin.Context()
    ctx.input = arg
    ctx.function = function
    Plugin().call_function(ctx)
    return ctx.output
예제 #8
0
 def setUp(self):
     super(Tests, self).setUp()
     self.ctx = plugin.Context()
예제 #9
0
 def _call_plugin(self, output, error):
     ctx = plugin.Context()
     ctx.output = output
     ctx.error = error
     json_output.Plugin().create_response(ctx)
     return ctx.response.data