예제 #1
0
 def test_remove_contact_with_bad_id(self):
     """
     Ensures a ValueError exception is raised if one attempts to remove a
     non-existent contact from a k-bucket.
     """
     range_min = 12345
     range_max = 98765
     bucket = Bucket(range_min, range_max)
     contact = PeerNode("12345", "192.168.0.2", 8888, 123)
     bucket.add_contact(contact)
     with self.assertRaises(ValueError):
         bucket.remove_contact("54321")
예제 #2
0
 def test_remove_contact(self):
     """
     Ensures it is possible to remove a contact with a certain ID from the
     k-bucket.
     """
     range_min = 12345
     range_max = 98765
     bucket = Bucket(range_min, range_max)
     for i in range(K):
         contact = PeerNode("%d" % i, "192.168.0.%d" % i, 9999, 123)
         bucket.add_contact(contact)
     for i in range(K):
         id = "%d" % i
         bucket.remove_contact(id)
         self.assertFalse(id in bucket._contacts,
                          "Could not remove contact with id %d" % i)