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

9856 test fixes

This commit is contained in:
Arthur
2024-03-06 14:34:51 -08:00
parent 1052ea5dd4
commit 5ff2c1806d
5 changed files with 8 additions and 17 deletions

View File

@ -51,7 +51,7 @@ class BaseIPAddressFamilyType:
def family(self) -> IPAddressFamilyType: def family(self) -> IPAddressFamilyType:
# Note that self, is an instance of models.IPAddress # Note that self, is an instance of models.IPAddress
# thus resolves to the address family value. # thus resolves to the address family value.
return IPAddressFamilyType(value=self.value, label=f'IPv{self.value}') return IPAddressFamilyType(value=self.family, label=f'IPv{self.family}')
@strawberry_django.type( @strawberry_django.type(
@ -127,8 +127,8 @@ class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType):
address: str address: str
@strawberry_django.field @strawberry_django.field
def nat_outside(self) -> Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]: def nat_outside(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
return self.nat_outside return self.nat_outside.all()
@strawberry_django.field @strawberry_django.field
def tunnel_terminations(self) -> List[Annotated["TunnelTerminationType", strawberry.lazy('vpn.graphql.types')]]: def tunnel_terminations(self) -> List[Annotated["TunnelTerminationType", strawberry.lazy('vpn.graphql.types')]]:

View File

@ -9,7 +9,7 @@ from .types import *
@strawberry.type @strawberry.type
class TenancyQuery: class TenancyQuery:
@strawberry.field @strawberry.field
def circutenantit(self, id: int) -> TenantType: def tenant(self, id: int) -> TenantType:
return models.Tenant.objects.get(id=id) return models.Tenant.objects.get(id=id)
tenant_list: List[TenantType] = strawberry_django.field() tenant_list: List[TenantType] = strawberry_django.field()

View File

@ -184,7 +184,7 @@ class ContactGroupType(OrganizationalObjectType):
@strawberry_django.field @strawberry_django.field
def contacts(self) -> List[ContactType]: def contacts(self) -> List[ContactType]:
return self.clusters.all() return self.contacts.all()
@strawberry_django.type( @strawberry_django.type(

View File

@ -19,6 +19,7 @@ from .base import ModelTestCase
from .utils import disable_warnings from .utils import disable_warnings
from ipam.graphql.types import IPAddressFamilyType from ipam.graphql.types import IPAddressFamilyType
from strawberry.field import StrawberryField
from strawberry.lazy_type import LazyType from strawberry.lazy_type import LazyType
from strawberry.type import StrawberryList, StrawberryOptional from strawberry.type import StrawberryList, StrawberryOptional
from strawberry.union import StrawberryUnion from strawberry.union import StrawberryUnion
@ -478,15 +479,9 @@ class APIViewTestCases:
fields_string += f'{field.name} {{ id }}\n' fields_string += f'{field.name} {{ id }}\n'
elif field.type.of_type == strawberry_django.fields.types.DjangoModelType: elif field.type.of_type == strawberry_django.fields.types.DjangoModelType:
fields_string += f'{field.name} {{ pk }}\n' fields_string += f'{field.name} {{ pk }}\n'
elif field.is_relation: elif hasattr(field, 'is_relation') and field.is_relation:
# Note: StrawberryField types do not have is_relation
fields_string += f'{field.name} {{ id }}\n' fields_string += f'{field.name} {{ id }}\n'
# TODO: Improve field detection logic to avoid nested ArrayFields
elif field.name == 'extra_choices':
continue
# elif type(field.type) is GQLList and not is_string_array:
# # TODO: Come up with something more elegant
# # Temporary hack to support automated testing of reverse generic relations
# fields_string += f'{field_name} {{ id }}\n'
elif inspect.isclass(field.type) and issubclass(field.type, IPAddressFamilyType): elif inspect.isclass(field.type) and issubclass(field.type, IPAddressFamilyType):
fields_string += f'{field.name} {{ value, label }}\n' fields_string += f'{field.name} {{ value, label }}\n'
else: else:

View File

@ -109,10 +109,6 @@ class VMInterfaceType(IPAddressesMixin, ComponentObjectType):
def tagged_vlans(self) -> List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]: def tagged_vlans(self) -> List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]:
return self.tagged_vlans.all() return self.tagged_vlans.all()
@strawberry_django.field
def mac_address(self) -> List[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
return self.mac_address.all()
@strawberry_django.field @strawberry_django.field
def bridge_interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]: def bridge_interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
return self.bridge_interfaces.all() return self.bridge_interfaces.all()