コード例 #1
0
def test_input_google_pubsub_stop():
    with patch("comet_common.comet_input_google_pubsub.pubsub.SubscriberClient"
               ) as mockpubsub:
        mockpubsub().subscribe.return_value = None
        message_callback = Mock(return_value=False)
        pubsubinput = PubSubInput(message_callback=message_callback,
                                  subscription_name="something")
        pubsubinput.consumer = Mock()

        pubsubinput.stop()

        pubsubinput.consumer.cancel.assert_called_once()
コード例 #2
0
def test_input_google_pubsub_invalid_message_drop():
    with patch("comet_common.comet_input_google_pubsub.pubsub.SubscriberClient"
               ) as mockpubsub:
        mockpubsub().subscribe.return_value = None
        message_callback = Mock()
        message_callback.side_effect = CometAlertException("moo", drop=True)
        pubsubinput = PubSubInput(message_callback=message_callback,
                                  subscription_name="something")
        message = Mock()
        message.attributes.get.return_value = "test_type"
        message.data.decode.return_value = {"subtype": ""}

        pubsubinput.callback(message)

        message.ack.assert_called_once()
コード例 #3
0
def test_input_google_pubsub_nocallback():
    """PubSubInput"""
    with patch("comet_common.comet_input_google_pubsub.pubsub.SubscriberClient"
               ) as mockpubsub:
        mockpubsub().subscribe.return_value = None
        message_callback = Mock(return_value=False)
        pubsubinput = PubSubInput(message_callback=message_callback,
                                  subscription_name="something")
        message = Mock()
        message.attributes.get.return_value = "test_type"
        message.data.decode.side_effect = "{}"

        pubsubinput.callback(message)

        message.nack.assert_called_once()
コード例 #4
0
def test_input_google_pubsub_passingok():
    """PubSubInput"""
    with patch("comet_common.comet_input_google_pubsub.pubsub.SubscriberClient"
               ) as mockpubsub:
        mockpubsub().subscribe.return_value = None
        message_callback = Mock(return_value=True)
        pubsubinput = PubSubInput(message_callback=message_callback,
                                  subscription_name="something")
        message = Mock()
        message.attributes.get.return_value = 'test_type'
        message.data.decode.return_value = '{}'

        pubsubinput.callback(message)

        message.ack.assert_called_once()
        message_callback.assert_called_once()
コード例 #5
0
def test_input_google_pubsub_failingtodecode():
    """PubSubInput"""
    with patch("comet_common.comet_input_google_pubsub.pubsub.SubscriberClient"
               ) as mockpubsub:
        mockpubsub().subscribe.return_value = None

        message_callback = Mock(return_value=False)
        pubsubinput = PubSubInput(message_callback=message_callback,
                                  subscription_name="something")
        message = Mock()
        message.attributes.get.return_value = "test_type"
        message.data.decode.side_effect = Exception("Mock Exception")

        with pytest.raises(Exception) as excinfo:
            pubsubinput.callback(message)

        assert excinfo.value.args[0] == "Mock Exception"
        message.nack.assert_called_once()