32
32
import json
33
33
import os
34
34
import tempfile
35
- import time
36
35
import sys
37
36
import random
38
37
import string
38
+ from io import StringIO
39
39
from pwd import getpwuid
40
40
41
41
from vsc .install .testing import TestCase
42
42
43
- from vsc .utils .zabbix import ZabbixReporter , SimpleZabbix
43
+ from vsc .utils .zabbix import ZabbixReporter
44
44
from vsc .utils .nagios import NAGIOS_EXIT_OK , NAGIOS_EXIT_WARNING , NAGIOS_EXIT_CRITICAL , NAGIOS_EXIT_UNKNOWN
45
- from vsc .utils .py2vs3 import StringIO
46
45
47
46
48
47
class TestZabbix (TestCase ):
@@ -51,7 +50,7 @@ class TestZabbix(TestCase):
51
50
def setUp (self ):
52
51
user = getpwuid (os .getuid ())
53
52
self .nagios_user = user .pw_name
54
- super (TestZabbix , self ).setUp ()
53
+ super ().setUp ()
55
54
56
55
def test_cache (self ):
57
56
"""Test the caching mechanism in the reporter."""
@@ -61,7 +60,6 @@ def test_cache(self):
61
60
62
61
message = '' .join (random .choice (string .printable ) for x in range (length ))
63
62
message = message .rstrip ()
64
- message = json .dumps ([message ])
65
63
66
64
(handle , filename ) = tempfile .mkstemp ()
67
65
os .unlink (filename )
@@ -72,7 +70,7 @@ def test_cache(self):
72
70
73
71
reporter .cache (nagios_exit , message )
74
72
75
- (handle , output_filename ) = tempfile .mkstemp ()
73
+ (handle , _ ) = tempfile .mkstemp ()
76
74
os .close (handle )
77
75
78
76
try :
@@ -85,9 +83,9 @@ def test_cache(self):
85
83
line = buffer .getvalue ().rstrip ()
86
84
sys .stdout = old_stdout
87
85
buffer .close ()
88
- self .assertTrue (err .code == nagios_exit [0 ])
86
+ self .assertEqual (err .code , nagios_exit [0 ])
89
87
line = json .loads (line )
90
- self .assertTrue (line ["exit_string" ] == nagios_exit [1 ])
91
- self .assertTrue (line ["message" ][ 0 ] == json . loads ( message )[ 0 ] )
88
+ self .assertEqual (line ["exit_string" ], nagios_exit [1 ])
89
+ self .assertEqual (line ["message" ], message )
92
90
93
91
os .unlink (filename )
0 commit comments