Starlette 0.21.0 changed the TestClient
implementation: it replaced the requests
library with httpx
.
As those libraries have different APIs, this change break tests for Starlette's users.
This codemod makes the transition to Starlette 0.21.0 easier. It makes the changes needed to make the tests work again.
Make your life easier. Suggested by Sebastián RamÃrez as a joke, but well... I did it.
- Replace
client.<method>(...)
byclient.request("<method>", ...)
The methods ("delete", "get", "head", "options") doesn't accept the content
, data
, json
and files
parameters.
Conditions for this transformation:
- Using
client.<method>
and<method>
in ("delete", "get", "head", "options"). - Using
content
,data
,json
orfiles
parameters.
- Replace
client.<method>(..., allow_redirects=...)
byclient.<method>(..., follow_redirects=...)
HTTPX uses follow_redirects
instead of allow_redirects
.
- Replace
client.<method>(..., data=...)
byclient.<method>(..., content=...)
If the argument passed to data
is either text or bytes, content
should be used instead.
Conditions for this to happen:
data
parameter receives a bytes/text argument.
pip install bump-testclient
Run the following on the repository you want to format:
python -m bump_testclient <files>
You can also use the pre-commit. Add the following to your .pre-commit-config.yaml
file:
- repo: https://github.com/Kludex/bump-testclient
rev: 0.3.0
hooks:
- id: bump_testclient
This project is licensed under the terms of the MIT license.