-
Notifications
You must be signed in to change notification settings - Fork 91
/
helper.py
80 lines (68 loc) · 2.36 KB
/
helper.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""helper functions for testing graypy
These functions are used for both the integration and unit testing.
"""
import logging
import pytest
from graypy import GELFUDPHandler, GELFTCPHandler, GELFTLSHandler, GELFHTTPHandler
TEST_CERT = "tests/config/localhost.cert.pem"
KEY_PASS = "secret"
TEST_TCP_PORT = 12201
TEST_UDP_PORT = 12202
TEST_HTTP_PORT = 12203
TEST_TLS_PORT = 12204
@pytest.fixture(
params=[
GELFTCPHandler("127.0.0.1", TEST_TCP_PORT),
GELFTCPHandler("127.0.0.1", TEST_TCP_PORT, extra_fields=True),
GELFTCPHandler(
"127.0.0.1", TEST_TCP_PORT, extra_fields=True, debugging_fields=True
),
GELFTLSHandler("localhost", TEST_TLS_PORT),
GELFTLSHandler("localhost", TEST_TLS_PORT, validate=True, ca_certs=TEST_CERT),
GELFTLSHandler("127.0.0.1", TEST_TLS_PORT),
GELFTLSHandler("127.0.0.1", TEST_TLS_PORT, validate=True, ca_certs=TEST_CERT),
GELFHTTPHandler("127.0.0.1", TEST_HTTP_PORT),
GELFHTTPHandler("127.0.0.1", TEST_HTTP_PORT, compress=False),
GELFUDPHandler("127.0.0.1", TEST_UDP_PORT),
GELFUDPHandler("127.0.0.1", TEST_UDP_PORT, compress=False),
# the below handler tests are essentially smoke tests
# that help cover the argument permutations of BaseGELFHandler
GELFUDPHandler(
"127.0.0.1",
TEST_UDP_PORT,
debugging_fields=True,
extra_fields=True,
localname="foobar_localname",
facility="foobar_facility",
level_names=True,
compress=False,
),
GELFUDPHandler(
"127.0.0.1",
TEST_UDP_PORT,
debugging_fields=True,
extra_fields=True,
fqdn=True,
facility="foobar_facility",
level_names=True,
compress=False,
),
]
)
def handler(request):
return request.param
@pytest.fixture
def logger(handler):
logger_ = logging.getLogger("test_logger")
logger_.addHandler(handler)
yield logger_
logger_.removeHandler(handler)
@pytest.fixture
def formatted_logger(handler):
logger_ = logging.getLogger("formatted_test_logger")
handler.setFormatter(logging.Formatter("%(levelname)s : %(message)s"))
logger_.addHandler(handler)
yield logger_
logger_.removeHandler(handler)