Python web port port configuration?

I am trying to write some tests using webtest to test my GAE application for python. The problem I am facing is that the application is listening on port 8080, but I cannot configure the web test to hit this port.

For example, I want to use app.get ('/ getreport') to click http: // localhost: 8080 / getreport . Obviously, it only gets to http: // localhost / getreport.

Is there a way to configure a web test to access a specific port?

+4
source share
3 answers

In config , and I quote

port 

Is required? No, the default is "80"

Defines the port number that will be used for query execution, for example. "8080".

Edit : user clarified that they mean this web test (pythonpaste's) and not the widely used Canoo application, I would not have guessed because the pythonpaste web test is a completely different fish maker, and I quote ...:

With this, you can test your application network without starting an HTTP server, and not a web framework that cuts down fragments of your application, which should be tested. WebTest testing is fully consistent with how the WSGI HTTP server will invoke the application

The HTTP server does not start, there is no concept of "port" - everything is done at the WSGI stage without real TCP / IP and HTTP in the game. Thus, the "application" does not listen on port 8080 (or any other port), and its WSGI entry points are called directly "exactly as if" their HTTP server called them.

If you want to test the actual running HTTP server, you will need the Canoo website (or other equivalent frameworks) and not pythonpaste - the latter will do faster testing, avoiding any overhead at the socket and HTTP layer level, but this way , you cannot test a separate existing server (e.g. GAE SDK).

+2
source

Using the paste.proxy.TransparentProxy method, you can test everything 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....." 
+4
source

I think you do not understand what WebTest does. Something like app.get('/getreport') should not make any requests to localhost on any port. The beauty of WebTest is that it doesn’t require your application to actually run on any server.

Here is a quote from the β€œWhat is it” section in WebTest:

With this, you can test your web applications without starting an HTTP server, and without delving into the web environment, reducing the part of your application that you need to test. WebTest tests are fully equivalent to how the WSGI HTTP server will invoke the application.

+2
source

Source: https://habr.com/ru/post/1308894/


All Articles