summaryrefslogtreecommitdiff
path: root/cherrypy/test/test_wsgi_vhost.py
blob: 2b6e5ba90944ab91cd7ff3e52ee91fdd38b62d38 (plain)
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
import cherrypy
from cherrypy.test import helper


class WSGI_VirtualHost_Test(helper.CPWebCase):

    @staticmethod
    def setup_server():

        class ClassOfRoot(object):

            def __init__(self, name):
                self.name = name

            @cherrypy.expose
            def index(self):
                return 'Welcome to the %s website!' % self.name

        default = cherrypy.Application(None)

        domains = {}
        for year in range(1997, 2008):
            app = cherrypy.Application(ClassOfRoot('Class of %s' % year))
            domains['www.classof%s.example' % year] = app

        cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))

    def test_welcome(self):
        if not cherrypy.server.using_wsgi:
            return self.skip('skipped (not using WSGI)... ')

        for year in range(1997, 2008):
            self.getPage(
                '/', headers=[('Host', 'www.classof%s.example' % year)])
            self.assertBody('Welcome to the Class of %s website!' % year)