class TestHtmlBody(unittest.TestCase): def setUp(self): self.Document = Document() self.DocumentWithChapter = Document() self.FirstChapterTitle = "this is the first chapter title" self.FirstChapter = Chapter(self.FirstChapterTitle) self.FirstChapterText = "this is text in the first chapter" self.FirstChapter.addText(self.FirstChapterText) self.DocumentWithChapter.addChapter(self.FirstChapter) self.SecondChapterTitle = "this is the second chapter title" self.SecondChapter = Chapter(self.SecondChapterTitle) self.DocumentWithChapter.addChapter(self.SecondChapter) def test_htmlPageHasBodyTag(self): page = getHtmlBody(self.Document) self.assertRegex(page, "<body>.*</body>") def test_htmlPageHasFirstChapter(self): page = getHtmlBody(self.DocumentWithChapter) self.assertRegex( page, f"<body><h1>{self.FirstChapterTitle}</h1>.*</body>") def test_htmlPageHasFirstChapterWithCorrectText(self): page = getHtmlBody(self.DocumentWithChapter) self.assertRegex( page, f".*</h1>{self.FirstChapterText}.*") def test_htmlPageHasSecondChapter(self): page = getHtmlBody(self.DocumentWithChapter) self.assertRegex( page, f"<body><h1>.*</h1>.*<h1>{self.SecondChapterTitle}</h1>.*</body>")
def setUp(self): self.Document = Document() self.DocumentWithChapter = Document() self.FirstChapterTitle = "this is the first chapter title" self.FirstChapter = Chapter(self.FirstChapterTitle) self.FirstChapterText = "this is text in the first chapter" self.FirstChapter.addText(self.FirstChapterText) self.DocumentWithChapter.addChapter(self.FirstChapter) self.SecondChapterTitle = "this is the second chapter title" self.SecondChapter = Chapter(self.SecondChapterTitle) self.DocumentWithChapter.addChapter(self.SecondChapter)
def test_canAddMoreText(self): chap = Chapter() text1 = "text1 blahBlah" chap.addText(text1) text2 = "text2 blahBlah" chap.addText(text2) self.assertIn(text1, chap.Text) self.assertIn(text2, chap.Text)
def test_ChapterHasTitle(self): title = "This is my title" chap = Chapter(title) self.assertEqual(chap.Title, title)
def test_chapter(self): chap = Chapter() self.assertIsNotNone(chap)
def test_canAddList(self): chap = Chapter() data = [] data.append("item 1") chap.addList(data) self.assertIn(data, chap.Lists)
def test_ChapterCanAddText(self): text = "blahBlah" chap = Chapter() chap.addText(text) self.assertIn(text, chap.Text)
def test_ChapterCanLiveWithoutTitle(self): chap = Chapter() self.assertEqual(chap.Title, None)
def test_AddChapterToDocument(self): doc = Document() chapterTitle = "A new beginning" chapter = Chapter(chapterTitle) doc.addChapter(chapter) self.assertIn(chapter, doc.Chapters)