File: test_GELFRabbitHandler.py

package info (click to toggle)
graypy 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 312 kB
  • sloc: python: 1,175; sh: 114; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,243 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""pytests for :class:`graypy.rabbitmq.GELFRabbitHandler`"""

import json

import pytest

from graypy.rabbitmq import GELFRabbitHandler
from graypy.handler import SYSLOG_LEVELS

from tests.unit.helper import MOCK_LOG_RECORD


def test_invalid_url():
    """Test constructing :class:`graypy.rabbitmq.GELFRabbitHandler` with
    an invalid rabbitmq url"""
    with pytest.raises(ValueError):
        GELFRabbitHandler("BADURL")


def test_valid_url():
    """Test constructing :class:`graypy.rabbitmq.GELFRabbitHandler` with
    a valid rabbitmq url"""
    handler = GELFRabbitHandler("amqp://localhost")
    assert handler
    assert "amqp://localhost" == handler.url


@pytest.mark.xfail(reason="rabbitmq service is not up")
def test_socket_creation_failure():
    """Test attempting to open a socket to a rabbitmq instance when no such
    service exists"""
    handler = GELFRabbitHandler("amqp://localhost")
    handler.makeSocket()


def test_make_pickle():
    handler = GELFRabbitHandler("amqp://localhost")
    pickle = json.loads(handler.makePickle(MOCK_LOG_RECORD))
    assert "Log message" == pickle["short_message"]
    assert SYSLOG_LEVELS[MOCK_LOG_RECORD.levelno] == pickle["level"]