How to use _create_dispatcher method in autotest

Best Python code snippet using autotest_python

test_main.py

Source:test_main.py Github

copy

Full Screen

...51 assert_is_instance(self.processor.config, dict)52 @patch('streamalert.alert_processor.main.LOGGER')53 def test_create_dispatcher_invalid(self, mock_logger):54 """Alert Processor - Create Dispatcher - Invalid Output"""55 assert_is_none(self.processor._create_dispatcher('helloworld'))56 mock_logger.error.called_once_with(ANY, 'helloworld')57 @patch('streamalert.alert_processor.main.LOGGER')58 def test_create_dispatcher_output_doesnt_exist(self, mock_logger):59 """Alert Processor - Create Dispatcher - Output Does Not Exist"""60 assert_is_none(self.processor._create_dispatcher('slack:no-such-channel'))61 mock_logger.error.called_once_with(62 'The output \'%s\' does not exist!', 'slack:no-such-channel')63 @patch.dict(os.environ, MOCK_ENV)64 def test_create_dispatcher(self):65 """Alert Processor - Create Dispatcher - Success"""66 dispatcher = self.processor._create_dispatcher('aws-s3:unit_test_bucket')67 assert_is_instance(dispatcher, OutputDispatcher)68 @patch.object(AlertProcessor, '_create_dispatcher')69 def test_send_alerts_success(self, mock_create_dispatcher):70 """Alert Processor - Send Alerts Success"""71 mock_create_dispatcher.return_value.dispatch.return_value = True72 result = self.processor._send_to_outputs(self.alert)73 mock_create_dispatcher.assert_called_once()74 mock_create_dispatcher.return_value.dispatch.assert_called_once()75 assert_equal({'slack:unit-test-channel': True}, result)76 assert_equal(self.alert.outputs, self.alert.outputs_sent)77 @patch.object(AlertProcessor, '_create_dispatcher')78 def test_send_alerts_failure(self, mock_create_dispatcher):79 """Alert Processor - Send Alerts Failure"""80 mock_create_dispatcher.return_value.dispatch.return_value = False...

Full Screen

Full Screen

test_executor.py

Source:test_executor.py Github

copy

Full Screen

