开发者

fake random requests to get same result

'netrecorder' is great to fake web request once and replay it for testing but it's good only for static contents. I came across this scenario where I've to fake random requests. Get same tweets but faked as random twitter users

Let's say our twitter user is randomly generated. Then we 'RECORD_WEB' our first request to get tweets of user '12345'. Now, if i try using netreco开发者_如何学Pythonrder in normal mode then the user_id(say 'abcd') of both request and response won't be matched as its generated randomly.

It would be nice to get same result in normal mode while only the user specific parameters being faked. Is there any other solution for this?


I'd write code to associate the two requests and store the association in a temporary file, DB or in-memory data structure, like a hash. Then you can walk that structure and know which user equals the temporary ID.

Writing test code often opens multiple cans of worms like this, which is why we end up writing twice as much code for the tests and the application, than we would if we only wrote the application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