Non-standard HTTP methods with WebTest

38 views
Skip to first unread message

Joel

unread,
Nov 27, 2012, 1:10:19 AM11/27/12
to pylons-...@googlegroups.com
I'm creating a REST-ish web service with Pylons 1.0 (Python 2.6, WebTest 1.4.2.  Search is an important part of the app.  I have decided to implement two ways of accessing the search method of my resource: 1. POST /resources/search and 2. SEARCH /resources.  I know the SEARCH method for HTTP is non-standard so that's why I have the POST interface also.  If someone has a better idea about how I should be structuring the search interface, please let me know.

Anyways, for my nosetests from within my TestController I've been calling self.app.request(url('resources'), method='SEARCH', body=jsonSearchParams) to simulate the request to SEARCH /resources.  This works except that WSGIWarnings are polluting the output complaining about the unknown http method.  I've sidestepped this by adding 'SEARCH' to the valid_methods tuple in webtest/lint.py but obviously this is a pretty hacky solution.

Is there a better way to test non-standard http methods with WebTest/nosetests without generating warnings?  Is it as simple as changing something in the nosetests section of setup.cfg?  (I've tried playing around with the values of verbose, verbosity and detailed-errors but no success.)  Should I be using a different approach altogether?  Advice appreciated.  Thanks,

Joel

Joel

unread,
Nov 27, 2012, 10:52:44 PM11/27/12
to pylons-...@googlegroups.com
Calling the following function before any tests are run appears to prevent WSGIWarnings being issued by WebTest.  Now at least anyone running my tests will not need to manually edit WebTest ...

    def addSEARCHToWebTestValidMethods():
        new_valid_methods = list(webtest.lint.valid_methods)
        new_valid_methods.append('SEARCH')
        new_valid_methods = tuple(new_valid_methods)
        webtest.lint.valid_methods = new_valid_methods
Reply all
Reply to author
Forward
0 new messages