CherryPy Project Download

root/test_tidy.py

Revision 7 (checked in by fumanchu, 4 years ago)

Dropping the tidy and nsgmls Tools here after being ripped out of the CherryPy distro.

Line 
1 from cherrypy.test import test
2 test.prefer_parent_path()
3
4 import os
5 localDir = os.path.join(os.getcwd(), os.path.dirname(__file__))
6 tidy_path = os.path.join(localDir, "tidy")
7
8 import cherrypy
9 from cherrypy import tools
10
11 doctype = ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
12            '"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">')
13
14 def setup_server():
15     class Root:
16         _cp_config = {
17             'tools.tidy.on': True,
18             'tools.tidy.tidy_path': tidy_path,
19             'tools.tidy.temp_dir': localDir,
20             }
21        
22         def plaintext(self):
23             yield "Hello, world"
24         plaintext.exposed = True
25         plaintext._cp_config = {'tools.tidy.warnings': False}
26        
27         def validhtml(self):
28             return "<html><body><h1>This should be valid</h1></body></html>"
29         validhtml.exposed = True
30         validhtml._cp_config = {'tools.tidy.warnings': False}
31        
32         def warning(self, skip_doctype=False):
33             if skip_doctype:
34                 # This should raise a warning
35                 pass
36             else:
37                 yield doctype
38            
39             yield "<html><head><title>Meh</title></head>"
40             yield "<body>Normal body</body></html>"
41         warning.exposed = True
42    
43     cherrypy.tree.mount(Root())
44
45
46 from cherrypy.test import helper
47
48 class TidyTest(helper.CPWebCase):
49
50     def test_Tidy_Tool(self):
51         if not os.path.exists(tidy_path) and not os.path.exists(tidy_path + ".exe"):
52             return self.skip("skipped (tidy not found) ")
53        
54         self.getPage('/validhtml')
55         self.assertStatus(200)
56         self.assertBody("<html><body><h1>This should be valid</h1></body></html>")
57        
58         self.getPage('/plaintext')
59         self.assertStatus(200)
60         self.assertBody('Hello, world')
61        
62         self.getPage('/warning')
63         self.assertStatus(200)
64         self.assertBody(doctype + "<html><head><title>Meh</title></head>"
65                         "<body>Normal body</body></html>")
66        
67         self.getPage('/warning?skip_doctype=YES')
68         self.assertStatus(200)
69         self.assertInBody("Wrong HTML")
70
71
72
73 if __name__ == "__main__":
74     helper.testmain()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages