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)
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)
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)
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)
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)
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
def _call_plugin(function, arg): ctx = plugin.Context() ctx.input = arg ctx.function = function Plugin().call_function(ctx) return ctx.output
def setUp(self): super(Tests, self).setUp() self.ctx = plugin.Context()
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