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

Changeset 1910

Show
Ignore:
Timestamp:
03/07/08 16:19:28
Author:
fumanchu
Message:

Test for #755 (trailing_slash not working for static files in 3.1 beta).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_static.py

    r1839 r1910  
    2525            return "This is a DYNAMIC page" 
    2626        dynamic.exposed = True 
    27  
    28  
     27     
     28     
     29    cherrypy.config.update({'environment': 'test_suite'}) 
     30     
    2931    root = Root() 
    3032    root.static = Static() 
    3133     
    32     conf = { 
     34    rootconf = { 
    3335        '/static': { 
    3436            'tools.staticdir.on': True, 
     
    5153        }, 
    5254        } 
     55    rootApp = cherrypy.Application(root) 
     56    rootApp.merge(rootconf) 
    5357     
    54     cherrypy.tree.mount(root, config=conf) 
    55     cherrypy.config.update({'environment': 'test_suite'}) 
     58    test_app_conf = { 
     59        '/test': { 
     60            'tools.staticdir.index': 'index.html', 
     61            'tools.staticdir.on': True, 
     62            'tools.staticdir.root': curdir, 
     63            'tools.staticdir.dir': 'static', 
     64            }, 
     65        } 
     66    testApp = cherrypy.Application(Static()) 
     67    testApp.merge(test_app_conf) 
     68     
     69    vhost = cherrypy._cpwsgi.VirtualHost(rootApp, {'virt.net': testApp}) 
     70    cherrypy.tree.graft(vhost) 
     71 
    5672 
    5773def teardown_server(): 
     
    92108        #   we just check the content 
    93109        self.assertMatchesBody('^Dummy stylesheet') 
    94          
     110     
     111    def test_fallthrough(self): 
    95112        # Test that NotFound will then try dynamic handlers (see [878]). 
    96113        self.getPage("/static/dynamic") 
     
    102119        self.assertHeader('Content-Type', 'text/html') 
    103120        self.assertBody('You want the Baron? You can have the Baron!') 
    104          
     121     
     122    def test_index(self): 
    105123        # Check a directory via "staticdir.index". 
    106124        self.getPage("/docroot/") 
     
    114132        self.assertBody("This resource can be found at <a href='%s/docroot/'>" 
    115133                        "%s/docroot/</a>." % (self.base(), self.base())) 
    116          
     134     
     135    def test_config_errors(self): 
    117136        # Check that we get an error if no .file or .dir 
    118137        self.getPage("/error/thing.html") 
     
    120139        self.assertInBody("TypeError: staticdir() takes at least 2 " 
    121140                          "arguments (0 given)") 
    122          
     141     
     142    def test_security(self): 
    123143        # Test up-level security 
    124144        self.getPage("/static/../../test/style.css") 
    125145        self.assertStatus((400, 403)) 
    126          
     146     
     147    def test_modif(self): 
    127148        # Test modified-since on a reasonably-large file 
    128149        self.getPage("/static/dirback.jpg") 
     
    139160        self.assertNoHeader("Content-Disposition") 
    140161        self.assertBody("") 
     162     
     163    def test_755_vhost(self): 
     164        self.getPage("/test/", [('Host', 'virt.net')]) 
     165        self.assertStatus(200) 
     166        self.getPage("/test", [('Host', 'virt.net')]) 
     167        self.assertStatus((302, 303)) 
     168        self.assertHeader('Location', 'http://virt.net/test/') 
    141169 
    142170 

Hosted by WebFaction

Log in as guest/cpguest to create tickets