From 4ea00474aa555388187c2ca40fd316ab8ed7f572 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Mon, 19 Aug 2024 21:50:16 -0500 Subject: [PATCH] Fix test errors --- netbox/dcim/api/serializers_/device_components.py | 14 +++++++------- netbox/dcim/models/device_components.py | 4 ++-- netbox/utilities/testing/api.py | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/netbox/dcim/api/serializers_/device_components.py b/netbox/dcim/api/serializers_/device_components.py index 9e021272d..fd66f0a1f 100644 --- a/netbox/dcim/api/serializers_/device_components.py +++ b/netbox/dcim/api/serializers_/device_components.py @@ -237,8 +237,8 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect def validate(self, data): - # Validate many-to-many VLAN assignments if not self.nested: + # Validate many-to-many VLAN assignments device = self.instance.device if self.instance else data.get('device') for vlan in data.get('tagged_vlans', []): if vlan.site not in [device.site, None]: @@ -247,12 +247,12 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect f"or it must be global." }) - # Validate that tagged-all payload does not include tagged_vlans - mode = data.get('mode') or self.instance.mode - if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'): - raise serializers.ValidationError({ - 'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans" - }) + # Validate that tagged-all payload does not include tagged_vlans + mode = data.get('mode') or getattr(self.instance, 'mode', None) + if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'): + raise serializers.ValidationError({ + 'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans" + }) return super().validate(data) diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index 951230bff..a785d5db1 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -912,12 +912,12 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd if self.rf_channel and not self.rf_channel_width: self.rf_channel_width = get_channel_attr(self.rf_channel, 'width') + super().save(*args, **kwargs) + # Clear any tagged vlans set when mode is tagged-all if self.mode == InterfaceModeChoices.MODE_TAGGED_ALL and self.tagged_vlans.count(): self.tagged_vlans.set([]) - super().save(*args, **kwargs) - @property def _occupied(self): return super()._occupied or bool(self.wireless_link_id) diff --git a/netbox/utilities/testing/api.py b/netbox/utilities/testing/api.py index 7bb349a66..baa8e2920 100644 --- a/netbox/utilities/testing/api.py +++ b/netbox/utilities/testing/api.py @@ -230,6 +230,8 @@ class APIViewTestCases: obj_perm.object_types.add(ObjectType.objects.get_for_model(self.model)) initial_count = self._get_queryset().count() + print(self._get_list_url()) + print(self.create_data[0]) response = self.client.post(self._get_list_url(), self.create_data[0], format='json', **self.header) self.assertHttpStatus(response, status.HTTP_201_CREATED) self.assertEqual(self._get_queryset().count(), initial_count + 1)