Add a first test

This commit is contained in:
Ramon Wenger 2018-09-10 12:04:07 +02:00
parent 9362fdb4e2
commit 7142e3f3b1
3 changed files with 51 additions and 8 deletions

View File

View File

@ -0,0 +1,40 @@
import io
import os
from django.test import TestCase
from graphene.test import Client
from graphql_relay import to_global_id
from api.schema import schema
from book.factories import ContentBlockFactory
from book.models import ContentBlock
from django.conf import settings
class NewContentBlockMutationTest(TestCase):
def setUp(self):
content_block = ContentBlockFactory()
self.sibling_id = to_global_id('ContentBlock', content_block.pk)
def test_add_new_content_block(self):
self.assertEqual(ContentBlock.objects.count(), 1)
client = Client(schema=schema)
with io.open(os.path.join(settings.GRAPHQL_MUTATIONS_DIR, 'addContentBlock.gql')) as f:
mutation = f.read()
executed = client.execute(mutation, variables={
'input': {
"contentBlock": {
"title": "Hello World", "contents": [
{
"type": "text_block",
"text": "Hello there"
}
]
},
"after": self.sibling_id
}
})
self.assertEqual(ContentBlock.objects.count(), 2)

View File

@ -43,13 +43,6 @@ if not DEBUG:
# Application definition
INSTALLED_APPS = [
'core',
'api',
'user',
'book',
'objectives',
'rooms',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
@ -78,6 +71,13 @@ INSTALLED_APPS = [
'graphene_django',
'django_extensions',
'compressor',
'core',
'api',
'user',
'book.apps.BookConfig',
'objectives',
'rooms',
]
if DEBUG:
@ -332,4 +332,7 @@ if DEBUG:
]
# http://docs.wagtail.io/en/v2.1/advanced_topics/settings.html?highlight=urls
WAGTAIL_SITE_NAME = 'skillBox'
WAGTAIL_SITE_NAME = 'skillbox'
GRAPHQL_QUERIES_DIR = os.path.join(BASE_DIR, '..', 'client', 'src', 'graphql', 'gql')
GRAPHQL_MUTATIONS_DIR = os.path.join(GRAPHQL_QUERIES_DIR, 'mutations')