Add test for mutation
This commit is contained in:
parent
1043b647a0
commit
3034f77640
|
|
@ -3,19 +3,19 @@ from graphene.test import Client
|
|||
from graphql_relay import to_global_id
|
||||
|
||||
from api.schema import schema
|
||||
from api.utils import get_graphql_mutation
|
||||
from books.factories import ModuleFactory
|
||||
from books.models import Chapter, ContentBlock
|
||||
from core.tests.base_test import SkillboxTestCase
|
||||
from users.models import User, SchoolClass
|
||||
from users.services import create_users
|
||||
|
||||
|
||||
class OwnContentTestCase(TestCase):
|
||||
class OwnContentTestCase(SkillboxTestCase):
|
||||
def setUp(self):
|
||||
self.module = ModuleFactory()
|
||||
self.chapter = Chapter(title='Hello')
|
||||
self.module.add_child(instance=self.chapter)
|
||||
create_users()
|
||||
self.createDefault()
|
||||
content_block = ContentBlock(title='bla', slug='bla')
|
||||
self.chapter_id = to_global_id('ChapterNode', self.chapter.id)
|
||||
self.chapter.specific.add_child(instance=content_block)
|
||||
|
|
@ -26,6 +26,8 @@ class OwnContentTestCase(TestCase):
|
|||
|
||||
request = RequestFactory().get('/')
|
||||
request.user = self.user
|
||||
assert content_block.id is not None
|
||||
self.content_block_id = to_global_id('ContentBlockNode', content_block.id)
|
||||
|
||||
self.client = Client(schema=schema, context_value=request)
|
||||
|
||||
|
|
@ -64,3 +66,79 @@ class OwnContentTestCase(TestCase):
|
|||
})
|
||||
self.assertEqual(len(result.get('data').get('chapter').get('contentBlocks')), 2)
|
||||
|
||||
def test_mutate_own_content_block(self):
|
||||
query = """
|
||||
query ContentBlockQuery($id: ID!) {
|
||||
contentBlock(id: $id) {
|
||||
contents
|
||||
title
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res = self.get_client().get_result(query, variables={'id': self.content_block_id})
|
||||
self.assertIsNone(res.errors)
|
||||
self.assertEqual(res.data['contentBlock']['title'], 'bla')
|
||||
|
||||
mutation = """
|
||||
mutation MutateContentBlock($input: MutateContentBlockInput!) {
|
||||
mutateContentBlock(input: $input) {
|
||||
contentBlock {
|
||||
contents
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
new_content = {
|
||||
'id': '',
|
||||
'type': 'text_block',
|
||||
'value': {
|
||||
'text': 'new text \n a new line'
|
||||
}
|
||||
}
|
||||
|
||||
variables = {
|
||||
'input': {
|
||||
'id': self.content_block_id,
|
||||
'contentBlock': {
|
||||
'contents': [
|
||||
new_content
|
||||
],
|
||||
'title': 'new title',
|
||||
'type': 'NORMAL'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation_result = self.get_client().get_result(mutation, variables=variables)
|
||||
self.assertIsNone(mutation_result.errors)
|
||||
content_block = mutation_result.data['mutateContentBlock']['contentBlock']
|
||||
self.assertEqual(content_block['title'], 'new title')
|
||||
self.assertEqual(content_block['contents'][0]['value']['text'], '<p>new text</p>\n<p>a new line</p>')
|
||||
|
||||
content_with_list = {
|
||||
'id': '',
|
||||
'type': 'text_block',
|
||||
'value': {
|
||||
'text': '<ul><li>Hallo</li><li>Velo</li></ul>'
|
||||
}
|
||||
}
|
||||
other_variables = {
|
||||
'input': {
|
||||
'id': self.content_block_id,
|
||||
'contentBlock': {
|
||||
'contents': [
|
||||
content_with_list
|
||||
],
|
||||
'title': 'title for list content',
|
||||
'type': 'NORMAL'
|
||||
}
|
||||
}
|
||||
}
|
||||
list_mutation_result = self.get_client().get_result(mutation, variables=other_variables)
|
||||
self.assertIsNone(list_mutation_result.errors)
|
||||
content_block = list_mutation_result.data['mutateContentBlock']['contentBlock']
|
||||
self.assertEqual(content_block['title'], 'title for list content')
|
||||
self.assertEqual(content_block['contents'][0]['value']['text'], '<ul><li>Hallo</li><li>Velo</li></ul>')
|
||||
|
|
|
|||
Loading…
Reference in New Issue