Refactor helper method from test
This commit is contained in:
parent
9a2bc91a20
commit
370fd54b98
|
|
@ -1,9 +1,13 @@
|
||||||
"""Script defined to create helper functions for graphql schema."""
|
import io
|
||||||
# https://medium.com/@jamesvaresamuel/mutation-and-query-in-graphql-using-python-django-part-2-79d9852a1092
|
import os
|
||||||
|
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
from graphql_relay.node.node import from_global_id
|
from graphql_relay.node.node import from_global_id
|
||||||
|
|
||||||
|
"""Script defined to create helper functions for graphql schema."""
|
||||||
|
|
||||||
|
|
||||||
|
# https://medium.com/@jamesvaresamuel/mutation-and-query-in-graphql-using-python-django-part-2-79d9852a1092
|
||||||
def get_object(object_name, relay_id, otherwise=None):
|
def get_object(object_name, relay_id, otherwise=None):
|
||||||
try:
|
try:
|
||||||
return object_name.objects.get(pk=from_global_id(relay_id)[1])
|
return object_name.objects.get(pk=from_global_id(relay_id)[1])
|
||||||
|
|
@ -31,3 +35,21 @@ def get_errors(e):
|
||||||
messages = ['; '.join(m) for m in e.message_dict.values()]
|
messages = ['; '.join(m) for m in e.message_dict.values()]
|
||||||
errors = [i for pair in zip(fields, messages) for i in pair]
|
errors = [i for pair in zip(fields, messages) for i in pair]
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
|
def get_graphql_query(filename):
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
with io.open(os.path.join(settings.GRAPHQL_QUERIES_DIR, filename)) as f:
|
||||||
|
query = f.read()
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
def get_graphql_mutation(filename):
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
with io.open(os.path.join(settings.GRAPHQL_MUTATIONS_DIR, filename)) as f:
|
||||||
|
mutation = f.read()
|
||||||
|
|
||||||
|
return mutation
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from graphene.test import Client
|
||||||
from graphql_relay import to_global_id
|
from graphql_relay import to_global_id
|
||||||
|
|
||||||
from api.schema import schema
|
from api.schema import schema
|
||||||
|
from api.utils import get_graphql_mutation
|
||||||
from book.factories import ContentBlockFactory
|
from book.factories import ContentBlockFactory
|
||||||
from book.models import ContentBlock
|
from book.models import ContentBlock
|
||||||
|
|
||||||
|
|
@ -21,8 +22,8 @@ class NewContentBlockMutationTest(TestCase):
|
||||||
def test_add_new_content_block(self):
|
def test_add_new_content_block(self):
|
||||||
self.assertEqual(ContentBlock.objects.count(), 1)
|
self.assertEqual(ContentBlock.objects.count(), 1)
|
||||||
client = Client(schema=schema)
|
client = Client(schema=schema)
|
||||||
with io.open(os.path.join(settings.GRAPHQL_MUTATIONS_DIR, 'addContentBlock.gql')) as f:
|
|
||||||
mutation = f.read()
|
mutation = get_graphql_mutation('addContentBlock.gql')
|
||||||
|
|
||||||
executed = client.execute(mutation, variables={
|
executed = client.execute(mutation, variables={
|
||||||
'input': {
|
'input': {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,13 @@ if not DEBUG:
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
'core',
|
||||||
|
'api',
|
||||||
|
'user',
|
||||||
|
'book',
|
||||||
|
'objectives',
|
||||||
|
'rooms',
|
||||||
|
|
||||||
'wagtail.contrib.forms',
|
'wagtail.contrib.forms',
|
||||||
'wagtail.contrib.redirects',
|
'wagtail.contrib.redirects',
|
||||||
'wagtail.embeds',
|
'wagtail.embeds',
|
||||||
|
|
@ -71,13 +78,6 @@ INSTALLED_APPS = [
|
||||||
'graphene_django',
|
'graphene_django',
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
'compressor',
|
'compressor',
|
||||||
|
|
||||||
'core',
|
|
||||||
'api',
|
|
||||||
'user',
|
|
||||||
'book.apps.BookConfig',
|
|
||||||
'objectives',
|
|
||||||
'rooms',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue