From d930c4e36e9ad1232c709ceb7a5a42df28a459f2 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 28 Dec 2023 14:43:08 -0500 Subject: [PATCH] Apply filterset & test changes for #14631 & #14629 --- netbox/extras/filtersets.py | 2 +- netbox/extras/tests/test_filtersets.py | 20 +++- .../virtualization/tests/test_filtersets.py | 12 ++- netbox/vpn/filtersets.py | 12 +-- netbox/vpn/tests/test_filtersets.py | 100 +++++++++++++++--- 5 files changed, 119 insertions(+), 27 deletions(-) diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py index b995fbbc457..730499956d3 100644 --- a/netbox/extras/filtersets.py +++ b/netbox/extras/filtersets.py @@ -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): diff --git a/netbox/extras/tests/test_filtersets.py b/netbox/extras/tests/test_filtersets.py index 9b111793fdd..ef8aedcbd3e 100644 --- a/netbox/extras/tests/test_filtersets.py +++ b/netbox/extras/tests/test_filtersets.py @@ -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', @@ -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) @@ -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', @@ -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', @@ -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', @@ -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) diff --git a/netbox/virtualization/tests/test_filtersets.py b/netbox/virtualization/tests/test_filtersets.py index e5c85df4028..5c020e1b2a7 100644 --- a/netbox/virtualization/tests/test_filtersets.py +++ b/netbox/virtualization/tests/test_filtersets.py @@ -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]} @@ -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) diff --git a/netbox/vpn/filtersets.py b/netbox/vpn/filtersets.py index fbdbb241803..0647838a8ec 100644 --- a/netbox/vpn/filtersets.py +++ b/netbox/vpn/filtersets.py @@ -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(): @@ -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(): @@ -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(): @@ -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(): @@ -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(): @@ -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(): diff --git a/netbox/vpn/tests/test_filtersets.py b/netbox/vpn/tests/test_filtersets.py index 1c4996e0a86..d4e80750d02 100644 --- a/netbox/vpn/tests/test_filtersets.py +++ b/netbox/vpn/tests/test_filtersets.py @@ -24,6 +24,10 @@ def setUpTestData(cls): TunnelGroup(name='Tunnel Group 3', slug='tunnel-group-3'), )) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['Tunnel Group 1']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) @@ -96,7 +100,8 @@ def setUpTestData(cls): group=tunnel_groups[0], encapsulation=TunnelEncapsulationChoices.ENCAP_GRE, ipsec_profile=ipsec_profiles[0], - tunnel_id=100 + tunnel_id=100, + description='foobar1' ), Tunnel( name='Tunnel 2', @@ -104,7 +109,8 @@ def setUpTestData(cls): group=tunnel_groups[1], encapsulation=TunnelEncapsulationChoices.ENCAP_IP_IP, ipsec_profile=ipsec_profiles[0], - tunnel_id=200 + tunnel_id=200, + description='foobar2' ), Tunnel( name='Tunnel 3', @@ -112,11 +118,16 @@ def setUpTestData(cls): group=tunnel_groups[2], encapsulation=TunnelEncapsulationChoices.ENCAP_IPSEC_TUNNEL, ipsec_profile=None, - tunnel_id=300 + tunnel_id=300, + description='foobar3' ), ) Tunnel.objects.bulk_create(tunnels) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['Tunnel 1', 'Tunnel 2']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) @@ -147,6 +158,10 @@ def test_tunnel_id(self): params = {'tunnel_id': [100, 200]} 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) + class TunnelTerminationTestCase(TestCase, ChangeLoggedFilterSetTests): queryset = TunnelTermination.objects.all() @@ -292,7 +307,8 @@ def setUpTestData(cls): encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES128_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA1, group=DHGroupChoices.GROUP_1, - sa_lifetime=1000 + sa_lifetime=1000, + description='foobar1' ), IKEProposal( name='IKE Proposal 2', @@ -300,7 +316,8 @@ def setUpTestData(cls): encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES192_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA256, group=DHGroupChoices.GROUP_2, - sa_lifetime=2000 + sa_lifetime=2000, + description='foobar2' ), IKEProposal( name='IKE Proposal 3', @@ -308,15 +325,24 @@ def setUpTestData(cls): encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES256_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA512, group=DHGroupChoices.GROUP_5, - sa_lifetime=3000 + sa_lifetime=3000, + description='foobar3' ), ) IKEProposal.objects.bulk_create(ike_proposals) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['IKE Proposal 1', 'IKE Proposal 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_authentication_method(self): params = {'authentication_method': [ AuthenticationMethodChoices.PRESHARED_KEYS, AuthenticationMethodChoices.CERTIFICATES @@ -380,16 +406,19 @@ def setUpTestData(cls): name='IKE Policy 1', version=IKEVersionChoices.VERSION_1, mode=IKEModeChoices.MAIN, + description='foobar1' ), IKEPolicy( name='IKE Policy 2', version=IKEVersionChoices.VERSION_1, mode=IKEModeChoices.MAIN, + description='foobar2' ), IKEPolicy( name='IKE Policy 3', version=IKEVersionChoices.VERSION_2, mode=IKEModeChoices.AGGRESSIVE, + description='foobar3' ), ) IKEPolicy.objects.bulk_create(ike_policies) @@ -397,10 +426,18 @@ def setUpTestData(cls): ike_policies[1].proposals.add(ike_proposals[1]) ike_policies[2].proposals.add(ike_proposals[2]) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['IKE Policy 1', 'IKE Policy 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_version(self): params = {'version': [IKEVersionChoices.VERSION_1]} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) @@ -429,29 +466,40 @@ def setUpTestData(cls): encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES128_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA1, sa_lifetime_seconds=1000, - sa_lifetime_data=1000 + sa_lifetime_data=1000, + description='foobar1' ), IPSecProposal( name='IPSec Proposal 2', encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES192_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA256, sa_lifetime_seconds=2000, - sa_lifetime_data=2000 + sa_lifetime_data=2000, + description='foobar2' ), IPSecProposal( name='IPSec Proposal 3', encryption_algorithm=EncryptionAlgorithmChoices.ENCRYPTION_AES256_CBC, authentication_algorithm=AuthenticationAlgorithmChoices.AUTH_HMAC_SHA512, sa_lifetime_seconds=3000, - sa_lifetime_data=3000 + sa_lifetime_data=3000, + description='foobar3' ), ) IPSecProposal.objects.bulk_create(ipsec_proposals) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['IPSec Proposal 1', 'IPSec Proposal 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_encryption_algorithm(self): params = {'encryption_algorithm': [ EncryptionAlgorithmChoices.ENCRYPTION_AES128_CBC, EncryptionAlgorithmChoices.ENCRYPTION_AES192_CBC @@ -501,15 +549,18 @@ def setUpTestData(cls): ipsec_policies = ( IPSecPolicy( name='IPSec Policy 1', - pfs_group=DHGroupChoices.GROUP_1 + pfs_group=DHGroupChoices.GROUP_1, + description='foobar1' ), IPSecPolicy( name='IPSec Policy 2', - pfs_group=DHGroupChoices.GROUP_2 + pfs_group=DHGroupChoices.GROUP_2, + description='foobar2' ), IPSecPolicy( name='IPSec Policy 3', - pfs_group=DHGroupChoices.GROUP_5 + pfs_group=DHGroupChoices.GROUP_5, + description='foobar3' ), ) IPSecPolicy.objects.bulk_create(ipsec_policies) @@ -517,10 +568,18 @@ def setUpTestData(cls): ipsec_policies[1].proposals.add(ipsec_proposals[1]) ipsec_policies[2].proposals.add(ipsec_proposals[2]) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['IPSec Policy 1', 'IPSec Policy 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_pfs_group(self): params = {'pfs_group': [DHGroupChoices.GROUP_1, DHGroupChoices.GROUP_2]} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) @@ -596,27 +655,38 @@ def setUpTestData(cls): name='IPSec Profile 1', mode=IPSecModeChoices.ESP, ike_policy=ike_policies[0], - ipsec_policy=ipsec_policies[0] + ipsec_policy=ipsec_policies[0], + description='foobar1' ), IPSecProfile( name='IPSec Profile 2', mode=IPSecModeChoices.ESP, ike_policy=ike_policies[1], - ipsec_policy=ipsec_policies[1] + ipsec_policy=ipsec_policies[1], + description='foobar2' ), IPSecProfile( name='IPSec Profile 3', mode=IPSecModeChoices.AH, ike_policy=ike_policies[2], - ipsec_policy=ipsec_policies[2] + ipsec_policy=ipsec_policies[2], + description='foobar3' ), ) IPSecProfile.objects.bulk_create(ipsec_profiles) + def test_q(self): + params = {'q': 'foobar1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + def test_name(self): params = {'name': ['IPSec Profile 1', 'IPSec Profile 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_mode(self): params = {'mode': [IPSecModeChoices.ESP]} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)