]> git.scottworley.com Git - paperdoorknob/blame - glowfic_test.py
Move get_title() to Thread
[paperdoorknob] / glowfic_test.py
CommitLineData
e6adf6ce
SW
1# paperdoorknob: Print glowfic
2#
3# This program is free software: you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation, version 3.
6
7
8import unittest
9
10from bs4 import BeautifulSoup
11
aa060d9b 12from images import FakeImageStore
94027099 13from glowfic import makeChunk, Thread
62043b2b 14from texify import PandocTexifier
e6adf6ce
SW
15
16
17class TestSplit(unittest.TestCase):
18
19 def testSplit1(self) -> None:
94027099 20 t = Thread(BeautifulSoup(b'''
e6adf6ce
SW
21 <html><body><div class="post-container post-post">
22 The "post"
94027099
SW
23 </div></body></html>''', 'html.parser'))
24 self.assertEqual([list(t.stripped_strings) for t in t.chunkDOMs()],
e6adf6ce
SW
25 [['The "post"']])
26
27 def testSplit2(self) -> None:
94027099 28 t = Thread(BeautifulSoup(b'''
e6adf6ce
SW
29 <html><body>
30 <div class="post-container post-post">The "post"</div>
31 <div class="flat-post-replies">
32 <div class="post-container post-reply">The "reply"</div>
33 </div>
94027099
SW
34 </body></html>''', 'html.parser'))
35 self.assertEqual([list(t.stripped_strings) for t in t.chunkDOMs()],
e6adf6ce
SW
36 [['The "post"'], ['The "reply"']])
37
38 def testSplit3(self) -> None:
94027099 39 t = Thread(BeautifulSoup(b'''
e6adf6ce
SW
40 <html><body>
41 <div class="post-container post-post">The "post"</div>
42 <div class="flat-post-replies">
43 <div class="post-container post-reply">1st reply</div>
44 <div class="post-container post-reply">2nd reply</div>
45 </div>
94027099
SW
46 </body></html>''', 'html.parser'))
47 self.assertEqual([list(t.stripped_strings) for t in t.chunkDOMs()],
e6adf6ce
SW
48 [['The "post"'], ['1st reply'], ['2nd reply']])
49
50
aa060d9b
SW
51class TestMakeChunk(unittest.TestCase):
52
53 def testEmptyContent(self) -> None:
54 with open('testdata/empty-content.html', 'rb') as f:
94027099
SW
55 t = Thread(BeautifulSoup(f, 'html.parser'))
56 c = makeChunk(next(iter(t.chunkDOMs())), FakeImageStore())
aa060d9b
SW
57 self.assertEqual(
58 c.icon,
59 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
60 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
37c47bc2
SW
61 assert c.character
62 assert c.screen_name
63 assert c.author
64 self.assertEqual(list(c.character.stripped_strings), ['Keltham'])
65 self.assertEqual(
66 list(c.screen_name.stripped_strings), ['lawful chaotic'])
67 self.assertEqual(list(c.author.stripped_strings), ['Iarwain'])
aa060d9b
SW
68 self.assertEqual(str(c.content),
69 '<div class="post-content"><p></p></div>')
70
62043b2b
SW
71 self.assertEqual(
72 PandocTexifier("pandoc").texify(c.character), b'{Keltham}\n')
73
aa060d9b 74
21e82200
SW
75class TestThread(unittest.TestCase):
76
77 def testTitle(self) -> None:
78 t = Thread(BeautifulSoup(b'''
79 <html><body>
80 <div class="content-header">
81 <span id="post-title">
82 <a href="/posts/1234">Teh Story!</a>
83 </span>
84 </div>
85 <div class="post-container post-post">The "post"</div>
86 </body></html>''', 'html.parser'))
87 self.assertEqual(t.title(), 'Teh Story!')
88
89
e6adf6ce
SW
90if __name__ == '__main__':
91 unittest.main()