def test_on_start__no_errors(): def data_handler1(context): return "data1" def data_handler2(context): return "data2" scheduled_topic = ScheduledTopic(topic_name='s_topic', data_handler=data_handler1, interval_in_sec=5) topic = Topic(topic_name='topic', data_handler=data_handler2) handler = PublisherBrokerHandler(mock.Mock()) sender = mock.Mock() handler._create_sender = mock.Mock(return_value=sender) mock_init_scheduled_topic = Mock() handler._init_scheduled_topic = mock_init_scheduled_topic handler.add_topic(topic) handler.add_topic(scheduled_topic) event = mock.Mock() with mock.patch.object(BrokerHandler, 'on_start'): handler.on_start(event) assert sender == handler._sender mock_init_scheduled_topic.assert_called_once_with(scheduled_topic)
def test_on_start__create_sender_error__logs_error_and_returns(caplog): caplog.set_level(logging.DEBUG) handler = PublisherBrokerHandler(mock.Mock()) handler._create_sender = mock.Mock( side_effect=BrokerHandlerError('proton error')) handler._schedule_topic_group = mock.Mock() event = mock.Mock() with mock.patch.object(BrokerHandler, 'on_start'): handler.on_start(event) log_message = caplog.records[0] assert 'Error while creating sender: proton error' == log_message.message handler._schedule_topic_group.assert_not_called()