-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_pool.py
37 lines (30 loc) · 1.48 KB
/
test_pool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import unittest
import demodhcpd
class AddressPoolTest(unittest.TestCase):
def test_pool(self):
pool = demodhcpd.AddressPool(['a', 'b', 'c', 'd'])
self.assertEqual(pool.get_addr('mac1'), 'a')
self.assertEqual(pool.get_addr('mac2'), 'a')
assert pool.assign('a', 'mac1', 'hostname1')
assert pool.assign('a', 'mac1', 'hostname1')
assert pool.assign('a', 'mac1', 'hostname2')
assert not pool.assign('a', 'mac2', 'hostname3')
self.assertEqual(pool.get_addr('mac1'), 'a')
self.assertEqual(pool.get_addr('mac2'), 'b')
self.assertEqual(pool.get_addr('mac2'), 'b')
assert pool.assign('b', 'mac2', 'hostname1')
assert pool.assign('b', 'mac2', 'hostname1')
assert not pool.assign('b', 'mac3', 'hostname1')
assert not pool.assign('x', 'mac4', 'hostname4')
def test_pool_exhausted(self):
pool = demodhcpd.AddressPool(['a', 'b'])
self.assertEqual(pool.get_addr('mac1'), 'a')
assert pool.assign('a', 'mac1', 'hostname1')
self.assertEqual(pool.get_addr('mac1'), 'a')
self.assertEqual(pool.get_addr('mac2'), 'b')
assert pool.assign('b', 'mac2', 'hostname2')
self.assertEqual(pool.get_addr('mac1'), 'a')
self.assertEqual(pool.get_addr('mac2'), 'b')
self.assertRaises(demodhcpd.NoAddressAvailable, pool.get_addr, 'mac3')
pool = demodhcpd.AddressPool([])
self.assertRaises(demodhcpd.NoAddressAvailable, pool.get_addr, 'any')