-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pflog.py
56 lines (46 loc) · 1.94 KB
/
test_pflog.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
from pathlib import Path
from pflog import pflog
import socket
import os
os.environ['XDG_CONFIG_HOME'] = '/tmp'
import time
import pudb
def test_pfprint() -> None:
collection:str = '%timestamp_chrplc|:|-_'
IP:str = socket.gethostbyname(socket.gethostname())
# This test will fail if a local `pftel` server has not been started!
pftelURL:str = f"http://{IP}:22223/api/v1/new/{collection}/event"
d_log:dict = pflog.pfprint(pftelURL, "hello, world!" , appName = "testApp", execTime = 2.0)
assert d_log['status'] is True
def test_pfprint_invalidURLspec() -> None:
# This spec is missing the /api/v1/ !
pftelURL:str = r'http://somehost.somewhere.com/logObject/logCollection/logEvent'
d_log:dict = pflog.pfprint(pftelURL, "hello, world!" , appName = "testApp", execTime = 2.0)
assert d_log['status'] is False
def test_pfprint_validSpecInvalidURL() -> None:
# Here we have a valid spec, but the URL is invalid !
pftelURL:str = r'http://1.2.3.4:22/api/v1/logObject/logCollection/logEvent'
d_log:dict = pflog.pfprint(pftelURL, "hello, world!" , appName = "testApp", execTime = 2.0)
assert d_log['status'] is False
def testmocptelTimedNoArgsDecorator(mocker) -> None:
mock_print = mocker.patch('builtins.print')
@pflog.tel_logTime
def wait(seconds:float) -> None:
time.sleep(seconds)
wait(2)
assert mock_print.call_count is 1
def test_mocpftelTimed(mocker) -> None:
"""
Send message to the moc listener with a log time
"""
mock_print = mocker.patch('builtins.print')
pftelURL:str = r'https://pftel-chris-public.apps.ocp-prod.massopen.cloud/api/v1/timetest/%timestamp/analysis'
@pflog.tel_logTime(
pftelDB = pftelURL,
event = 'pytest',
log = 'A two second delay logger'
)
def wait(seconds:float) -> None:
time.sleep(seconds)
wait(2)
assert mock_print.call_count is 2