Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

root/tags/cherrypy-3.0.0/cherrypy/test/test_tidy.py

Revision 1466 (checked in by fumanchu, 2 years ago)

Initial test_tidy, plus a bugfix in tidy.strict_xml and indent args.

  • Property svn:eol-style set to native
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.config.update({'environment': 'test_suite'})
44     cherrypy.tree.mount(Root())
45
46
47 from cherrypy.test import helper
48
49 class TidyTest(helper.CPWebCase):
50
51     def test_Tidy_Tool(self):
52         if not os.path.exists(tidy_path) and not os.path.exists(tidy_path + ".exe"):
53             print "skipped (tidy not found) ",
54             return
55        
56         self.getPage('/validhtml')
57         self.assertStatus(200)
58         self.assertBody("<html><body><h1>This should be valid</h1></body></html>")
59        
60         self.getPage('/plaintext')
61         self.assertStatus(200)
62         self.assertBody('Hello, world')
63        
64         self.getPage('/warning')
65         self.assertStatus(200)
66         self.assertBody(doctype + "<html><head><title>Meh</title></head>"
67                         "<body>Normal body</body></html>")
68        
69         self.getPage('/warning?skip_doctype=YES')
70         self.assertStatus(200)
71         self.assertInBody("Wrong HTML")
72
73
74
75 if __name__ == "__main__":
76     setup_server()
77     helper.testmain()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets