Chris Miles wrote:
> 
> On 08/01/2009, at 5:51 AM, csismondo wrote:
> 
>> I have a controller that I want to build unit test for, the controller
>> is a web-based REST api, and I would like to know what you guys would
>> recommend for a module.
> 
> I'm using the TestController that comes with a Pylons template project  
> for RESTful HTTP controller testing.  This uses webtest as mentioned  
> by Jorge.  In the tests you can just use calls like:
> 
>      response = self.app.post(url('/new_app_submit'),  
> params=dict(app_name='testapp1', app_desc='Test app #1'))
>      response = self.app.put(url('/app/testapp1/purchases/user1/ 
> productA'))
>      response = self.app.get(url('/app/testapp1/purchases'))
> 
> and test the response object for each case. e.g:  
> self.failUnlessEqual(response.status, '200 OK')
> 
> If you need a more thorough example of code just call out.

Note that WebTest automatically tests for a response code of 2xx or 3xx 
-- 4xx or 5xx will raise an error.  So you don't really need 
failUnlessEqual, and you can always assert the response code like:

self.app.post(..., status=200) # e.g., 204 No Content would be an error
self.app.post('/random', status=404)

-- 
Ian Bicking : [email protected] : http://blog.ianbicking.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to