Skip to content

Commit

Permalink
Apply filterset & test changes for #14631 & #14629
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 28, 2023
1 parent d5c1cb0 commit d930c4e
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 27 deletions.
2 changes: 1 addition & 1 deletion netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Meta:
model = Webhook
fields = [
'id', 'name', 'payload_url', 'http_method', 'http_content_type', 'secret', 'ssl_verification',
'ca_file_path',
'ca_file_path', 'description',
]

def search(self, queryset, name, value):
Expand Down
20 changes: 19 additions & 1 deletion netbox/extras/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,21 @@ def setUpTestData(cls):
payload_url='http://example.com/?1',
http_method='GET',
ssl_verification=True,
description='foobar1'
),
Webhook(
name='Webhook 2',
payload_url='http://example.com/?2',
http_method='POST',
ssl_verification=True,
description='foobar2'
),
Webhook(
name='Webhook 3',
payload_url='http://example.com/?3',
http_method='PATCH',
ssl_verification=False,
description='foobar3'
),
Webhook(
name='Webhook 4',
Expand All @@ -211,13 +214,17 @@ def setUpTestData(cls):
Webhook.objects.bulk_create(webhooks)

def test_q(self):
params = {'q': 'Webhook 1'}
params = {'q': 'foobar1'}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_name(self):
params = {'name': ['Webhook 1', 'Webhook 2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_description(self):
params = {'description': ['foobar1', 'foobar2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_http_method(self):
params = {'http_method': ['GET', 'POST']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
Expand Down Expand Up @@ -276,6 +283,7 @@ def setUpTestData(cls):
type_job_start=False,
type_job_end=False,
action_type=EventRuleActionChoices.WEBHOOK,
description='foobar1'
),
EventRule(
name='Event Rule 2',
Expand All @@ -287,6 +295,7 @@ def setUpTestData(cls):
type_job_start=False,
type_job_end=False,
action_type=EventRuleActionChoices.WEBHOOK,
description='foobar2'
),
EventRule(
name='Event Rule 3',
Expand All @@ -298,6 +307,7 @@ def setUpTestData(cls):
type_job_start=False,
type_job_end=False,
action_type=EventRuleActionChoices.WEBHOOK,
description='foobar3'
),
EventRule(
name='Event Rule 4',
Expand Down Expand Up @@ -329,10 +339,18 @@ def setUpTestData(cls):
event_rules[3].content_types.add(content_types[3])
event_rules[4].content_types.add(content_types[4])

def test_q(self):
params = {'q': 'foobar1'}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_name(self):
params = {'name': ['Event Rule 1', 'Event Rule 2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_description(self):
params = {'description': ['foobar1', 'foobar2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_content_types(self):
params = {'content_types': 'dcim.region'}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
Expand Down
12 changes: 8 additions & 4 deletions netbox/virtualization/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,16 @@ def setUpTestData(cls):
VirtualMachine.objects.bulk_create(vms)

disks = (
VirtualDisk(virtual_machine=vms[0], name='Disk 1', size=1, description='A'),
VirtualDisk(virtual_machine=vms[1], name='Disk 2', size=2, description='B'),
VirtualDisk(virtual_machine=vms[2], name='Disk 3', size=3, description='C'),
VirtualDisk(virtual_machine=vms[0], name='Disk 1', size=1, description='foobar1'),
VirtualDisk(virtual_machine=vms[1], name='Disk 2', size=2, description='foobar2'),
VirtualDisk(virtual_machine=vms[2], name='Disk 3', size=3, description='foobar3'),
)
VirtualDisk.objects.bulk_create(disks)

def test_q(self):
params = {'q': 'foobar1'}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_virtual_machine(self):
vms = VirtualMachine.objects.all()[:2]
params = {'virtual_machine_id': [vms[0].pk, vms[1].pk]}
Expand All @@ -691,5 +695,5 @@ def test_size(self):
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_description(self):
params = {'description': ['A', 'B']}
params = {'description': ['foobar1', 'foobar2']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
12 changes: 6 additions & 6 deletions netbox/vpn/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TunnelFilterSet(NetBoxModelFilterSet, TenancyFilterSet):

class Meta:
model = Tunnel
fields = ['id', 'name', 'tunnel_id']
fields = ['id', 'name', 'tunnel_id', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand Down Expand Up @@ -139,7 +139,7 @@ class IKEProposalFilterSet(NetBoxModelFilterSet):

class Meta:
model = IKEProposal
fields = ['id', 'name', 'sa_lifetime']
fields = ['id', 'name', 'sa_lifetime', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand Down Expand Up @@ -167,7 +167,7 @@ class IKEPolicyFilterSet(NetBoxModelFilterSet):

class Meta:
model = IKEPolicy
fields = ['id', 'name', 'preshared_key']
fields = ['id', 'name', 'preshared_key', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand All @@ -189,7 +189,7 @@ class IPSecProposalFilterSet(NetBoxModelFilterSet):

class Meta:
model = IPSecProposal
fields = ['id', 'name', 'sa_lifetime_seconds', 'sa_lifetime_data']
fields = ['id', 'name', 'sa_lifetime_seconds', 'sa_lifetime_data', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand All @@ -214,7 +214,7 @@ class IPSecPolicyFilterSet(NetBoxModelFilterSet):

class Meta:
model = IPSecPolicy
fields = ['id', 'name']
fields = ['id', 'name', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand Down Expand Up @@ -253,7 +253,7 @@ class IPSecProfileFilterSet(NetBoxModelFilterSet):

class Meta:
model = IPSecProfile
fields = ['id', 'name']
fields = ['id', 'name', 'description']

def search(self, queryset, name, value):
if not value.strip():
Expand Down
Loading

0 comments on commit d930c4e

Please sign in to comment.