#NEWLINE# def test_event_dispatcher( mock_container ) : #NEWLINE# #INDENT# container = mock_container #NEWLINE# container . service_name = 'srcservice' #NEWLINE# service = Mock ( ) #NEWLINE# worker_ctx = WorkerContext ( container , service , DummyProvider ( 'dispatch' ) ) #NEWLINE# event_dispatcher = EventDispatcher ( retry_policy = { #NEWLINE# #INDENT# 'max_retries' : 5 , #NEWLINE# #UNINDENT# } ) . bind ( container , attr_name = 'dispatch' ) #NEWLINE# event_dispatcher . setup ( ) #NEWLINE# service . dispatch = event_dispatcher . get_dependency ( worker_ctx ) #NEWLINE# from mock import ANY #NEWLINE# with patch ( 'nameko.standalone.events.producers' ) as mock_producers : #NEWLINE# #INDENT# with mock_producers [ ANY ] . acquire ( ) as mock_producer : #NEWLINE# #INDENT# service . dispatch ( 'eventtype' , 'msg' ) #NEWLINE# headers = event_dispatcher . get_message_headers ( worker_ctx ) #NEWLINE# #UNINDENT# #UNINDENT# mock_producer . publish . assert_called_once_with ( 'msg' , exchange = ANY , headers = headers , serializer = container . serializer , routing_key = 'eventtype' , retry = True , retry_policy = { #NEWLINE# #INDENT# 'max_retries' : 5 , #NEWLINE# #UNINDENT# } ) #NEWLINE# ( _ , call_kwargs ) = mock_producer . publish . call_args #NEWLINE# exchange = call_kwargs [ 'exchange' ] #NEWLINE# assert ( exchange . name == 'srcservice.events' )