Replace Starlette's TestClient from `requests` to `httpx`! 🎉
Project description
bump-testclient
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.
Why?
Make your life easier. Suggested by Sebastián Ramírez as a joke, but well... I did it.
Transformations
- 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 ` in ("delete", "get", "head", "options"). - Using
content,data,jsonorfilesparameters.
- 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:
dataparameter receives a bytes/text argument.
Installation
pip install bump-testclient
Usage
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
License
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bump_testclient-0.3.0-py3-none-any.whl.
File metadata
- Download URL: bump_testclient-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55139fe9aed45702a0215701ef6d37ad7dd449813bd95e65b58cd7430637964f
|
|
| MD5 |
94ba948011f94c22e6a18099ae05ead3
|
|
| BLAKE2b-256 |
3028b2f62ebcd2fb35892e788c497b2d4d0629d7c83559e8f3855acafaa626f1
|