views:

98

answers:

3

I am attempting to write some tests using webtest to test out my python GAE application. The problem I am running into is that the application is listening on port 8080 but I cannot configure webtest to hit that port.

For example, I want to use app.get('/getreport') to hit http://localhost:8080/getreport. Obviously, it hits just thits http:// localhost/getreport.

Is there a way to set up webtest to hit a particular port?

+2  A: 

In config, and I quote,

port

Required? No, defaults is "80"

Defines the port number to use for executing requests, e.g. "8080".

Edit: the user clarified that they mean this webtest (pythonpaste's), not the widely used Canoo application. I wouldn't have guessed, because pythonpaste's webtest is a very different kettle of fish, and I quote...:

With this you can test your web applications without starting an HTTP server, and without poking into the web framework shortcutting pieces of your application that need to be tested. The tests WebTest runs are entirely equivalent to how a WSGI HTTP server would call an application

No HTTP server being started, there is no concept of "port" -- things run in-process, at WSGI level, without actual TCP/IP and HTTP in play. So, the "application" is not listening on port 8080 (or any other port), but rather its WSGI entry points are called directly, "just as if" an HTTP server was calling them.

If you want to test an actual running HTTP server, then you need Canoo's webtest (or other equivalent frameworks), not pythonpaste's -- the latter will make for faster testing by avoiding any socket-layer and HTTP-layer overhead, but you can't test a separate, existing, running server (such as GAE's SDK's) in this way.

Alex Martelli
Sorry, should have been clearer. This is the python version of webtest, confusingly named the same as Canoo's webtest.http://pythonpaste.org/webtest/
MattM
actually it is somewhat possible by handing TestApp a TransparentProxy which is a wsgi application which just forwards http requests wherever you tell it to and returns the responses.
Tom Willis
A: 

I think you're misunderstanding what WebTest does. Something like app.get('/getreport') shouldn't make any kind of request to localhost on any port. The beauty of WebTest is that it doesn't require your app to actually be running on any server.

Here's a quote from the "What This Does" section of the WebTest docs:

With this you can test your web applications without starting an HTTP server, and without poking into the web framework shortcutting pieces of your application that need to be tested. The tests WebTest runs are entirely equivalent to how a WSGI HTTP server would call an application.

Will McCutchen
A: 

With paste.proxy.TransparentProxy you can test anything that responds to an http request...

from webtest import TestApp
from paste.proxy import TransparentProxy
testapp = TestApp(TransparentProxy())
res = testapp.get("http://google.com")
assert res.status=="200 OK","failure....."
Tom Willis