mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-18 23:07:42 +01:00
When IP addresses and IP ranges are displayed together in a prefix's
IP Addresses tab, only IP addresses should be selectable for bulk
operations since the bulk delete form doesn't support mixed object types.
- Override render_pk() in AnnotatedIPAddressTable to conditionally render
checkboxes only for the table's primary model type (IPAddress)
- Add warning comment to add_requested_prefixes() about fake Prefix objects
- Add regression test to verify IPAddress has checkboxes but IPRange does not
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from django.test import RequestFactory, TestCase
|
|
from netaddr import IPNetwork
|
|
|
|
from ipam.models import IPAddress, IPRange, Prefix
|
|
from ipam.tables import AnnotatedIPAddressTable
|
|
from ipam.utils import annotate_ip_space
|
|
|
|
|
|
class AnnotatedIPAddressTableTest(TestCase):
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
cls.prefix = Prefix.objects.create(
|
|
prefix=IPNetwork('10.1.1.0/24'),
|
|
status='active'
|
|
)
|
|
|
|
cls.ip_address = IPAddress.objects.create(
|
|
address='10.1.1.1/24',
|
|
status='active'
|
|
)
|
|
|
|
cls.ip_range = IPRange.objects.create(
|
|
start_address=IPNetwork('10.1.1.2/24'),
|
|
end_address=IPNetwork('10.1.1.10/24'),
|
|
status='active'
|
|
)
|
|
|
|
def test_ipaddress_has_checkbox_iprange_does_not(self):
|
|
data = annotate_ip_space(self.prefix)
|
|
table = AnnotatedIPAddressTable(data, orderable=False)
|
|
table.columns.show('pk')
|
|
|
|
request = RequestFactory().get('/')
|
|
html = table.as_html(request)
|
|
|
|
ipaddress_checkbox_count = html.count(f'name="pk" value="{self.ip_address.pk}"')
|
|
self.assertEqual(ipaddress_checkbox_count, 1)
|
|
|
|
iprange_checkbox_count = html.count(f'name="pk" value="{self.ip_range.pk}"')
|
|
self.assertEqual(iprange_checkbox_count, 0)
|