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

Changeset 754

Show
Ignore:
Timestamp:
10/27/05 17:31:37
Author:
fumanchu
Message:

New test to avoid future HTTP-verb-dispatch collisions. Needs to be updated if HTTP-verb-dispatch is ever implemented.

Files:

Legend:

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

    r752 r754  
    237237        # which CP will just pipe back out if we tell it to. 
    238238        return cherrypy.request.body 
     239 
     240class Divorce: 
     241    """HTTP Method handlers shouldn't collide with normal method names. 
     242    For example, a GET-handler shouldn't collide with a method named 'get'. 
     243     
     244    If you build HTTP method dispatching into CherryPy, rewrite this class 
     245    to use your new dispatch mechanism and make sure that: 
     246        "GET /divorce HTTP/1.1" maps to divorce.index() and 
     247        "GET /divorce/get?ID=13 HTTP/1.1" maps to divorce.get() 
     248    """ 
     249     
     250    documents = {} 
     251     
     252    def index(self): 
     253        yield "<h1>Choose your document</h1>\n" 
     254        yield "<ul>\n" 
     255        for id, contents in self.documents: 
     256            yield ("    <li><a href='/divorce/get?ID=%s'>%s</a>: %s</li>\n" 
     257                   % (id, id, contents)) 
     258        yield "</ul>" 
     259    index.exposed = True 
     260     
     261    def get(self, ID): 
     262        return ("Divorce document %s: %s" % 
     263                (ID, self.documents.get(ID, "empty"))) 
     264    get.exposed = True 
     265 
     266cherrypy.root.divorce = Divorce() 
     267 
    239268 
    240269class Cookies(Test): 
     
    461490        self.assertStatus('200 OK') 
    462491         
     492        # Test that requests for index methods without a trailing slash 
     493        # get redirected to the same URI path with a trailing slash. 
    463494        self.getPage("/redirect?id=3") 
    464495        self.assert_(self.status in ('302 Found', '303 See Other')) 
     
    664695        # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2 
    665696        self.assertHeader("Content-Length", "0") 
     697         
     698        # For method dispatchers: make sure that an HTTP method doesn't 
     699        # collide with a virtual path atom. If you build HTTP-method 
     700        # dispatching into the core, rewrite these handlers to use 
     701        # your dispatch idioms. 
     702        self.getPage("/divorce/get?ID=13") 
     703        self.assertBody('Divorce document 13: empty') 
     704        self.assertStatus('200 OK') 
     705        self.getPage("/divorce/", method="GET") 
     706        self.assertBody('<h1>Choose your document</h1>\n<ul>\n</ul>') 
     707        self.assertStatus('200 OK') 
    666708     
    667709    def testFavicon(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets