Question

I’m writing a cherrypy application that needs to redirect to a particular page and I use HTTPRedirect(‘mynewurl’, status=303) to achieve this. This works inasmuch as the browser (Safari) redirects to ‘mynewurl’ without asking the user. However, when I attempt to unit test using nosetests with assertInBody(), I get a different result; assertInBody reports that ‘This resource can be found at mynewurl’ rather than the actual contents of ‘mynewurl’. My question is how can I get nosetests to behave in the same way as a Safari, that is, redirecting to a page without displaying an ‘ask’ message?

Thanks Kevin

Was it helpful?

Solution

With python unit tests, you are basically testing the server. And the correct response from server is the redirect exception and not the redirected page itself. I would recommend you testing this behaviour in two steps:

  1. test if the first page/url throws correctly initialized (code, url) HTTPRedirect exception
  2. test contents of the second page (on which is being redirected)

But of course, if you insist, you can resolve the redirect in Try/Except by yourself by inspecting the exception attributes and calling testing method on target url again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top