BF+ENH: fixed up testing querying cymru information + assert_dict_equal helper

pull/1400/head
Yaroslav Halchenko 9 years ago
parent aa303acfd6
commit 340a5a23f4

@ -28,7 +28,7 @@ import unittest
from ..server.banmanager import BanManager from ..server.banmanager import BanManager
from ..server.ticket import BanTicket from ..server.ticket import BanTicket
from .utils import assert_dict_equal
class AddFailure(unittest.TestCase): class AddFailure(unittest.TestCase):
def setUp(self): def setUp(self):
@ -74,15 +74,10 @@ class StatusExtendedCymruInfo(unittest.TestCase):
def testCymruInfo(self): def testCymruInfo(self):
cymru_info = self.__banManager.getBanListExtendedCymruInfo() cymru_info = self.__banManager.getBanListExtendedCymruInfo()
if "assertDictEqual" in dir(self): assert_dict_equal(cymru_info,
self.assertDictEqual(cymru_info, {"asn": [self.__asn], {"asn": [self.__asn],
"country": [self.__country], "country": [self.__country],
"rir": [self.__rir]}) "rir": [self.__rir]})
else:
# Python 2.6 does not support assertDictEqual()
self.assertEqual(cymru_info["asn"], [self.__asn])
self.assertEqual(cymru_info["country"], [self.__country])
self.assertEqual(cymru_info["rir"], [self.__rir])
def testCymruInfoASN(self): def testCymruInfoASN(self):
self.assertEqual( self.assertEqual(
@ -100,16 +95,24 @@ class StatusExtendedCymruInfo(unittest.TestCase):
[self.__rir]) [self.__rir])
def testCymruInfoNxdomain(self): def testCymruInfoNxdomain(self):
ticket = BanTicket("10.0.0.0", 1167605999.0)
self.__banManager = BanManager() self.__banManager = BanManager()
# non-existing IP
ticket = BanTicket("0.0.0.0", 1167605999.0)
self.assertTrue(self.__banManager.addBanTicket(ticket))
cymru_info = self.__banManager.getBanListExtendedCymruInfo()
assert_dict_equal(cymru_info,
{"asn": ["nxdomain"],
"country": ["nxdomain"],
"rir": ["nxdomain"]})
# even for private IPs ASNs defined
# Since it outputs for all active tickets we would get previous results
# and new ones
ticket = BanTicket("10.0.0.0", 1167606000.0)
self.assertTrue(self.__banManager.addBanTicket(ticket)) self.assertTrue(self.__banManager.addBanTicket(ticket))
cymru_info = self.__banManager.getBanListExtendedCymruInfo() cymru_info = self.__banManager.getBanListExtendedCymruInfo()
if "assertDictEqual" in dir(self): assert_dict_equal(cymru_info,
self.assertDictEqual(cymru_info, {"asn": ["nxdomain"], {"asn": ["nxdomain", "4565",],
"country": ["nxdomain"], "country": ["nxdomain", "unknown"],
"rir": ["nxdomain"]}) "rir": ["nxdomain", "other"]})
else:
# Python 2.6 does not support assertDictEqual()
self.assertEqual(cymru_info["asn"], ["nxdomain"])
self.assertEqual(cymru_info["country"], ["nxdomain"])
self.assertEqual(cymru_info["rir"], ["nxdomain"])

@ -312,4 +312,10 @@ else:
kernel32.CloseHandle(process) kernel32.CloseHandle(process)
return True return True
else: else:
return False return False
# Python 2.6 compatibility. in 2.7 assertDictEqual
def assert_dict_equal(a, b):
assert isinstance(a, dict), "Object is not dictionary: %r" % a
assert isinstance(b, dict), "Object is not dictionary: %r" % b
assert a==b, "Dictionaries differ:\n%r !=\n%r" % (a, b)

Loading…
Cancel
Save