mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 19:19:22 -06:00
Add GraphQL for tenancy
This commit is contained in:
parent
7256c7050a
commit
881b18f6d0
@ -3,12 +3,14 @@ import graphene
|
|||||||
from circuits.graphql.schema import CircuitsQuery
|
from circuits.graphql.schema import CircuitsQuery
|
||||||
from extras.graphql.schema import ExtrasQuery
|
from extras.graphql.schema import ExtrasQuery
|
||||||
from ipam.graphql.schema import IPAMQuery
|
from ipam.graphql.schema import IPAMQuery
|
||||||
|
from tenancy.graphql.schema import TenancyQuery
|
||||||
|
|
||||||
|
|
||||||
class Query(
|
class Query(
|
||||||
CircuitsQuery,
|
CircuitsQuery,
|
||||||
ExtrasQuery,
|
ExtrasQuery,
|
||||||
IPAMQuery,
|
IPAMQuery,
|
||||||
|
TenancyQuery,
|
||||||
graphene.ObjectType
|
graphene.ObjectType
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
0
netbox/tenancy/graphql/__init__.py
Normal file
0
netbox/tenancy/graphql/__init__.py
Normal file
12
netbox/tenancy/graphql/schema.py
Normal file
12
netbox/tenancy/graphql/schema.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import graphene
|
||||||
|
|
||||||
|
from netbox.graphql.fields import ObjectField, ObjectListField
|
||||||
|
from .types import *
|
||||||
|
|
||||||
|
|
||||||
|
class TenancyQuery(graphene.ObjectType):
|
||||||
|
tenant = ObjectField(TenantType)
|
||||||
|
tenants = ObjectListField(TenantType)
|
||||||
|
|
||||||
|
tenant_group = ObjectField(TenantGroupType)
|
||||||
|
tenant_groups = ObjectListField(TenantGroupType)
|
23
netbox/tenancy/graphql/types.py
Normal file
23
netbox/tenancy/graphql/types.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from tenancy import filtersets, models
|
||||||
|
from netbox.graphql.types import ObjectType, TaggedObjectType
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'TenantType',
|
||||||
|
'TenantGroupType',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TenantType(ObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Tenant
|
||||||
|
fields = '__all__'
|
||||||
|
filterset_class = filtersets.TenantFilterSet
|
||||||
|
|
||||||
|
|
||||||
|
class TenantGroupType(TaggedObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.TenantGroup
|
||||||
|
fields = '__all__'
|
||||||
|
filterset_class = filtersets.TenantGroupFilterSet
|
@ -14,7 +14,7 @@ class AppTest(APITestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
class TenantGroupTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
brief_fields = ['_depth', 'display', 'id', 'name', 'slug', 'tenant_count', 'url']
|
brief_fields = ['_depth', 'display', 'id', 'name', 'slug', 'tenant_count', 'url']
|
||||||
bulk_update_data = {
|
bulk_update_data = {
|
||||||
@ -52,7 +52,7 @@ class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class TenantTest(APIViewTestCases.APIViewTestCase):
|
class TenantTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||||
model = Tenant
|
model = Tenant
|
||||||
brief_fields = ['display', 'id', 'name', 'slug', 'url']
|
brief_fields = ['display', 'id', 'name', 'slug', 'url']
|
||||||
bulk_update_data = {
|
bulk_update_data = {
|
||||||
|
Loading…
Reference in New Issue
Block a user