Fix unit test

This commit is contained in:
Ramon Wenger 2024-04-15 14:17:29 +02:00
parent be4dac3b51
commit eeb0664a25
1 changed files with 13 additions and 14 deletions

View File

@ -1,31 +1,30 @@
from books.factories import ModuleFactory, ChapterFactory from books.factories import ModuleFactory
from books.models import ContentBlock, Chapter, ModulePageForm from books.models import Chapter
from core.tests.base_test import SkillboxTestCase from core.tests.base_test import SkillboxTestCase
from django.test.client import Client from django.test.client import Client
from users.models import User
class TestChapterCreation(SkillboxTestCase): class TestChapterCreation(SkillboxTestCase):
""" Test created for Issue MS-932 """ """Test created for Issue MS-932"""
def setUp(self) -> None: def setUp(self) -> None:
self.createDefault() self.createDefault()
self.module = ModuleFactory(slug="my-module") self.module = ModuleFactory(slug="my-module")
user = User.objects.get(username='admin')
self.Client = Client() self.Client = Client()
self.client.login(username='admin', password='test') self.client.login(username="admin", password="test")
def test_create_chapter_creates_slug_autmatically(self): def test_create_chapter_creates_slug_automatically(self):
new_chapter = Chapter(title='New Chapter') new_chapter = Chapter(title="New Chapter")
self.module.add_child(instance=new_chapter) self.module.add_child(instance=new_chapter)
new_chapter.save() new_chapter.save()
self.assertEqual('new-chapter', new_chapter.slug) self.assertEqual("new-chapter", new_chapter.slug)
def test_create_chapter_creates_slug_autmatically_if_existing(self): def test_create_chapter_creates_slug_automatically_if_existing(self):
new_chapter = Chapter(title='New Chapter') new_chapter = Chapter(title="New Chapter")
self.module.add_child(instance=new_chapter) self.module.add_child(instance=new_chapter)
new_chapter.save() new_chapter.save()
self.assertEqual('new-chapter', new_chapter.slug) self.assertEqual("new-chapter", new_chapter.slug)
new_chapter2 = Chapter(title='New Chapter') new_chapter2 = Chapter(title="New Chapter")
self.module.add_child(instance=new_chapter2) self.module.add_child(instance=new_chapter2)
new_chapter2.save() new_chapter2.save()
self.assertEqual('new-chapter-2', new_chapter2.slug) self.assertEqual("new-chapter-2", new_chapter2.slug)