77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
from graphql_relay import to_global_id
|
|
|
|
from books.factories import ContentBlockFactory, ModuleFactory, ChapterFactory
|
|
from books.models import ContentBlock
|
|
from core.tests.base_test import SkillboxTestCase
|
|
|
|
DUPLICATE_CONTENT_BLOCK_MUTATION = """
|
|
mutation DuplicateContentBlockMutation($input: DuplicateContentBlockInput!) {
|
|
duplicateContentBlock(input: $input) {
|
|
contentBlock {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|
|
CONTENT_BLOCK_QUERY = """
|
|
query ContentBlockQuery($slug: String!) {
|
|
module(slug: $slug) {
|
|
chapters {
|
|
id
|
|
contentBlocks {
|
|
id
|
|
title
|
|
type
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|
|
|
|
class DuplicateContentBlockTestCase(SkillboxTestCase):
|
|
def setUp(self) -> None:
|
|
self.createDefault()
|
|
#
|
|
self.slug = 'module'
|
|
self.module = ModuleFactory(slug=self.slug)
|
|
self.chapter = ChapterFactory(parent=self.module)
|
|
self.content_block = ContentBlock(
|
|
type=ContentBlock.NORMAL,
|
|
title='Title',
|
|
)
|
|
self.chapter.add_child(instance=self.content_block)
|
|
|
|
def test_duplicate_content_block(self):
|
|
result = self.get_client().execute(CONTENT_BLOCK_QUERY, variables={
|
|
'slug': self.slug
|
|
})
|
|
self.assertIsNone(result.errors)
|
|
module = result.data.get('module')
|
|
chapter = module.get('chapters')[0]
|
|
content_blocks = chapter.get('contentBlocks')
|
|
self.assertEqual(len(content_blocks), 1)
|
|
self.assertEqual(ContentBlock.objects.count(), 1)
|
|
|
|
result = self.get_client().execute(DUPLICATE_CONTENT_BLOCK_MUTATION, variables={
|
|
'input': {
|
|
"id": to_global_id('ContentBlockNode', self.content_block.id)
|
|
}
|
|
})
|
|
self.assertIsNone(result.errors)
|
|
duplicate_content_block = result.data.get('duplicateContentBlock')
|
|
content_block = duplicate_content_block.get('contentBlock')
|
|
# self.assertEqual(content_block['title'], 'Title')
|
|
self.assertIsNotNone(content_block['id'])
|
|
|
|
result = self.get_client().execute(CONTENT_BLOCK_QUERY, variables={
|
|
'slug': self.slug
|
|
})
|
|
self.assertIsNone(result.errors)
|
|
module = result.data.get('module')
|
|
chapter = module.get('chapters')[0]
|
|
content_blocks = chapter.get('contentBlocks')
|
|
self.assertEqual(ContentBlock.objects.count(), 2)
|
|
self.assertEqual(len(content_blocks), 2)
|