mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Filterset tests
This commit is contained in:
parent
9da0191b09
commit
b75f142ce4
@ -1123,10 +1123,14 @@ class VLANTranslationPolicyFilterSet(NetBoxModelFilterSet):
|
|||||||
|
|
||||||
|
|
||||||
class VLANTranslationRuleFilterSet(NetBoxModelFilterSet):
|
class VLANTranslationRuleFilterSet(NetBoxModelFilterSet):
|
||||||
|
policy_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
queryset=VLANTranslationPolicy.objects.all(),
|
||||||
|
label=_('VLAN Translation Policy (ID)'),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VLANTranslationRule
|
model = VLANTranslationRule
|
||||||
fields = ('id', 'policy', 'local_vid', 'remote_vid')
|
fields = ('id', 'policy_id', 'local_vid', 'remote_vid')
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -484,14 +484,24 @@ class VLANTranslationRuleFilterForm(NetBoxModelFilterSetForm):
|
|||||||
model = VLANTranslationRule
|
model = VLANTranslationRule
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag'),
|
||||||
FieldSet('policy', 'local_vid', 'remote_vid', name=_('Attributes')),
|
FieldSet('policy_id', 'local_vid', 'remote_vid', name=_('Attributes')),
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
policy = DynamicModelMultipleChoiceField(
|
policy_id = DynamicModelMultipleChoiceField(
|
||||||
queryset=VLANTranslationPolicy.objects.all(),
|
queryset=VLANTranslationPolicy.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('VLAN Translation Policy')
|
label=_('VLAN Translation Policy')
|
||||||
)
|
)
|
||||||
|
local_vid = forms.IntegerField(
|
||||||
|
min_value=1,
|
||||||
|
required=False,
|
||||||
|
label=_('Local VLAN ID')
|
||||||
|
)
|
||||||
|
remote_vid = forms.IntegerField(
|
||||||
|
min_value=1,
|
||||||
|
required=False,
|
||||||
|
label=_('Remote VLAN ID')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VLANFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
class VLANFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||||
|
@ -1898,6 +1898,90 @@ class VLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||||
|
|
||||||
|
|
||||||
|
class VLANTranslationPolicyTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
|
queryset = VLANTranslationPolicy.objects.all()
|
||||||
|
filterset = VLANTranslationPolicyFilterSet
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
|
||||||
|
vlan_translation_policies = (
|
||||||
|
VLANTranslationPolicy(
|
||||||
|
name='Policy 1',
|
||||||
|
description='foobar1',
|
||||||
|
),
|
||||||
|
VLANTranslationPolicy(
|
||||||
|
name='Policy 2',
|
||||||
|
description='foobar2',
|
||||||
|
),
|
||||||
|
VLANTranslationPolicy(
|
||||||
|
name='Policy 3',
|
||||||
|
description='foobar3',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
VLANTranslationPolicy.objects.bulk_create(vlan_translation_policies)
|
||||||
|
|
||||||
|
def test_name(self):
|
||||||
|
params = {'name': ['Policy 1', '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)
|
||||||
|
|
||||||
|
|
||||||
|
class VLANTranslationRuleTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
|
queryset = VLANTranslationRule.objects.all()
|
||||||
|
filterset = VLANTranslationRuleFilterSet
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
|
||||||
|
vlan_translation_policies = (
|
||||||
|
VLANTranslationPolicy(
|
||||||
|
name='Policy 1',
|
||||||
|
description='foobar1',
|
||||||
|
),
|
||||||
|
VLANTranslationPolicy(
|
||||||
|
name='Policy 2',
|
||||||
|
description='foobar2',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
VLANTranslationPolicy.objects.bulk_create(vlan_translation_policies)
|
||||||
|
|
||||||
|
vlan_translation_rules = (
|
||||||
|
VLANTranslationRule(
|
||||||
|
policy=vlan_translation_policies[0],
|
||||||
|
local_vid=100,
|
||||||
|
remote_vid=200,
|
||||||
|
),
|
||||||
|
VLANTranslationRule(
|
||||||
|
policy=vlan_translation_policies[0],
|
||||||
|
local_vid=101,
|
||||||
|
remote_vid=201,
|
||||||
|
),
|
||||||
|
VLANTranslationRule(
|
||||||
|
policy=vlan_translation_policies[1],
|
||||||
|
local_vid=100,
|
||||||
|
remote_vid=200,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
VLANTranslationRule.objects.bulk_create(vlan_translation_rules)
|
||||||
|
|
||||||
|
def test_policy_id(self):
|
||||||
|
policies = VLANTranslationPolicy.objects.all()[:2]
|
||||||
|
params = {'policy_id': [policies[0].pk]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_local_vid(self):
|
||||||
|
params = {'local_vid': [100]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_remote_vid(self):
|
||||||
|
params = {'remote_vid': [200]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
|
||||||
class ServiceTemplateTestCase(TestCase, ChangeLoggedFilterSetTests):
|
class ServiceTemplateTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
queryset = ServiceTemplate.objects.all()
|
queryset = ServiceTemplate.objects.all()
|
||||||
filterset = ServiceTemplateFilterSet
|
filterset = ServiceTemplateFilterSet
|
||||||
|
Loading…
Reference in New Issue
Block a user