Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 136 lines (108 sloc) 4.534 kB
7cbc2e3 Theme support
Sam Ruby authored
1 #!/usr/bin/env python
2
3 import unittest, os, shutil
33e669b @rubys Warn if dependencies can't be tested
authored
4 from planet import config, splice, logger
cb2d6d2 recapture; verify content and xml:lang
Sam Ruby authored
5 from xml.dom import minidom
7cbc2e3 Theme support
Sam Ruby authored
6
7 workdir = 'tests/work/apply'
f338e29 Test case for fancy theme
Sam Ruby authored
8 configfile = 'tests/data/apply/config-%s.ini'
7cbc2e3 Theme support
Sam Ruby authored
9 testfeed = 'tests/data/apply/feed.xml'
10
11 class ApplyTest(unittest.TestCase):
12 def setUp(self):
f338e29 Test case for fancy theme
Sam Ruby authored
13 testfile = open(testfeed)
14 self.feeddata = testfile.read()
15 testfile.close()
16
7cbc2e3 Theme support
Sam Ruby authored
17 try:
18 os.makedirs(workdir)
19 except:
20 self.tearDown()
21 os.makedirs(workdir)
22
23 def tearDown(self):
a5e1fde @rubys MeMeme and html2xhtml plugins
authored
24 shutil.rmtree(os.path.split(workdir)[0])
7cbc2e3 Theme support
Sam Ruby authored
25
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
26 def apply_asf(self):
f338e29 Test case for fancy theme
Sam Ruby authored
27 splice.apply(self.feeddata)
7cbc2e3 Theme support
Sam Ruby authored
28
cb2d6d2 recapture; verify content and xml:lang
Sam Ruby authored
29 # verify that selected files are there
7cbc2e3 Theme support
Sam Ruby authored
30 for file in ['index.html', 'default.css', 'images/foaf.png']:
31 path = os.path.join(workdir, file)
32 self.assertTrue(os.path.exists(path))
2107817 @bazzargh integrated portalocker with htmltmpl
bazzargh authored
33 self.assertTrue(os.stat(path).st_size > 0, file + ' has size 0')
cb2d6d2 recapture; verify content and xml:lang
Sam Ruby authored
34
35 # verify that index.html is well formed, has content, and xml:lang
36 html = open(os.path.join(workdir, 'index.html'))
37 doc = minidom.parse(html)
38 list = []
39 content = lang = 0
40 for div in doc.getElementsByTagName('div'):
41 if div.getAttribute('class') != 'content': continue
42 content += 1
43 if div.getAttribute('xml:lang') == 'en-us': lang += 1
44 html.close()
45 self.assertEqual(12, content)
366fe8b Progress towards accomodating Python 2.2
Sam Ruby authored
46 self.assertEqual(3, lang)
f338e29 Test case for fancy theme
Sam Ruby authored
47
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
48 def test_apply_asf(self):
49 config.load(configfile % 'asf')
50 self.apply_asf()
51
1e3ca39 @rubys Genshi Themes
authored
52 def test_apply_classic_fancy(self):
f338e29 Test case for fancy theme
Sam Ruby authored
53 config.load(configfile % 'fancy')
1e3ca39 @rubys Genshi Themes
authored
54 self.apply_fancy()
55
56 def test_apply_genshi_fancy(self):
57 config.load(configfile % 'genshi')
58 self.apply_fancy()
59
c7bc970 @rubys Allow filters to "tee"
authored
60 def test_apply_filter_html(self):
61 config.load(configfile % 'html')
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
62 self.apply_asf()
c7bc970 @rubys Allow filters to "tee"
authored
63
64 output = open(os.path.join(workdir, 'index.html')).read()
65 self.assertTrue(output.find('/>')>=0)
66
67 output = open(os.path.join(workdir, 'index.html4')).read()
68 self.assertTrue(output.find('/>')<0)
69
a5e1fde @rubys MeMeme and html2xhtml plugins
authored
70 def test_apply_filter_mememe(self):
71 config.load(configfile % 'mememe')
72 self.apply_fancy()
73
74 output = open(os.path.join(workdir, 'index.html')).read()
75 self.assertTrue(output.find('<div class="sidebar"><h2>Memes <a href="memes.atom">')>=0)
76
1e3ca39 @rubys Genshi Themes
authored
77 def apply_fancy(self):
a5e1fde @rubys MeMeme and html2xhtml plugins
authored
78 # drop slow templates unrelated to test at hand
79 templates = config.parser.get('Planet','template_files').split()
80 templates.remove('rss10.xml.tmpl')
81 templates.remove('rss20.xml.tmpl')
82 config.parser.set('Planet','template_files',' '.join(templates))
83
f338e29 Test case for fancy theme
Sam Ruby authored
84 splice.apply(self.feeddata)
85
86 # verify that selected files are there
87 for file in ['index.html', 'planet.css', 'images/jdub.png']:
88 path = os.path.join(workdir, file)
89 self.assertTrue(os.path.exists(path), path)
90 self.assertTrue(os.stat(path).st_size > 0)
91
92 # verify that index.html is well formed, has content, and xml:lang
93 html = open(os.path.join(workdir, 'index.html')).read()
366fe8b Progress towards accomodating Python 2.2
Sam Ruby authored
94 self.assertTrue(html.find('<h1>test planet</h1>')>=0)
95 self.assertTrue(html.find(
96 '<h4><a href="http://example.com/2">Venus</a></h4>')>=0)
33e669b @rubys Warn if dependencies can't be tested
authored
97
3e1c9bc @rubys Output filters
authored
98 def test_apply_filter(self):
99 config.load(configfile % 'filter')
100 splice.apply(self.feeddata)
101
102 # verify that index.html is well formed, has content, and xml:lang
103 html = open(os.path.join(workdir, 'index.html')).read()
104 self.assertTrue(html.find(' href="http://example.com/default.css"')>=0)
105
c2ff924 @rubys Handle case where neither xslt nor genshi are installed
authored
106 import test_filter_genshi
107 for method in dir(test_filter_genshi.GenshiFilterTests):
108 if method.startswith('test_'): break
109 else:
110 delattr(ApplyTest,'test_apply_genshi_fancy')
111
33e669b @rubys Warn if dependencies can't be tested
authored
112 try:
113 import libxml2
114 except ImportError:
115
5abeeeb @rubys Make libxml2 optional again
authored
116 delattr(ApplyTest,'test_apply_filter_mememe')
117
33e669b @rubys Warn if dependencies can't be tested
authored
118 try:
119 import win32pipe
120 (stdin,stdout) = win32pipe.popen4('xsltproc -V', 't')
121 stdin.close()
122 stdout.read()
123 try:
124 exitcode = stdout.close()
125 except IOError:
126 exitcode = -1
127 except:
128 import commands
129 (exitstatus,output) = commands.getstatusoutput('xsltproc -V')
130 exitcode = ((exitstatus>>8) & 0xFF)
131
132 if exitcode:
133 logger.warn("xsltproc is not available => can't test XSLT templates")
134 for method in dir(ApplyTest):
135 if method.startswith('test_'): delattr(ApplyTest,method)
Something went wrong with that request. Please try again.