Add tests for createion over wagtail admin

This commit is contained in:
Lorenz Padberg 2024-04-10 15:09:31 +02:00
parent acaeae0cf7
commit a883f94591
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
from books.factories import ModuleFactory, ChapterFactory
from books.models import ContentBlock, Chapter, ModulePageForm
from core.tests.base_test import SkillboxTestCase
from django.test.client import Client
from users.models import User
class TestChapterCreation(SkillboxTestCase):
""" Test created for Issue MS-932 """
def setUp(self) -> None:
self.createDefault()
self.module = ModuleFactory(slug="my-module")
user = User.objects.get(username='admin')
self.Client = Client()
self.client.login(username='admin', password='test')
def test_create_chapter_creates_slug_autmatically(self):
new_chapter = Chapter(title='New Chapter')
self.module.add_child(instance=new_chapter)
new_chapter.save()
self.assertEqual('new-chapter', new_chapter.slug)
def test_create_chapter_creates_slug_autmatically_if_existing(self):
new_chapter = Chapter(title='New Chapter')
self.module.add_child(instance=new_chapter)
new_chapter.save()
self.assertEqual('new-chapter', new_chapter.slug)
new_chapter2 = Chapter(title='New Chapter')
self.module.add_child(instance=new_chapter2)
new_chapter2.save()
self.assertEqual('new-chapter-2', new_chapter2.slug)
def test_add_chapter_in_admin(self):
data = {
'title': 'New Chapter',
'slug': 'new-chapter-test',
'module': self.module.id
}
response = self.client.post(f"/cms/pages/add/books/chapter/{self.module.id}", data=data)
self.assertEqual(200, response.status_code)
chapter = Chapter.objects.get(title='New Chapter')
self.assertEqual("new-chapter-test", chapter.slug)
def test_add_chapter_in_admin_no_slug(self):
data = {
'title': 'New Chapter',
'module': self.module.id
}
response = self.client.post(f"/cms/pages/add/books/chapter/{self.module.id}", data=data)
self.assertEqual(200, response.status_code)
chapter = Chapter.objects.get(title='New Chapter')
self.assertEqual("new-chapter", chapter.slug)