14637 fix tests

This commit is contained in:
Arthur 2024-01-03 14:53:07 -08:00
parent 33d1679001
commit 59a25d6b20
4 changed files with 12 additions and 7 deletions

View File

@ -1,8 +1,6 @@
from datetime import datetime from datetime import datetime, timezone
from django.test import TestCase from django.test import TestCase
from django.utils import timezone
from utilities.testing import ChangeLoggedFilterSetTests from utilities.testing import ChangeLoggedFilterSetTests
from ..choices import * from ..choices import *
from ..filtersets import * from ..filtersets import *

View File

@ -317,10 +317,14 @@ class CableTermination(ChangeLoggedModel):
super().clean() super().clean()
# Check for existing termination # Check for existing termination
existing_termination = CableTermination.objects.exclude(cable=self.cable).filter( qs = existing_termination = CableTermination.objects.filter(
termination_type=self.termination_type, termination_type=self.termination_type,
termination_id=self.termination_id termination_id=self.termination_id
).first() )
if self.cable.pk:
qs = qs.exclude(cable=self.cable)
existing_termination = qs.first()
if existing_termination is not None: if existing_termination is not None:
raise ValidationError( raise ValidationError(
f"Duplicate termination found for {self.termination_type.app_label}.{self.termination_type.model} " f"Duplicate termination found for {self.termination_type.app_label}.{self.termination_type.model} "

View File

@ -1098,7 +1098,10 @@ class Device(
:param if_master: If True, return VC member interfaces only if this Device is the VC master. :param if_master: If True, return VC member interfaces only if this Device is the VC master.
""" """
if self.pk:
filter = Q(device=self) filter = Q(device=self)
else:
filter = Q()
if self.virtual_chassis and (self.virtual_chassis.master == self or not if_master): if self.virtual_chassis and (self.virtual_chassis.master == self or not if_master):
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False) filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
return Interface.objects.filter(filter) return Interface.objects.filter(filter)

View File

@ -182,7 +182,7 @@ class ConfigContextModel(models.Model):
if not hasattr(self, 'config_context_data'): if not hasattr(self, 'config_context_data'):
# The annotation is not available, so we fall back to manually querying for the config context objects # The annotation is not available, so we fall back to manually querying for the config context objects
config_context_data = ConfigContext.objects.get_for_object(self, aggregate_data=True) config_context_data = ConfigContext.objects.get_for_object(self, aggregate_data=True) or []
else: else:
# The attribute may exist, but the annotated value could be None if there is no config context data # The attribute may exist, but the annotated value could be None if there is no config context data
config_context_data = self.config_context_data or [] config_context_data = self.config_context_data or []