示例#1
0
def test_aggregate_audit_msg(mocker):
    mock_iris_client = mocker.patch('iris.sender.cache.iris_client')
    mock_iris_client.get.return_value.json.return_value = fake_plan
    from iris.bin.sender import (fetch_and_prepare_message, message_queue,
                                 send_queue, plan_aggregate_windows)

    init_queue_with_item(message_queue, fake_message)
    init_queue_with_item(send_queue)

    now = time.time()
    msg_aggregate_key = (fake_message['plan_id'], fake_message['application'],
                         fake_message['priority'], fake_message['target'])
    from collections import defaultdict
    plan_aggregate_windows[msg_aggregate_key] = defaultdict(int)
    plan_aggregate_windows[msg_aggregate_key][now] = 10
    plan_aggregate_windows[msg_aggregate_key][now - 60] = 10

    mocker.patch('iris.bin.sender.cache').plans = {fake_plan['id']: fake_plan}

    mocker.patch('iris.bin.sender.spawn')
    from iris.bin.sender import spawn as mock_spawn

    # run code to test
    fetch_and_prepare_message()

    # examine results
    assert send_queue.qsize() == 0
    from iris.sender import auditlog
    mock_spawn.assert_called_with(
        auditlog.message_change, fake_message['message_id'],
        auditlog.SENT_CHANGE, '', '',
        "Aggregated with key (19546, 'test-app', 'high', 'test-user')")
示例#2
0
def test_aggregate_audit_msg(mocker):
    from iris.bin.sender import (
        fetch_and_prepare_message, message_queue, per_mode_send_queues,
        plan_aggregate_windows
    )

    send_queue = per_mode_send_queues.setdefault('email', gevent.queue.Queue())

    init_queue_with_item(message_queue, fake_message)
    init_queue_with_item(send_queue)

    now = time.time()
    msg_aggregate_key = (
        fake_message['plan_id'],
        fake_message['application'],
        fake_message['priority'],
        fake_message['target'])
    from collections import defaultdict
    plan_aggregate_windows[msg_aggregate_key] = defaultdict(int)
    plan_aggregate_windows[msg_aggregate_key][now] = 10
    plan_aggregate_windows[msg_aggregate_key][now - 60] = 10

    mocker.patch('iris.bin.sender.cache').plans = {fake_plan['id']: fake_plan}

    mocker.patch('iris.bin.sender.spawn')
    from iris.bin.sender import spawn as mock_spawn

    # run code to test
    fetch_and_prepare_message()

    # examine results
    assert send_queue.qsize() == 0
    from iris.sender import auditlog
    mock_spawn.assert_called_with(
        auditlog.message_change,
        fake_message['message_id'],
        auditlog.SENT_CHANGE,
        '',
        '',
        "Aggregated with key (19546, test-app, high, test-user)")