[Testing] How to assert on the requests served #1075
-
We use proxy.py in our test suite, and it's really great. While we do have requests flowing through the proxy, how can I have a record of the requests it serves so my test code can assert on them? If there isn't some easy/official way to support this, perhaps I could be pointed to what attributes in the code I could pytest.monkeypatch onto to make my own record as calls to that attribute occur. What would you recommend? We currently use it simply like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@bmbouter Here is one option that came to my mind. CacheResponsesPluginOne option is to use Next, you will need a way to access this cached file path. Luckily, it's available as Finally, to make this all work in your test environment
Monkey PatchYou can of-course monkey patch too. But:
Let me know if it helps. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for this clear and great reply. I'll give this a try! |
Beta Was this translation helpful? Give feedback.
@bmbouter Here is one option that came to my mind.
CacheResponsesPlugin
One option is to use
CacheResponsesPlugin
. By default it will write upstream responses in a file per request. Recently,--cache-requests
flag was also added. When used, plugin will also dump request packets in the same file written per request.Next, you will need a way to access this cached file path. Luckily, it's available as
cache_file_path
within access log context dictionary. Just for reference, this log context is populated from here https://github.com/abhinavsingh/proxy.py/blob/develop/proxy/plugin/cache/cache_responses.py#L54Finally, to make this all work in your test environment