Source code for dhcpkit.tests.ipv6.extensions.leasequery.test_lq_client_link_option

"""
Test the LQClientLink implementation
"""
import unittest
from ipaddress import IPv6Address

from dhcpkit.ipv6.extensions.leasequery import LQClientLink, LQRelayDataOption
from dhcpkit.tests.ipv6.options import test_option


[docs]class ClientDataOptionTestCase(test_option.OptionTestCase):
[docs] def setUp(self): self.option_bytes = bytes.fromhex( '0030' # Option type: OPTION_LQ_CLIENT_LINK '0030' # Option length: 48 '20010db8000000000000000000000001' # Link address: 2001:db8::2 '20010db8000000000000000000000002' # Link address: 2001:db8::2 '20010db8000000000000000000000004' # Link address: 2001:db8::2 ) self.option_object = LQClientLink(link_addresses=[ IPv6Address('2001:db8::1'), IPv6Address('2001:db8::2'), IPv6Address('2001:db8::4'), ]) self.parse_option()
[docs] def test_parse_wrong_type(self): with self.assertRaisesRegex(ValueError, 'does not contain LQClientLink data'): option = LQClientLink() option.load_from(b'00020010ff12000000000000000000000000abcd')
[docs] def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, 'length does not match the combined length'): LQRelayDataOption.parse(bytes.fromhex( '0030' # Option type: OPTION_LQ_CLIENT_LINK '002f' # Option length: 47 (should be 48) '20010db8000000000000000000000001' # Link address: 2001:db8::2 '20010db8000000000000000000000002' # Link address: 2001:db8::2 '20010db8000000000000000000000004' # Link address: 2001:db8::2 )) with self.assertRaisesRegex(ValueError, 'longer than the available buffer'): LQRelayDataOption.parse(bytes.fromhex( '0030' # Option type: OPTION_LQ_CLIENT_LINK '0031' # Option length: 49 (should be 48) '20010db8000000000000000000000001' # Link address: 2001:db8::2 '20010db8000000000000000000000002' # Link address: 2001:db8::2 '20010db8000000000000000000000004' # Link address: 2001:db8::2 ))
if __name__ == '__main__': # pragma: no cover unittest.main()