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

Changeset 757

Show
Ignore:
Timestamp:
10/28/05 19:09:25
Author:
fumanchu
Message:

Enable complete testing of virtual roots. Set test.helper.vroot to "/vpath", for example, to run the whole test suite using that as a virtual mount point.

Files:

Legend:

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

    r699 r757  
    7171 
    7272 
     73class VirtualRootFilter: 
     74     
     75    def __init__(self, prefix): 
     76        self.prefix = prefix 
     77     
     78    def onStartResource(self): 
     79        path = cherrypy.request.path 
     80        if path.startswith(self.prefix): 
     81            cherrypy.request.objectPath = path[len(self.prefix):] 
     82vroot = "" 
     83test_vrf = VirtualRootFilter(vroot) 
     84 
     85 
    7386class CPWebCase(webtest.WebCase): 
    7487     
     
    131144        cherrypy.root._cpOnError = onerror 
    132145         
     146        if vroot: 
     147            url = vroot + url 
     148            filters = getattr(cherrypy.root, "_cpFilterList", None) 
     149            if filters is None: 
     150                cherrypy.root._cpFilterList = filters = [] 
     151            if test_vrf not in filters: 
     152                filters.append(test_vrf) 
     153         
    133154        if cherrypy.server.httpserver is None: 
    134155            self._getRequest(url, headers, method, body) 
  • trunk/cherrypy/test/test_core.py

    r755 r757  
    3838class Root: 
    3939     
    40     _cpFilterList = [] 
    41      
    4240    def index(self): 
    4341        return "hello" 
    4442    index.exposed = True 
     43     
     44    def andnow(self): 
     45        return "the larch" 
     46    andnow.exposed = True 
    4547     
    4648    def _global(self): 
     
    101103    def bad(self): 
    102104        cherrypy.response.status = "error" 
    103         return "hello
     105        return "bad news
    104106 
    105107 
     
    140142 
    141143 
    142 class Slash(Test): 
    143     def index(self): 
    144         return "slashed!" 
    145  
    146 class VPrefix: 
    147     def __init__(self, prefix): 
    148         self.prefix = prefix 
    149     def onStartResource(self): 
    150         path = cherrypy.request.path 
    151         if path.startswith(self.prefix): 
    152             cherrypy.request.objectPath = path[len(self.prefix):] 
    153 cherrypy.root._cpFilterList.append(VPrefix("/vpath")) 
    154  
    155  
    156144class Image(Test): 
    157145     
     
    188176     
    189177    def page_yield(self): 
    190         yield "hello
     178        yield "howdy
    191179        raise ValueError() 
    192180     
    193181    def page_streamed(self): 
    194         yield "hello
     182        yield "word up
    195183        raise ValueError() 
    196184        yield "very oops" 
     
    308296    def index(self): 
    309297        existing = repr(getattr(cherrypy.request, "asdf", None)) 
    310         cherrypy.request.asdf = "hello
     298        cherrypy.request.asdf = "rassfrassin
    311299        return existing 
    312300 
     
    510498        # Test that requests for index methods without a trailing slash 
    511499        # get redirected to the same URI path with a trailing slash. 
     500        # Make sure GET params are preserved. 
    512501        self.getPage("/redirect?id=3") 
    513502        self.assert_(self.status in ('302 Found', '303 See Other')) 
     
    565554        self.assertStatus('303 See Other') 
    566555        self.assertInBody('/errpage') 
    567          
    568         # Trailing slash redirect on a virtualpath child. 
    569         self.getPage("/vpath/slash") 
    570         self.assertStatus('303 See Other') 
    571         self.assertInBody('/vpath/slash/') 
    572556     
    573557    def testCPFilterList(self): 
     
    607591                # started, the status should not change to an error status. 
    608592                self.assertStatus("200 OK") 
    609                 self.assertBody("helloUnrecoverable error in the server.") 
     593                self.assertBody("word upUnrecoverable error in the server.") 
    610594             
    611595            # No traceback should be present 

Hosted by WebFaction

Log in as guest/cpguest to create tickets