def test_bogus_requests_releases(self): """Requests twice or release twice""" s = SlotsProvider(10) s.request("eth1", "192.168.1.10") with self.assertRaises(ValueError): s.request("eth1", "192.168.1.10") self.assertEqual(s.request("eth1", "192.168.1.11"), 1) s.release("192.168.1.10") with self.assertRaises(ValueError): s.release("192.168.1.10") with self.assertRaises(ValueError): s.get("192.168.1.10")
def test_requests(self): """Request a slot""" s = SlotsProvider(10) self.assertEqual(s.request("eth1", "192.168.1.1"), 0) self.assertEqual(s.request("eth1", "192.168.1.2"), 1) self.assertEqual(s.request("eth1", "192.168.1.3"), 2) self.assertEqual(s.request("eth3", "192.168.1.4"), 0) self.assertEqual(s.request("eth3", "192.168.1.5"), 1) self.assertEqual(s.get("192.168.1.5"), 1)