mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -06:00
Fix test errors
This commit is contained in:
parent
282836c9a0
commit
4ea00474aa
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user