Add a test to make sure we can use the Response from pecan

This commit is contained in:
Angus Salkeld 2013-04-30 15:15:32 +10:00
parent 6ff590844e
commit 6e5cb63d7a
2 changed files with 12 additions and 0 deletions

View File

@ -70,6 +70,10 @@ class AuthorsController(RestController):
def get(self, id):
if id == 999:
raise wsme.exc.ClientSideError('Wrong ID')
if id == 911:
return wsme.api.Response(Author(),
status_code=401)
author = Author()
author.id = id
author.firstname = u"aname"

View File

@ -87,6 +87,14 @@ class TestWS(FunctionalTest):
self.assertEqual(res.status, '400 Bad Request')
assert '<faultcode>Client</faultcode>' in res.body
def test_non_default_response(self):
res = self.app.get(
'/authors/911.json',
expect_errors=True
)
self.assertEqual(res.status_int, 401)
self.assertEqual(res.status, '401 Unauthorized')
def test_serversideerror(self):
res = self.app.get('/divide_by_zero.json', expect_errors=True)
self.assertEqual(res.status, '500 Internal Server Error')