@@ -94,22 +94,25 @@ def _assert_equal_entries(utest, found, output, count=None):
94
94
# do not check if custom count (e.g. going through them twice)
95
95
utest .assertEqual (repr (found [3 ]), repr (output [3 ]))
96
96
97
+ def _ticket_tuple (ticket ):
98
+ """Create a tuple for easy comparison from fail ticket
99
+ """
100
+ attempts = ticket .getAttempt ()
101
+ date = ticket .getTime ()
102
+ ip = ticket .getIP ()
103
+ matches = ticket .getMatches ()
104
+ return (ip , attempts , date , matches )
105
+
97
106
def _assert_correct_last_attempt (utest , filter_ , output , count = None ):
98
107
"""Additional helper to wrap most common test case
99
108
100
109
Test filter to contain target ticket
101
110
"""
102
111
if isinstance (filter_ , DummyJail ):
103
- ticket = filter_ .getFailTicket ()
112
+ found = _ticket_tuple ( filter_ .getFailTicket () )
104
113
else :
105
114
# when we are testing without jails
106
- ticket = filter_ .failManager .toBan ()
107
-
108
- attempts = ticket .getAttempt ()
109
- date = ticket .getTime ()
110
- ip = ticket .getIP ()
111
- matches = ticket .getMatches ()
112
- found = (ip , attempts , date , matches )
115
+ found = _ticket_tuple (filter_ .failManager .toBan ())
113
116
114
117
_assert_equal_entries (utest , found , output , count )
115
118
@@ -642,10 +645,14 @@ def testGetFailuresMultiLine(self):
642
645
643
646
self .filter .getFailures (GetFailures .FILENAME_MULTILINE )
644
647
645
- _assert_correct_last_attempt (self , self .filter , output .pop ())
646
- _assert_correct_last_attempt (self , self .filter , output .pop ())
647
-
648
- self .assertRaises (FailManagerEmpty , self .filter .failManager .toBan )
648
+ foundList = []
649
+ while True :
650
+ try :
651
+ foundList .append (
652
+ _ticket_tuple (self .filter .failManager .toBan ())[0 :3 ])
653
+ except FailManagerEmpty :
654
+ break
655
+ self .assertEqual (sorted (foundList ), sorted (output ))
649
656
650
657
def testGetFailuresMultiLineIgnoreRegex (self ):
651
658
output = [("192.0.43.10" , 2 , 1124013599.0 )]
@@ -673,11 +680,14 @@ def testGetFailuresMultiLineMultiRegex(self):
673
680
674
681
self .filter .getFailures (GetFailures .FILENAME_MULTILINE )
675
682
676
- _assert_correct_last_attempt (self , self .filter , output .pop ())
677
- _assert_correct_last_attempt (self , self .filter , output .pop ())
678
- _assert_correct_last_attempt (self , self .filter , output .pop ())
679
-
680
- self .assertRaises (FailManagerEmpty , self .filter .failManager .toBan )
683
+ foundList = []
684
+ while True :
685
+ try :
686
+ foundList .append (
687
+ _ticket_tuple (self .filter .failManager .toBan ())[0 :3 ])
688
+ except FailManagerEmpty :
689
+ break
690
+ self .assertEqual (sorted (foundList ), sorted (output ))
681
691
682
692
class DNSUtilsTests (unittest .TestCase ):
683
693
0 commit comments