]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | import unittest | |
9 | ||
10 | from bs4 import BeautifulSoup | |
11 | ||
aa060d9b SW |
12 | from images import FakeImageStore |
13 | from glowfic import chunkDOMs, makeChunk | |
e6adf6ce SW |
14 | |
15 | ||
16 | class TestSplit(unittest.TestCase): | |
17 | ||
18 | def testSplit1(self) -> None: | |
19 | soup = BeautifulSoup(b''' | |
20 | <html><body><div class="post-container post-post"> | |
21 | The "post" | |
22 | </div></body></html>''', 'html.parser') | |
23 | self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)], | |
24 | [['The "post"']]) | |
25 | ||
26 | def testSplit2(self) -> None: | |
27 | soup = BeautifulSoup(b''' | |
28 | <html><body> | |
29 | <div class="post-container post-post">The "post"</div> | |
30 | <div class="flat-post-replies"> | |
31 | <div class="post-container post-reply">The "reply"</div> | |
32 | </div> | |
33 | </body></html>''', 'html.parser') | |
34 | self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)], | |
35 | [['The "post"'], ['The "reply"']]) | |
36 | ||
37 | def testSplit3(self) -> None: | |
38 | soup = BeautifulSoup(b''' | |
39 | <html><body> | |
40 | <div class="post-container post-post">The "post"</div> | |
41 | <div class="flat-post-replies"> | |
42 | <div class="post-container post-reply">1st reply</div> | |
43 | <div class="post-container post-reply">2nd reply</div> | |
44 | </div> | |
45 | </body></html>''', 'html.parser') | |
46 | self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)], | |
47 | [['The "post"'], ['1st reply'], ['2nd reply']]) | |
48 | ||
49 | ||
aa060d9b SW |
50 | class TestMakeChunk(unittest.TestCase): |
51 | ||
52 | def testEmptyContent(self) -> None: | |
53 | with open('testdata/empty-content.html', 'rb') as f: | |
54 | soup = BeautifulSoup(f, 'html.parser') | |
55 | c = makeChunk(next(iter(chunkDOMs(soup))), FakeImageStore()) | |
56 | self.assertEqual( | |
57 | c.icon, | |
58 | 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' + | |
59 | 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png') | |
60 | self.assertEqual(c.character, 'Keltham') | |
61 | self.assertEqual(c.screen_name, 'lawful chaotic') | |
62 | self.assertEqual(c.author, 'Iarwain') | |
63 | self.assertEqual(str(c.content), | |
64 | '<div class="post-content"><p></p></div>') | |
65 | ||
66 | ||
e6adf6ce SW |
67 | if __name__ == '__main__': |
68 | unittest.main() |