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

root/branches/cp3-wsgi-remix/test/test_virtualhost.py

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

Removed "filter" from lots of places, including renaming of tests.

  • Property svn:eol-style set to native
Line 
1
2 import test
3 test.prefer_parent_path()
4
5 import cherrypy
6
7 def setup_server():
8     class Root:
9         def index(self):
10             return "Hello, world"
11         index.exposed = True
12        
13         def dom4(self):
14             return "Under construction"
15         dom4.exposed = True
16        
17         def method(self, value):
18             return "You sent %s" % repr(value)
19         method.exposed = True
20    
21     class VHost:
22         def __init__(self, sitename):
23             self.sitename = sitename
24        
25         def index(self):
26             return "Welcome to %s" % self.sitename
27         index.exposed = True
28        
29         def vmethod(self, value):
30             return "You sent %s" % repr(value)
31         vmethod.exposed = True
32    
33    
34     root = Root()
35     root.mydom2 = VHost("Domain 2")
36     root.mydom3 = VHost("Domain 3")
37     cherrypy.tree.mount(root)
38    
39     cherrypy.config.update({
40             'log_to_screen': False,
41             'environment': 'production',
42             'tools.virtual_host.on': True,
43             'tools.virtual_host.www.mydom2.com': '/mydom2',
44             'tools.virtual_host.www.mydom3.com': '/mydom3',
45             'tools.virtual_host.www.mydom4.com': '/dom4',
46     })
47
48 import helper
49
50 class VirtualHostTest(helper.CPWebCase):
51    
52     def testVirtualHost(self):
53         self.getPage("/", [('Host', 'www.mydom1.com')])
54         self.assertBody('Hello, world')
55         self.getPage("/mydom2/", [('Host', 'www.mydom1.com')])
56         self.assertBody('Welcome to Domain 2')
57        
58         self.getPage("/", [('Host', 'www.mydom2.com')])
59         self.assertBody('Welcome to Domain 2')
60         self.getPage("/", [('Host', 'www.mydom3.com')])
61         self.assertBody('Welcome to Domain 3')
62         self.getPage("/", [('Host', 'www.mydom4.com')])
63         self.assertBody('Under construction')
64        
65         # Test GET, POST, and positional params
66         self.getPage("/method?value=root")
67         self.assertBody("You sent 'root'")
68         self.getPage("/vmethod?value=dom2+GET", [('Host', 'www.mydom2.com')])
69         self.assertBody("You sent 'dom2 GET'")
70         self.getPage("/vmethod", [('Host', 'www.mydom3.com')], method="POST",
71                      body="value=dom3+POST")
72         self.assertBody("You sent 'dom3 POST'")
73         self.getPage("/vmethod/pos", [('Host', 'www.mydom3.com')])
74         self.assertBody("You sent 'pos'")
75
76
77 if __name__ == "__main__":
78     setup_server()
79     helper.testmain()
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets