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

Convert make_test_environ_builder into class (fixes #3207) #3232

Merged
merged 3 commits into from
May 31, 2019

Conversation

lordmauve
Copy link
Contributor

@lordmauve lordmauve commented May 31, 2019

Added a new class flask.testing.EnvironBuilder inheriting from werkzeug.test.EnvironBuilder.

Logic from make_test_environ_builder() moved to the constructor of that class, and changed to simply instantiate the class, while issuing a DeprecationWarning.

I did explore making json_dumps() a regular method rather than a static method, to pick up app, but if anything was expecting to call EnvironBuilder.json_dumps() as a static method then this would break. Requires funky descriptor tricks to work both as a static method and an instance method under Python 2 and so didn't seem worth the code it would take.

closes #3207

@lordmauve
Copy link
Contributor Author

Tests and stylecheck passed under Tox but somehow the Azure pipelines have not been requested for this PR. (I appear to be on a dodgy internet connection.)

flask/testing.py Outdated

if subdomain:
http_host = "{0}.{1}".format(subdomain, http_host)
if "json" in kwargs:
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to remove this part, since the base EnvironBuilder handles JSON.

Copy link
Contributor Author

@lordmauve lordmauve May 31, 2019

Choose a reason for hiding this comment

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

No, because the base class doesn't know about app and therefore does not take JSON serialisation settings from it.

This could be removed if json_dumps() was added as a method that respects self.app, but this is hard if json_dumps() needs to be callable as a static method as described above. If that's not needed, then yes, I can remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, I'm pretty sure it is a safe assumption that it's not needed. Let me go ahead and do this.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that should work.

@davidism
Copy link
Member

Looks good! Please add a changelog entry as well.

flask/testing.py Outdated Show resolved Hide resolved
@davidism davidism merged commit 5e15850 into pallets:master May 31, 2019
@davidism davidism added this to the 1.1.0 milestone May 31, 2019
@lordmauve lordmauve deleted the environbuilder branch June 3, 2019 17:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert make_test_environ_builder into EnvironBuilder subclass
2 participants