1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Clean up exemption logic

This commit is contained in:
Jeremy Stretch
2024-03-11 15:44:47 -04:00
parent 313e63622b
commit f8744a6659
3 changed files with 5 additions and 23 deletions

View File

@ -3235,7 +3235,7 @@ class PowerOutletTestCase(TestCase, DeviceComponentFilterSetTests, ChangeLoggedF
class InterfaceTestCase(TestCase, DeviceComponentFilterSetTests, ChangeLoggedFilterSetTests):
queryset = Interface.objects.all()
filterset = InterfaceFilterSet
ignore_fields = ('untagged_vlan', 'vdcs')
ignore_fields = ('tagged_vlans', 'untagged_vlan', 'vdcs')
@classmethod
def setUpTestData(cls):

View File

@ -19,21 +19,7 @@ __all__ = (
'ChangeLoggedFilterSetTests',
)
IGNORE_MODELS = (
('core', 'AutoSyncRecord'),
('core', 'ManagedFile'),
('core', 'ObjectType'),
('dcim', 'CablePath'),
('extras', 'Branch'),
('extras', 'CachedValue'),
('extras', 'Dashboard'),
('extras', 'ScriptModule'),
('extras', 'StagedChange'),
('extras', 'TaggedItem'),
('users', 'UserConfig'),
)
IGNORE_FIELDS = (
EXEMPT_MODEL_FIELDS = (
'comments',
'custom_field_data',
'level', # MPTT
@ -117,10 +103,6 @@ class BaseFilterSetTests:
model = self.queryset.model
model_name = model.__name__
# Skip ignored models
if (app_label, model_name) in IGNORE_MODELS:
return
# Import the FilterSet class & sanity check it
filterset = import_string(f'{app_label}.filtersets.{model_name}FilterSet')
self.assertEqual(model, filterset.Meta.model, "FilterSet model does not match!")
@ -135,14 +117,14 @@ class BaseFilterSetTests:
continue
# Skip ignored fields
if model_field.name in chain(self.ignore_fields, IGNORE_FIELDS):
if model_field.name in chain(self.ignore_fields, EXEMPT_MODEL_FIELDS):
continue
# Skip reverse ForeignKey relationships
if type(model_field) is ManyToOneRel:
continue
# TODO: Generic relationships
# Skip generic relationships
if type(model_field) in (GenericForeignKey, GenericRelation):
continue

View File

@ -522,7 +522,7 @@ class VirtualMachineTestCase(TestCase, ChangeLoggedFilterSetTests):
class VMInterfaceTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = VMInterface.objects.all()
filterset = VMInterfaceFilterSet
ignore_fields = ('untagged_vlan',)
ignore_fields = ('tagged_vlans', 'untagged_vlan',)
@classmethod
def setUpTestData(cls):