Pass raw request bodies to requests as data - #29
Merged
Merged
Conversation
do_request forwarded raw bodies to requests under the keyword `body`, which requests doesn't accept, so any call with a raw body raised TypeError before anything was sent. upload_dfiq_archive is the only such caller, and could not succeed. The unit test mocked Session.post, which accepts any keyword. It now mocks Session.send, so requests builds the request from the arguments do_request passes, and it checks that the archive bytes reach the request body. A new e2e test uploads an archive to a live Yeti.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
do_requestforwarded raw bodies to requests under the keywordbody. requests has no such argument, so any call with a raw body raisedTypeError: Session.request() got an unexpected keyword argument 'body'before anything was sent.upload_dfiq_archiveis the only method that passes one, so it could never succeed.What changed
do_requestpasses raw bodies asdata, the name requests uses.test_upload_dfiq_archivemockedSession.post, which accepts any keyword, so it passed with the bug in place. It now mocksSession.send, one layer down. That way the realSession.requestbuilds the request from whatdo_requestpasses, and the test checks that the archive bytes reach the request body. Onmainit fails with theTypeErrorabove. The archive is now a real temporary file rather than a patchedbuiltins.open, because requests runs inside the test and may open files of its own, such as~/.netrc.test_upload_dfiq_archiveuploads a one-scenario archive to a live Yeti and looks the scenario up afterwards. Nothing intests/e2e.pyexercised the upload before.Verification
Unit and type checks, run the way CI does after
poetry install --no-root:poetry run python -m unittest tests/api.py: 39 passed. Onmain'syeti/api.py, the updated test errors with theTypeError.poetry run pyrefly check: 0 errorstests/e2e.pyagainst a local Yeti built frommainplus yeti-platform/yeti#1403, using API key auth: 15 passed, including the new test, which errors onmainwith theTypeError.Release
No version bump: 2.4.0, from #28, isn't released yet, and this ships with it.