Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / lore / test / test_slides.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.lore.slides}.
6 """
7
8 from xml.dom.minidom import Element, Text
9
10 from twisted.trial.unittest import TestCase
11 from twisted.lore.slides import HTMLSlide, splitIntoSlides, insertPrevNextLinks
12
13
14 class SlidesTests(TestCase):
15     """
16     Tests for functions in L{twisted.lore.slides}.
17     """
18     def test_splitIntoSlides(self):
19         """
20         L{splitIntoSlides} accepts a document and returns a list of two-tuples,
21         each element of which contains the title of a slide taken from an I{h2}
22         element and the body of that slide.
23         """
24         parent = Element('html')
25         body = Element('body')
26         parent.appendChild(body)
27
28         first = Element('h2')
29         text = Text()
30         text.data = 'first slide'
31         first.appendChild(text)
32         body.appendChild(first)
33         body.appendChild(Element('div'))
34         body.appendChild(Element('span'))
35
36         second = Element('h2')
37         text = Text()
38         text.data = 'second slide'
39         second.appendChild(text)
40         body.appendChild(second)
41         body.appendChild(Element('p'))
42         body.appendChild(Element('br'))
43
44         slides = splitIntoSlides(parent)
45
46         self.assertEqual(slides[0][0], 'first slide')
47         firstContent = slides[0][1]
48         self.assertEqual(firstContent[0].tagName, 'div')
49         self.assertEqual(firstContent[1].tagName, 'span')
50         self.assertEqual(len(firstContent), 2)
51
52         self.assertEqual(slides[1][0], 'second slide')
53         secondContent = slides[1][1]
54         self.assertEqual(secondContent[0].tagName, 'p')
55         self.assertEqual(secondContent[1].tagName, 'br')
56         self.assertEqual(len(secondContent), 2)
57
58         self.assertEqual(len(slides), 2)
59
60
61     def test_insertPrevNextText(self):
62         """
63         L{insertPrevNextLinks} appends a text node with the title of the
64         previous slide to each node with a I{previous} class and the title of
65         the next slide to each node with a I{next} class.
66         """
67         next = Element('span')
68         next.setAttribute('class', 'next')
69         container = Element('div')
70         container.appendChild(next)
71         slideWithNext = HTMLSlide(container, 'first', 0)
72
73         previous = Element('span')
74         previous.setAttribute('class', 'previous')
75         container = Element('div')
76         container.appendChild(previous)
77         slideWithPrevious = HTMLSlide(container, 'second', 1)
78
79         insertPrevNextLinks(
80             [slideWithNext, slideWithPrevious], None, None)
81
82         self.assertEqual(
83             next.toxml(), '<span class="next">second</span>')
84         self.assertEqual(
85             previous.toxml(), '<span class="previous">first</span>')