Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP Headers fixer for Client and RequestFactory. #305

Merged
merged 30 commits into from Feb 17, 2023

Conversation

David-Wobrock
Copy link
Contributor

@David-Wobrock David-Wobrock commented Dec 22, 2022

Fixes #271

At the moment, it's just a first draft, to get the idea.
Some cases are not handled yet, and we will have to decide how far to push the handled cases :)

Used for django/django#16401

) -> Iterable[tuple[Offset, TokenFunc]]:
if (
isinstance(node.func, ast.Name)
and "RequestFactory" in state.from_imports["django.test"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncRequestFactory and AsyncClient are not handled at the moment, as the keyword arguments don't start with HTTP_ I guess they would be harder to catch 🤔

Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just been looking into this now I have the time, and Django 4.2 alpha 1 is out. I've made some fixes, comments on outstanding changes to make.

src/django_upgrade/fixers/test_http_headers.py Outdated Show resolved Hide resolved
src/django_upgrade/fixers/test_http_headers.py Outdated Show resolved Hide resolved
src/django_upgrade/fixers/test_http_headers.py Outdated Show resolved Hide resolved
src/django_upgrade/fixers/test_http_headers.py Outdated Show resolved Hide resolved
@adamchainz
Copy link
Owner

Okay I’ve rewritten the implementation to resolve all noted issues.

Tested against Django before your fixup commit, Sentry, and some of my clients' projects. All worked well on those.

@adamchainz adamchainz enabled auto-merge (squash) February 17, 2023 08:54
@adamchainz adamchainz merged commit 7beb03b into adamchainz:main Feb 17, 2023
@David-Wobrock
Copy link
Contributor Author

Thanks a lot for your help @adamchainz 🙇
Happy to see this merged 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Django 4.2: Rewrite test request factory and client usage to use headers
2 participants