mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-23 13:52:17 -06:00
9627 use ArrayField on VLANGroup for allowed VLANs (#16710)
* 9627 initial commit * 9627 numeric range field * 9627 numeric range field * 9627 numeric range field * 9627 numeric range field * 9627 add stuff for utilization calc * 9627 update views * 9627 fixes * 9627 available_vlans * 9627 available_vlans * 9627 fixes * 9627 bulk import / edit * 9627 test fixes * 9627 test fixes * 9627 update validation * 9627 fix tests * 9627 fix tests * 9627 fix tests * 9627 fix tests * 9627 fix tests * 9627 fix tests * 9627 review changes * 9627 temp vlan_id filter * Clean up labels * Remove annotate_vlan_ranges() from VLANGroupQuerySet * Misc cleanup * Implement contains_vid filter * Serialize VID ranges as integer lists in REST API * Remove default value from vlan_id_ranges * 9627 fix typo in test * Require vlan_id_ranges & set default value * Fix logic for upper range boundaries * Add field to VLANGroup model documentation * Rename vlan_id_ranges to vid_ranges * Fix computation of available VLAN IDs * Clean up migration * Add tests for range utility functions * Clean up add_available_vlans() * Misc cleanup, add test for VID validation --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
68
netbox/utilities/tests/test_data.py
Normal file
68
netbox/utilities/tests/test_data.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from django.db.backends.postgresql.psycopg_any import NumericRange
|
||||
from django.test import TestCase
|
||||
|
||||
from utilities.data import check_ranges_overlap, ranges_to_string, string_to_ranges
|
||||
|
||||
|
||||
class RangeFunctionsTestCase(TestCase):
|
||||
|
||||
def test_check_ranges_overlap(self):
|
||||
# Non-overlapping ranges
|
||||
self.assertFalse(
|
||||
check_ranges_overlap([
|
||||
NumericRange(9, 19, bounds='(]'), # 10-19
|
||||
NumericRange(19, 30, bounds='(]'), # 20-29
|
||||
])
|
||||
)
|
||||
self.assertFalse(
|
||||
check_ranges_overlap([
|
||||
NumericRange(10, 19, bounds='[]'), # 10-19
|
||||
NumericRange(20, 29, bounds='[]'), # 20-29
|
||||
])
|
||||
)
|
||||
self.assertFalse(
|
||||
check_ranges_overlap([
|
||||
NumericRange(10, 20, bounds='[)'), # 10-19
|
||||
NumericRange(20, 30, bounds='[)'), # 20-29
|
||||
])
|
||||
)
|
||||
|
||||
# Overlapping ranges
|
||||
self.assertTrue(
|
||||
check_ranges_overlap([
|
||||
NumericRange(9, 20, bounds='(]'), # 10-20
|
||||
NumericRange(19, 30, bounds='(]'), # 20-30
|
||||
])
|
||||
)
|
||||
self.assertTrue(
|
||||
check_ranges_overlap([
|
||||
NumericRange(10, 20, bounds='[]'), # 10-20
|
||||
NumericRange(20, 30, bounds='[]'), # 20-30
|
||||
])
|
||||
)
|
||||
self.assertTrue(
|
||||
check_ranges_overlap([
|
||||
NumericRange(10, 21, bounds='[)'), # 10-20
|
||||
NumericRange(20, 31, bounds='[)'), # 10-30
|
||||
])
|
||||
)
|
||||
|
||||
def test_ranges_to_string(self):
|
||||
self.assertEqual(
|
||||
ranges_to_string([
|
||||
NumericRange(10, 20), # 10-19
|
||||
NumericRange(30, 40), # 30-39
|
||||
NumericRange(100, 200), # 100-199
|
||||
]),
|
||||
'10-19,30-39,100-199'
|
||||
)
|
||||
|
||||
def test_string_to_ranges(self):
|
||||
self.assertEqual(
|
||||
string_to_ranges('10-19, 30-39, 100-199'),
|
||||
[
|
||||
NumericRange(10, 19, bounds='[]'), # 10-19
|
||||
NumericRange(30, 39, bounds='[]'), # 30-39
|
||||
NumericRange(100, 199, bounds='[]'), # 100-199
|
||||
]
|
||||
)
|
||||
Reference in New Issue
Block a user