...64 thread = threading.Thread(target=target, args=(executor,))65 thread.daemon = True66 thread.start()67 return thread68 def _create_dispatcher(self):69 if impl_aioeventlet is not None:70 aioeventlet_class = impl_aioeventlet.AsyncioEventletExecutor71 else:72 aioeventlet_class = None73 is_aioeventlet = (self.executor == aioeventlet_class)74 if impl_blocking is not None:75 blocking_class = impl_blocking.BlockingExecutor76 else:77 blocking_class = None78 is_blocking = (self.executor == blocking_class)79 if is_aioeventlet:80 policy = aioeventlet.EventLoopPolicy()81 trollius.set_event_loop_policy(policy)82 self.addCleanup(trollius.set_event_loop_policy, None)83 def run_loop(loop):84 loop.run_forever()85 loop.close()86 trollius.set_event_loop(None)87 def run_executor(executor):88 # create an event loop in the executor thread89 loop = trollius.new_event_loop()90 trollius.set_event_loop(loop)91 eventlet.spawn(run_loop, loop)92 # run the executor93 executor.start()94 executor.wait()95 # stop the event loop: run_loop() will close it96 loop.stop()97 @trollius.coroutine98 def simple_coroutine(value):99 raise trollius.Return(value)100 endpoint = mock.MagicMock(return_value=simple_coroutine('result'))101 event = eventlet.event.Event()102 elif is_blocking:103 def run_executor(executor):104 executor.start()105 executor.execute()106 executor.wait()107 endpoint = mock.MagicMock(return_value='result')108 event = None109 else:110 def run_executor(executor):111 executor.start()112 executor.wait()113 endpoint = mock.MagicMock(return_value='result')114 event = None115 class Dispatcher(dispatcher_base.DispatcherBase):116 def __init__(self, endpoint):117 self.endpoint = endpoint118 self.result = "not set"119 def _listen(self, transport):120 pass121 def callback(self, incoming, executor_callback):122 if executor_callback is None:123 result = self.endpoint(incoming.ctxt,124 incoming.message)125 else:126 result = executor_callback(self.endpoint,127 incoming.ctxt,128 incoming.message)129 if is_aioeventlet:130 event.send()131 self.result = result132 return result133 def __call__(self, incoming, executor_callback=None):134 return dispatcher_base.DispatcherExecutorContext(135 incoming[0], self.callback, executor_callback)136 return Dispatcher(endpoint), endpoint, event, run_executor137 def test_slow_wait(self):138 dispatcher, endpoint, event, run_executor = self._create_dispatcher()139 listener = mock.Mock(spec=['poll', 'stop'])140 executor = self.executor(self.conf, listener, dispatcher)141 incoming_message = mock.MagicMock(ctxt={}, message={'payload': 'data'})142 def fake_poll(timeout=None, prefetch_size=1):143 time.sleep(0.1)144 if listener.poll.call_count == 10:145 if event is not None:146 event.wait()147 executor.stop()148 else:149 return incoming_message150 listener.poll.side_effect = fake_poll151 thread = self._run_in_thread(run_executor, executor)152 self.assertFalse(executor.wait(timeout=0.1))153 thread.join()154 self.assertTrue(executor.wait())155 def test_dead_wait(self):156 dispatcher, _endpoint, _event, _run_executor = self._create_dispatcher()157 listener = mock.Mock(spec=['poll', 'stop'])158 executor = self.executor(self.conf, listener, dispatcher)159 executor.stop()160 self.assertTrue(executor.wait())161 def test_executor_dispatch(self):162 dispatcher, endpoint, event, run_executor = self._create_dispatcher()163 listener = mock.Mock(spec=['poll', 'stop'])164 executor = self.executor(self.conf, listener, dispatcher)165 incoming_message = mock.MagicMock(ctxt={}, message={'payload': 'data'})166 def fake_poll(timeout=None, prefetch_size=1):167 if listener.poll.call_count == 1:168 return [incoming_message]169 if event is not None:170 event.wait()171 executor.stop()172 listener.poll.side_effect = fake_poll173 thread = self._run_in_thread(run_executor, executor)174 thread.join()175 endpoint.assert_called_once_with({}, {'payload': 'data'})176 self.assertEqual(dispatcher.result, 'result')...

Full Screen

Full Screen

headerparserhandler.py

Source:headerparserhandler.py Github

copy

Full Screen

...11# PythonOption to specify the handler scan directory.12# This must be a directory under the root directory.13# The default is the root directory.14_PYOPT_HANDLER_SCAN = 'mod_pywebsocket.handler_scan'15def _create_dispatcher():16 _HANDLER_ROOT = apache.main_server.get_options().get(17 _PYOPT_HANDLER_ROOT, None)18 if not _HANDLER_ROOT:19 raise Exception('PythonOption %s is not defined' % _PYOPT_HANDLER_ROOT,20 apache.APLOG_ERR)21 _HANDLER_SCAN = apache.main_server.get_options().get(22 _PYOPT_HANDLER_SCAN, _HANDLER_ROOT)23 dispatcher = dispatch.Dispatcher(_HANDLER_ROOT, _HANDLER_SCAN)24 for warning in dispatcher.source_warnings():25 apache.log_error('mod_pywebsocket: %s' % warning, apache.APLOG_WARNING)26 return dispatcher27# Initialize28_dispatcher = _create_dispatcher()29def headerparserhandler(request):30 """Handle request.31 Args:32 request: mod_python request.33 This function is named headerparserhandler because it is the default name34 for a PythonHeaderParserHandler.35 """36 try:37 handshaker = handshake.Handshaker(request, _dispatcher)38 handshaker.do_handshake()39 request.log_error('mod_pywebsocket: resource: %r' % request.ws_resource,40 apache.APLOG_DEBUG)41 _dispatcher.transfer_data(request)42 except handshake.HandshakeError, e:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful