I'm working with WebTest and Pyramid in my application. I want to ensure an HTTPBadRequest is thrown under certain conditions, but WebTest's TestApp is returning an AppError with a message representing the HTTPBadRequest.
AppError: Bad response: 400 Bad Request (not 200 OK or 3xx redirect for ..myEndpoint..) The server could not comply with the request since it is either malformed or otherwise incorrect. Originally my test was written to look for an HTTPBadRequest like this: with self.assertRaises(HTTPBadRequest): response = self.delete(url) However an HTTPBadRequest isn't thrown, instead an AppError is thrown. The below passes: with self.assertRaises(AppError): response = self.delete(url) I noticed on Github AppError only has an init method, and AppError(HTTPBadRequest) isn't valid. https://github.com/Pylons/webtest/blob/master/webtest/app.py#L43 I also couldn't find any documentation for AppError on the WebTest ReadTheDocs, but I found this section: http://webtest.readthedocs.org/en/latest/testapp.html?highlight=exception#what-is-tested-by-default Due to this documentation I tried: with self.assertRaises(AppError): response = self.delete(url, status=400) This prevented an AppError from being returned, but I found I would then have to compare a TestResponse object from WebTest and a Response object from Pyramid (since HTTPException is a subclass of both Response and Exception). It seems like I could compare the two, but the process seemed a bit more complicated than I expected. Is there a better way to ensure my application is throwing an HTTPBadRequest? Thanks, Kevin -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
