Skip to content

Commit

Permalink
15761 filter IKE Proposals on IKE Policy detail view (netbox-communit…
Browse files Browse the repository at this point in the history
…y#15766)

* 15761 filter IKEAProposals on IKEAPolicy detail view

* Add test for ike_policy filter

---------

Co-authored-by: Jeremy Stretch <[email protected]>
  • Loading branch information
2 people authored and JCWasmx86 committed Apr 23, 2024
1 parent b5e792d commit c36b914
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions netbox/vpn/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ class IKEProposalFilterSet(NetBoxModelFilterSet):
group = django_filters.MultipleChoiceFilter(
choices=DHGroupChoices
)
ike_policy_id = django_filters.ModelMultipleChoiceFilter(
field_name='ike_policies',
queryset=IKEPolicy.objects.all(),
label=_('IKE policy (ID)'),
)
ike_policy = django_filters.ModelMultipleChoiceFilter(
field_name='ike_policies__name',
queryset=IKEPolicy.objects.all(),
to_field_name='name',
label=_('IKE policy (name)'),
)

class Meta:
model = IKEProposal
Expand Down
17 changes: 17 additions & 0 deletions netbox/vpn/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ def setUpTestData(cls):
)
IKEProposal.objects.bulk_create(ike_proposals)

ike_policies = (
IKEPolicy(name='IKE Policy 1'),
IKEPolicy(name='IKE Policy 2'),
IKEPolicy(name='IKE Policy 3'),
)
IKEPolicy.objects.bulk_create(ike_policies)
ike_policies[0].proposals.add(ike_proposals[0])
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)
Expand Down Expand Up @@ -369,6 +379,13 @@ def test_sa_lifetime(self):
params = {'sa_lifetime': [1000, 2000]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_ike_policy(self):
ike_policies = IKEPolicy.objects.all()[:2]
params = {'ike_policy_id': [ike_policies[0].pk, ike_policies[1].pk]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
params = {'ike_policy': [ike_policies[0].name, ike_policies[1].name]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)


class IKEPolicyTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = IKEPolicy.objects.all()
Expand Down

0 comments on commit c36b914

Please sign in to comment.