What's the first function Django executes after receiving a request?
I need to put a breakpoint just at the moment Django receives the request and observe the methods being called next, step by step.
For example, I call
localhost:8000/test
where do I insert the very first breakpoint to see how the middleware processes the request?
Related
I'm new to Postman and I am trying to automate usage of these two requests.
The first one is a POST request which returns a JSON with a single key:value pair ("id") in it
The second one is a POST request which just returns 200 OK
So far I've managed to save "id" from the 1st request's response to an environment variable.
However, I still need to do the following:
After sending 1st request, wait about 30 seconds, put "id" from first request in the URL of 2nd request, then send 2nd request.
To wait 30 sec use setTImeout in prerequest script:
setTimeout(()=>{},30000)
This will wait for 30000 second
Now to send the id url you can directly add it to url as {{id}} or in prerequest script add :
pm.request.addQueryParams({key:"id",value:pm.variables.get("id")})
if you want to run the request again and again till you get 200:
add this to test section of request 2
if (pm.response.code !== 200) {
setTimeout(()=>{postman.setNextRequest(pm.info.requestName)},5000)
}
Note: there is a automatic delay between request option in postman you can use that also.
Also setNextRequest works only if you run using newman or colection runner
In the below image, you can find a delay option before you try to run postman.
This option is used to add a delay between requests running in the runner.
You can check my video to learn more about postman runner and request chaining.
Postman Runner and Request Chaining Explained in Detail
I am trying to write automated tests with Postman. I am new to postman automation world so sorry if the question will seem dumb.
In the api that I need to test when I send a request I immediately receive a response with a transactionID, no matter transaction succeeded or not. Along with my request I send a CallbackURL to the server where I expect the actual transaction result to be called back. The server will do a PUT request back to the CallbackURL that I have provided with the transactionID and the actual response or error.
So the question is, can I have such kind of scenarios in my postman tests?
I guess I should run a web server and expose an endpoint which will expect a PUT request and I should get the body of this PUT request in my tests to check it, and respond back to it with success.
In other words, within my script I need to perform the following actions:
Do a request to the server passing a callback URL
check the immediate response from the server and keep the returned transactionID
Have a webserver run with an endpoint that I passed as a callback URL
Expect a request to that endpoint with transactionID and actual response
Check that the response is what I actually expected
Respond to the request with success
I was thinking about Postman Mock server, but seems it is not designed for such usage.
I also think may be I can run some JS Webserver (may be nodeJS) inside the postman Sandbox...
Actually I am very new to postman testing and I am really confused about this kind of issue. Is it even possible to do this with postman or I need something else?
There are some features provided by POSTMAN which can help you to resolve your problem
When you do request to server passing callback URL it gives you transactionID in response. Save that transactionID in environment variable or global variable. Same you can do it for callbackURL.
Eg. pm.environment.set("transactionID", transactionID);
Then you can do the second request where you passed callback URL and transactionID which you have already.
In short in POSTMAN there are features like
Set global and environment variable which helps to pass some values fetched from response to another request.
call other request on success of first request
eg. postman.setnextRequest({{requestname}});
If you can mentioned your problem statement little bit in details it will be easy to answer in better way.
Hope This Will Help You
Is there any way to access the response and request properties of the last run postman call using pm api's. In other words, does postman keep any historical log which is accessible till at least the last request.
Something like:
pm.lastResponse.body or pm.lastRequest.Url
You can save the response from the last call to an environment variable and get it on the next one
http://blog.getpostman.com/2014/01/27/extracting-data-from-responses-and-chaining-requests/
I would like to block or redirect all requests to another service temporarily in django request/response module. However, I do want to do this put a control mechanism at the begining of all service functions. For example there is a sginal request_start which is sent when a request incomes to any restful API. In handler, is it possible to also block these requests or stop django temporarily?
If you want to simply filter requests by context (for example by the URL) or reject all of them, then you can write your own middleware with a process_request method, where you can check for condition(s) and return either None (to continue processing) or HttpResponse with redirect/404/403 (to block processing).
Now, if you want to send signals or perform any other processing, you can do it in another middleware and simply set a proper order in MIDDLEWARE_CLASSES (the "blocking" middleware should be the last).
I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?