1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import test
test.prefer_parent_path()
import cherrypy
def setup_server():
class Root:
def index(self):
return "Hello, world"
index.exposed = True
def dom4(self):
return "Under construction"
dom4.exposed = True
class VHost:
def __init__(self, sitename):
self.sitename = sitename
def index(self):
return "Welcome to %s" % self.sitename
index.exposed = True
cherrypy.root = Root()
cherrypy.root.mydom2 = VHost("Domain 2")
cherrypy.root.mydom3 = VHost("Domain 3")
cherrypy.config.update({
'server.logToScreen': False,
'server.environment': 'production',
'virtual_host_filter.on': True,
'virtual_host_filter.www.mydom2.com': '/mydom2',
'virtual_host_filter.www.mydom3.com': '/mydom3',
'virtual_host_filter.www.mydom4.com': '/dom4',
})
import helper
class VirtualHostFilterTest(helper.CPWebCase):
def testVirtualHostFilter(self):
self.getPage("/", [('Host', 'www.mydom1.com')])
self.assertBody('Hello, world')
self.getPage("/mydom2/", [('Host', 'www.mydom1.com')])
self.assertBody('Welcome to Domain 2')
self.getPage("/", [('Host', 'www.mydom2.com')])
self.assertBody('Welcome to Domain 2')
self.getPage("/", [('Host', 'www.mydom3.com')])
self.assertBody('Welcome to Domain 3')
self.getPage("/", [('Host', 'www.mydom4.com')])
self.assertBody('Under construction')
if __name__ == "__main__":
setup_server()
helper.testmain()
|