skillbox/server/books/tests/test_module_creation.py

33 lines
1.2 KiB
Python

from django.test import TestCase, RequestFactory
from unittest import skip
from graphene.test import Client
from graphql_relay import to_global_id
from api.schema import schema
from api.utils import get_object
from books.models import ContentBlock, Chapter
from books.factories import ModuleFactory, ModuleLevelFactory, TopicFactory
from core.factories import UserFactory
from users.models import User
class TestModuleCreation(TestCase):
"""
Since the modules url in the frontend is not /topic/module but /module the slug has to be unique.
This test checks if the slug is generated correctly.
"""
def test_create_new_module_generates_slug(self):
topic = TopicFactory(title="Berufslehre")
module = ModuleFactory(title="Modul 1", parent=topic)
self.assertEqual("modul-1", module.slug)
def test_create_new_module_different_topic(self):
topic = TopicFactory(title="Berufslehre")
module = ModuleFactory(title="Modul 1", parent=topic)
topic2 = TopicFactory(title="Geld und Macht")
module2 = ModuleFactory(title="Modul 1", parent=topic2)
self.assertEqual("modul-1", module.slug)
self.assertEqual("modul-1-2", module2.slug, )