def test_repr(self): c1 = contact.Contact(self.ipv4, self.port1, self.guid1) cr = repr(c1) self.assertEqual( cr, 'Contact({0}, {1}, {2})'.format(self.ipv4, self.port1, self.guid1) )
def setUpClass(cls): cls.range_min = 0 cls.range_max = 2**constants.BIT_NODE_ID_LEN cls.own_num_guid = 1 cls.own_guid = util.num_to_guid(cls.own_num_guid) cls.bad_guid = 'f' * (constants.HEX_NODE_ID_LEN + 1) cls.bad_contact = contact.Contact('123.45.67.89', 12345, cls.bad_guid)
def test_add_self_contact(self): self_contact = contact.Contact('123.45.67.89', 12345, self.own_guid) self.rt.add_contact(self_contact) self.assertIsNone(self.rt.get_contact(self.own_guid)) self.assertEqual(len(self.rt), 1) self.assertEqual(list(self.rt[0]), [])
def _make_contact_from_num(i): return contact.Contact('123.45.67.89', 12345, util.num_to_guid(i))
def test_uneq(self): c1 = contact.Contact(self.ipv4, self.port1, self.guid1) c2 = contact.Contact(self.ipv4, self.port1, self.guid2) self.assertNotEqual(c1, c2)
def test_eq_hash(self): c1 = contact.Contact(self.ipv4, self.port1, self.guid1) c2 = contact.Contact(self.ipv6, self.port2, self.guid1) self.assertIsNot(c1, c2) self.assertEqual(c1, c2) self.assertEqual(hash(c1), hash(c2))
def _test_init_scenario(self, ip, port, guid): contact1 = contact.Contact(ip, port, guid) self.assertEqual(contact1.ip, ip) self.assertEqual(contact1.port, port) self.assertEqual(contact1.guid, guid)