Add ticket equality test and representation.

pull/519/head
Daniel Black 2013-12-26 05:27:41 +00:00
parent a1a219189f
commit e9f5f9b86f
2 changed files with 13 additions and 5 deletions

View File

@ -46,9 +46,17 @@ class Ticket:
self.__matches = matches or []
def __str__(self):
return "%s: ip=%s time=%s #attempts=%d" % \
(self.__class__.__name__.split('.')[-1], self.__ip, self.__time, self.__attempt)
return "%s: ip=%s time=%s #attempts=%d matches=%r" % \
(self.__class__.__name__.split('.')[-1], self.__ip, self.__time, self.__attempt, self.__matches)
def __repr__(self):
return str(self)
def __eq__(self, other):
return self.__ip == other.__ip and \
round(self.__time,2) == round(other.__time,2) and \
self.__attempt == other.__attempt and \
self.__matches == other.__matches
def setIP(self, value):
if isinstance(value, basestring):

View File

@ -95,14 +95,14 @@ class AddFailure(unittest.TestCase):
ticket_str = str(ticket)
self.assertEqual(
ticket_str,
'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5')
'FailTicket: ip=193.168.0.128 time=1167605999.0 #attempts=5 matches=[]')
# and some get/set-ers otherwise not tested
ticket.setTime(1000002000.0)
self.assertEqual(ticket.getTime(), 1000002000.0)
# and str() adjusted correspondingly
self.assertEqual(
str(ticket),
'FailTicket: ip=193.168.0.128 time=1000002000.0 #attempts=5')
'FailTicket: ip=193.168.0.128 time=1000002000.0 #attempts=5 matches=[]')
def testbanNOK(self):
self.__failManager.setMaxRetry(10)