skillbox/server/books/tests/test_content_blocks.py

49 lines
1.3 KiB
Python

from books.factories import ModuleFactory, ChapterFactory
from books.models import ContentBlock
from core.tests.base_test import SkillboxTestCase
CONTENT_BLOCK_QUERY = """
query ContentBlockQuery($slug: String!) {
module(slug: $slug) {
chapters {
edges {
node {
id
contentBlocks {
id
title
type
}
}
}
}
}
}
"""
class ContentBlockTestCase(SkillboxTestCase):
def setUp(self) -> None:
self.createDefault()
self.client = self.get_client()
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_content_block(self):
result = self.client.execute(CONTENT_BLOCK_QUERY, variables={
"slug": self.slug
})
self.assertIsNone(result.get('errors'))
module = result.get('data').get('module')
content_block = module['chapters']['edges'][0]['node']['contentBlocks'][0]
self.assertEqual(content_block['title'], 'Title')
self.assertIsNotNone(content_block['type'])