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

Extended GraphQL tests to include all fields

This commit is contained in:
jeremystretch
2021-06-29 11:20:54 -04:00
parent bd1e019a42
commit 7deabfe9cd
3 changed files with 52 additions and 16 deletions

View File

@ -7,7 +7,7 @@ from django.urls import reverse
from rest_framework import status
from rest_framework.utils import formatting
from netbox.api.exceptions import SerializerNotFound
from netbox.api.exceptions import GraphQLTypeNotFound, SerializerNotFound
from .utils import dynamic_import
@ -24,10 +24,22 @@ def get_serializer_for_model(model, prefix=''):
return dynamic_import(serializer_name)
except AttributeError:
raise SerializerNotFound(
"Could not determine serializer for {}.{} with prefix '{}'".format(app_name, model_name, prefix)
f"Could not determine serializer for {app_name}.{model_name} with prefix '{prefix}'"
)
def get_graphql_type_for_model(model):
"""
Return the GraphQL type class for the given model.
"""
app_name, model_name = model._meta.label.split('.')
class_name = f'{app_name}.graphql.types.{model_name}Type'
try:
return dynamic_import(class_name)
except AttributeError:
raise GraphQLTypeNotFound(f"Could not find GraphQL type for {app_name}.{model_name}")
def is_api_request(request):
"""
Return True of the request is being made via the REST API.