I'm using paste to do some functional testing on my 'controllers' in my web.py app. In one case I'm trying to test for a 400 response when a malformed post is made to an API endpoint. Here is what my test looks like:
def test_api_users_index_post_malformed(self):
r = self.testApp.post('/api/users', params={})
assert r.header('Content-Type') == 'application/json'
assert r.status == 400
But I'm getting the following exception:
AppError: Bad response: 400 Bad Request (not 200 OK or 3xx redirect for /api/users)
I see paste has HttpException middleware, but I can't find any examples on how to use it or if its even the right way to go. Any suggestions? Or am I just going about this wrong?
I know I'm tardy to the party, but I ran across this searching for the answer to the same issue. To allow the TestApp to pass non 2xx/3xx responses back you need to tell the request to allow "errors".
def test_api_users_index_post_malformed(self):
r = self.testApp.post('/api/users', params={}, expect_errors=True)
assert r.header('Content-Type') == 'application/json'
assert r.status == 400
Happy Hacking!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With