Fix test errors

This commit is contained in:
Daniel Sheppard 2024-08-19 21:50:16 -05:00
parent 282836c9a0
commit 4ea00474aa
3 changed files with 11 additions and 9 deletions

View File

@ -237,8 +237,8 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
def validate(self, data): def validate(self, data):
# Validate many-to-many VLAN assignments
if not self.nested: if not self.nested:
# Validate many-to-many VLAN assignments
device = self.instance.device if self.instance else data.get('device') device = self.instance.device if self.instance else data.get('device')
for vlan in data.get('tagged_vlans', []): for vlan in data.get('tagged_vlans', []):
if vlan.site not in [device.site, None]: if vlan.site not in [device.site, None]:
@ -247,12 +247,12 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
f"or it must be global." f"or it must be global."
}) })
# Validate that tagged-all payload does not include tagged_vlans # Validate that tagged-all payload does not include tagged_vlans
mode = data.get('mode') or self.instance.mode mode = data.get('mode') or getattr(self.instance, 'mode', None)
if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'): if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'):
raise serializers.ValidationError({ raise serializers.ValidationError({
'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans" 'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans"
}) })
return super().validate(data) return super().validate(data)

View File

@ -912,12 +912,12 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd
if self.rf_channel and not self.rf_channel_width: if self.rf_channel and not self.rf_channel_width:
self.rf_channel_width = get_channel_attr(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 # Clear any tagged vlans set when mode is tagged-all
if self.mode == InterfaceModeChoices.MODE_TAGGED_ALL and self.tagged_vlans.count(): if self.mode == InterfaceModeChoices.MODE_TAGGED_ALL and self.tagged_vlans.count():
self.tagged_vlans.set([]) self.tagged_vlans.set([])
super().save(*args, **kwargs)
@property @property
def _occupied(self): def _occupied(self):
return super()._occupied or bool(self.wireless_link_id) return super()._occupied or bool(self.wireless_link_id)

View File

@ -230,6 +230,8 @@ class APIViewTestCases:
obj_perm.object_types.add(ObjectType.objects.get_for_model(self.model)) obj_perm.object_types.add(ObjectType.objects.get_for_model(self.model))
initial_count = self._get_queryset().count() 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) response = self.client.post(self._get_list_url(), self.create_data[0], format='json', **self.header)
self.assertHttpStatus(response, status.HTTP_201_CREATED) self.assertHttpStatus(response, status.HTTP_201_CREATED)
self.assertEqual(self._get_queryset().count(), initial_count + 1) self.assertEqual(self._get_queryset().count(), initial_count + 1)