vcrpy
vcrpy copied to clipboard
fix(aiohttp): record body of first request in redirect chain
The first could be e.g. a POST with one, only the remaining ones are expected to be GETs without one.
Codecov Report
Merging #581 (d39f580) into master (6e04003) will increase coverage by
3.09%. The diff coverage is94.73%.
@@ Coverage Diff @@
## master #581 +/- ##
==========================================
+ Coverage 89.01% 92.11% +3.09%
==========================================
Files 24 27 +3
Lines 1539 1712 +173
Branches 212 239 +27
==========================================
+ Hits 1370 1577 +207
+ Misses 139 97 -42
- Partials 30 38 +8
| Impacted Files | Coverage Δ | |
|---|---|---|
| vcr/stubs/aiohttp_stubs.py | 94.30% <88.23%> (ø) |
|
| vcr/stubs/httpx_stubs.py | 97.80% <97.80%> (ø) |
|
| vcr/__init__.py | 100.00% <100.00%> (ø) |
|
| vcr/cassette.py | 97.15% <100.00%> (+0.98%) |
:arrow_up: |
| vcr/config.py | 95.00% <100.00%> (+0.03%) |
:arrow_up: |
| vcr/patch.py | 89.41% <100.00%> (+5.04%) |
:arrow_up: |
| vcr/record_mode.py | 100.00% <100.00%> (ø) |
|
| vcr/serializers/jsonserializer.py | 100.00% <100.00%> (ø) |
|
| vcr/serializers/yamlserializer.py | 77.77% <0.00%> (-22.23%) |
:arrow_down: |
| vcr/migration.py | 74.48% <0.00%> (-2.05%) |
:arrow_down: |
| ... and 7 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update c79a06f...d39f580. Read the comment docs.
Rebased.
@scop I'm not really familiar with the aiohttp code. How sure are you that this it the right thing?
@kevin1024 @scop Do you have any interest in helping out with maintainership?
I don't think anyone is very actively maintaining right now, and I really have not used vcrpy in years. I think we'd all really appreciate if you could step in.
I am very confident that this is the right thing to do. If not done, the request body of a POST that results in a redirect is recorded as null.
Notably, at least for example for requests, the body is recorded.
Small reproducer:
$ cat test.py
import asyncio
import aiohttp
import requests
import vcr
with vcr.use_cassette("redirect_requests.yaml"):
response = requests.post("https://httpbingo.org/redirect-to",
params={"url": "https://vcrpy.readthedocs.io"},
data={"hello": "world"})
async def do_aiohttp():
async with aiohttp.ClientSession() as session:
async with session.post("https://httpbingo.org/redirect-to",
params={"url": "https://vcrpy.readthedocs.io"},
data={"hello": "world"}) as response:
text = response.text
with vcr.use_cassette("redirect_aiohttp.yaml"):
asyncio.get_event_loop().run_until_complete(do_aiohttp())
$ python ./test.py
$ head -n 3 redirect_requests.yaml
interactions:
- request:
body: hello=world
$ head -n 3 redirect_aiohttp.yaml
interactions:
- request:
body: null
With regards to maintainership, I think there's a lot of value having vcrpy around, and it should be used a lot more than it currently is. In a sense I am interested, but I already have so much on my plate already that I cannot commit to being around to help out consistently, and I don't want to raise false hopes. My own vcrpy usage is currently a bit sporadic, too, but it's possible that'll change some in the foreseeable future. Anyway I'll keep this in mind.
Anything more I can do to help getting this merged?
I gotcha. Thanks for your contribution.
Thanks!