From 5ff2c1806dc5ba9e33d33cb55b6f735374172da7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 6 Mar 2024 14:34:51 -0800 Subject: [PATCH] 9856 test fixes --- netbox/ipam/graphql/types.py | 6 +++--- netbox/tenancy/graphql/schema.py | 2 +- netbox/tenancy/graphql/types.py | 2 +- netbox/utilities/testing/api.py | 11 +++-------- netbox/virtualization/graphql/types.py | 4 ---- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/netbox/ipam/graphql/types.py b/netbox/ipam/graphql/types.py index 283dd3e30..bae8ec686 100644 --- a/netbox/ipam/graphql/types.py +++ b/netbox/ipam/graphql/types.py @@ -51,7 +51,7 @@ class BaseIPAddressFamilyType: def family(self) -> IPAddressFamilyType: # Note that self, is an instance of models.IPAddress # 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( @@ -127,8 +127,8 @@ class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType): address: str @strawberry_django.field - def nat_outside(self) -> Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]: - return self.nat_outside + def nat_outside(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]: + return self.nat_outside.all() @strawberry_django.field def tunnel_terminations(self) -> List[Annotated["TunnelTerminationType", strawberry.lazy('vpn.graphql.types')]]: diff --git a/netbox/tenancy/graphql/schema.py b/netbox/tenancy/graphql/schema.py index 80e77cc82..0fd541c5d 100644 --- a/netbox/tenancy/graphql/schema.py +++ b/netbox/tenancy/graphql/schema.py @@ -9,7 +9,7 @@ from .types import * @strawberry.type class TenancyQuery: @strawberry.field - def circutenantit(self, id: int) -> TenantType: + def tenant(self, id: int) -> TenantType: return models.Tenant.objects.get(id=id) tenant_list: List[TenantType] = strawberry_django.field() diff --git a/netbox/tenancy/graphql/types.py b/netbox/tenancy/graphql/types.py index 77c7cfea8..f64015f33 100644 --- a/netbox/tenancy/graphql/types.py +++ b/netbox/tenancy/graphql/types.py @@ -184,7 +184,7 @@ class ContactGroupType(OrganizationalObjectType): @strawberry_django.field def contacts(self) -> List[ContactType]: - return self.clusters.all() + return self.contacts.all() @strawberry_django.type( diff --git a/netbox/utilities/testing/api.py b/netbox/utilities/testing/api.py index d07b54a36..15c96d568 100644 --- a/netbox/utilities/testing/api.py +++ b/netbox/utilities/testing/api.py @@ -19,6 +19,7 @@ from .base import ModelTestCase from .utils import disable_warnings from ipam.graphql.types import IPAddressFamilyType +from strawberry.field import StrawberryField from strawberry.lazy_type import LazyType from strawberry.type import StrawberryList, StrawberryOptional from strawberry.union import StrawberryUnion @@ -478,15 +479,9 @@ class APIViewTestCases: fields_string += f'{field.name} {{ id }}\n' elif field.type.of_type == strawberry_django.fields.types.DjangoModelType: 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' - # 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): fields_string += f'{field.name} {{ value, label }}\n' else: diff --git a/netbox/virtualization/graphql/types.py b/netbox/virtualization/graphql/types.py index a263a8d9d..86a7d4b2c 100644 --- a/netbox/virtualization/graphql/types.py +++ b/netbox/virtualization/graphql/types.py @@ -109,10 +109,6 @@ class VMInterfaceType(IPAddressesMixin, ComponentObjectType): def tagged_vlans(self) -> List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]: 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 def bridge_interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]: return self.bridge_interfaces.all()