1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

69 lines
1.7 KiB
Python
Raw Normal View History

2020-01-09 18:26:10 +00:00
from django.test import TestCase
from utilities.forms import *
class ExpandIPAddress(TestCase):
"""
Validate the operation of expand_ipaddress_pattern().
"""
def test_ipv4_range(self):
input = '1.2.3.[9-10]/32'
output = sorted([
'1.2.3.9/32',
'1.2.3.10/32',
])
2020-01-10 10:26:46 +00:00
self.assertEqual(sorted(expand_ipaddress_pattern(input, 4)), output)
2020-01-09 18:26:10 +00:00
def test_ipv4_set(self):
input = '1.2.3.[4,44]/32'
output = sorted([
'1.2.3.4/32',
'1.2.3.44/32',
])
2020-01-10 10:26:46 +00:00
self.assertEqual(sorted(expand_ipaddress_pattern(input, 4)), output)
2020-01-09 18:26:10 +00:00
def test_ipv4_multiple_ranges(self):
input = '1.[9-10].3.[9-11]/32'
output = sorted([
'1.9.3.9/32',
'1.9.3.10/32',
'1.9.3.11/32',
'1.10.3.9/32',
'1.10.3.10/32',
'1.10.3.11/32',
])
2020-01-10 10:26:46 +00:00
self.assertEqual(sorted(expand_ipaddress_pattern(input, 4)), output)
2020-01-09 18:26:10 +00:00
def test_ipv4_multiple_sets(self):
input = '1.[2,22].3.[4,44]/32'
output = sorted([
'1.2.3.4/32',
'1.2.3.44/32',
'1.22.3.4/32',
'1.22.3.44/32',
])
2020-01-10 10:26:46 +00:00
self.assertEqual(sorted(expand_ipaddress_pattern(input, 4)), output)
2020-01-09 18:26:10 +00:00
def test_ipv4_set_and_range(self):
input = '1.[2,22].3.[9-11]/32'
output = sorted([
'1.2.3.9/32',
'1.2.3.10/32',
'1.2.3.11/32',
'1.22.3.9/32',
'1.22.3.10/32',
'1.22.3.11/32',
])
2020-01-10 10:26:46 +00:00
self.assertEqual(sorted(expand_ipaddress_pattern(input, 4)), output)
2020-01-09 18:26:10 +00:00
# TODO: IPv6
# TODO: negative tests
# TODO: alphanumeric