41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
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)
|