Coverage for tenancy/graphql/types.py: 74%

29 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from typing import TYPE_CHECKING, Annotated 

2 

3import strawberry 

4 

5from extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin 

6from netbox.graphql.types import ( 

7 BaseObjectType, 

8 NestedLtreeGroupObjectType, 

9 OrganizationalObjectType, 

10 PrimaryObjectType, 

11 register_type, 

12) 

13from tenancy import models 

14 

15from .filters import * 

16from .mixins import ContactAssignmentsMixin 

17 

18if TYPE_CHECKING: 18 ↛ 19line 18 didn't jump to line 19 because the condition on line 18 was never true

19 from circuits.graphql.types import CircuitType 

20 from dcim.graphql.types import ( 

21 CableType, 

22 DeviceType, 

23 LocationType, 

24 PowerFeedType, 

25 RackReservationType, 

26 RackType, 

27 SiteType, 

28 VirtualDeviceContextType, 

29 ) 

30 from ipam.graphql.types import ( 

31 AggregateType, 

32 ASNRangeType, 

33 ASNType, 

34 IPAddressType, 

35 IPRangeType, 

36 PrefixType, 

37 RouteTargetType, 

38 VLANType, 

39 VRFType, 

40 ) 

41 from netbox.graphql.types import ContentTypeType 

42 from virtualization.graphql.types import ClusterType, VirtualMachineType 

43 from vpn.graphql.types import L2VPNType, TunnelType 

44 from wireless.graphql.types import WirelessLANType, WirelessLinkType 

45 

46__all__ = ( 

47 'ContactAssignmentType', 

48 'ContactGroupType', 

49 'ContactRoleType', 

50 'ContactType', 

51 'TenantGroupType', 

52 'TenantType', 

53) 

54 

55 

56# 

57# Tenants 

58# 

59 

60@register_type( 

61 models.Tenant, 

62 fields='__all__', 

63 filters=TenantFilter, 

64 pagination=True 

65) 

66class TenantType(ContactsMixin, PrimaryObjectType): 

67 group: Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')] | None 

68 asns: list[Annotated['ASNType', strawberry.lazy('ipam.graphql.types')]] 

69 circuits: list[Annotated['CircuitType', strawberry.lazy('circuits.graphql.types')]] 

70 sites: list[Annotated['SiteType', strawberry.lazy('dcim.graphql.types')]] 

71 vlans: list[Annotated['VLANType', strawberry.lazy('ipam.graphql.types')]] 

72 wireless_lans: list[Annotated['WirelessLANType', strawberry.lazy('wireless.graphql.types')]] 

73 route_targets: list[Annotated['RouteTargetType', strawberry.lazy('ipam.graphql.types')]] 

74 locations: list[Annotated['LocationType', strawberry.lazy('dcim.graphql.types')]] 

75 ip_ranges: list[Annotated['IPRangeType', strawberry.lazy('ipam.graphql.types')]] 

76 rackreservations: list[Annotated['RackReservationType', strawberry.lazy('dcim.graphql.types')]] 

77 racks: list[Annotated['RackType', strawberry.lazy('dcim.graphql.types')]] 

78 vdcs: list[Annotated['VirtualDeviceContextType', strawberry.lazy('dcim.graphql.types')]] 

79 prefixes: list[Annotated['PrefixType', strawberry.lazy('ipam.graphql.types')]] 

80 cables: list[Annotated['CableType', strawberry.lazy('dcim.graphql.types')]] 

81 virtual_machines: list[Annotated['VirtualMachineType', strawberry.lazy('virtualization.graphql.types')]] 

82 vrfs: list[Annotated['VRFType', strawberry.lazy('ipam.graphql.types')]] 

83 asn_ranges: list[Annotated['ASNRangeType', strawberry.lazy('ipam.graphql.types')]] 

84 wireless_links: list[Annotated['WirelessLinkType', strawberry.lazy('wireless.graphql.types')]] 

85 aggregates: list[Annotated['AggregateType', strawberry.lazy('ipam.graphql.types')]] 

86 power_feeds: list[Annotated['PowerFeedType', strawberry.lazy('dcim.graphql.types')]] 

87 devices: list[Annotated['DeviceType', strawberry.lazy('dcim.graphql.types')]] 

88 tunnels: list[Annotated['TunnelType', strawberry.lazy('vpn.graphql.types')]] 

89 ip_addresses: list[Annotated['IPAddressType', strawberry.lazy('ipam.graphql.types')]] 

90 clusters: list[Annotated['ClusterType', strawberry.lazy('virtualization.graphql.types')]] 

91 l2vpns: list[Annotated['L2VPNType', strawberry.lazy('vpn.graphql.types')]] 

92 

93 

94@register_type( 

95 models.TenantGroup, 

96 exclude=['path', 'sort_path'], 

97 filters=TenantGroupFilter, 

98 pagination=True 

99) 

100class TenantGroupType(NestedLtreeGroupObjectType): 

101 parent: Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')] | None 

102 

103 tenants: list[TenantType] 

104 children: list[Annotated['TenantGroupType', strawberry.lazy('tenancy.graphql.types')]] 

105 

106 

107# 

108# Contacts 

109# 

110 

111@register_type( 

112 models.Contact, 

113 fields='__all__', 

114 filters=ContactFilter, 

115 pagination=True 

116) 

117class ContactType(ContactAssignmentsMixin, PrimaryObjectType): 

118 groups: list[Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')]] 

119 

120 

121@register_type( 

122 models.ContactRole, 

123 fields='__all__', 

124 filters=ContactRoleFilter, 

125 pagination=True 

126) 

127class ContactRoleType(ContactAssignmentsMixin, OrganizationalObjectType): 

128 pass 

129 

130 

131@register_type( 

132 models.ContactGroup, 

133 exclude=['path', 'sort_path'], 

134 filters=ContactGroupFilter, 

135 pagination=True 

136) 

137class ContactGroupType(NestedLtreeGroupObjectType): 

138 parent: Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')] | None 

139 

140 contacts: list[ContactType] 

141 children: list[Annotated['ContactGroupType', strawberry.lazy('tenancy.graphql.types')]] 

142 

143 

144@register_type( 

145 models.ContactAssignment, 

146 fields='__all__', 

147 filters=ContactAssignmentFilter, 

148 pagination=True 

149) 

150class ContactAssignmentType(CustomFieldsMixin, TagsMixin, BaseObjectType): 

151 object_type: Annotated['ContentTypeType', strawberry.lazy('netbox.graphql.types')] | None 

152 contact: Annotated['ContactType', strawberry.lazy('tenancy.graphql.types')] | None 

153 role: Annotated['ContactRoleType', strawberry.lazy('tenancy.graphql.types')] | None