Coverage for netbox_data_import/graphql/schema.py: 96.00%

25 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-10-30 09:47 +0000

1# SPDX-License-Identifier: Apache-2.0 

2# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com> 

3 

4"""GraphQL queries registered with NetBox.""" 

5 

6import strawberry 

7import strawberry_django 

8from strawberry.permission import BasePermission 

9 

10from netbox_data_import import branching 

11 

12from .types import CableClassMappingType, ImportProfileType, PortClassMappingType 

13 

14 

15class MainOnly(BasePermission): 

16 """Refuse a plugin field on the same terms as the plugin's REST and UI views.""" 

17 

18 def has_permission(self, source, info, **kwargs) -> bool: 

19 """Raise BranchActive, whose message becomes the GraphQL error, for a refused request.""" 

20 message = branching.request_refusal(info.context.request) 

21 if message is not None: 

22 raise branching.BranchActive(message) 

23 return True 

24 

25 

26@strawberry.type(name="Query") 

27class ImportProfilesQuery: 

28 """Expose import profile detail and list queries.""" 

29 

30 import_profile: ImportProfileType = strawberry_django.field(permission_classes=[MainOnly]) 

31 import_profile_list: list[ImportProfileType] = strawberry_django.field(permission_classes=[MainOnly]) 

32 

33 

34@strawberry.type(name="Query") 

35class CableClassMappingsQuery: 

36 """Expose CableClass mapping detail and list queries.""" 

37 

38 cable_class_mapping: CableClassMappingType = strawberry_django.field(permission_classes=[MainOnly]) 

39 cable_class_mapping_list: list[CableClassMappingType] = strawberry_django.field(permission_classes=[MainOnly]) 

40 

41 

42@strawberry.type(name="Query") 

43class PortClassMappingsQuery: 

44 """Expose PortClass mapping detail and list queries.""" 

45 

46 port_class_mapping: PortClassMappingType = strawberry_django.field(permission_classes=[MainOnly]) 

47 port_class_mapping_list: list[PortClassMappingType] = strawberry_django.field(permission_classes=[MainOnly]) 

48 

49 

50schema = [ImportProfilesQuery, CableClassMappingsQuery, PortClassMappingsQuery] 

51 

52__all__ = ("CableClassMappingsQuery", "ImportProfilesQuery", "PortClassMappingsQuery", "schema")