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

make_test_environ_builder: use url_scheme from path if provided #2430

Merged
merged 2 commits into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Major release, unreleased
- The ``flask`` command and ``app.run`` will load environment variables using
from ``.env`` and ``.flaskenv`` files if python-dotenv is installed.
(`#2416`_)
- When passing a full URL to the test client, use the scheme in the URL instead
of the ``PREFERRED_URL_SCHEME``. (`#2436`_)

.. _#1421: https://github.com/pallets/flask/issues/1421
.. _#1489: https://github.com/pallets/flask/pull/1489
Expand Down Expand Up @@ -134,6 +136,7 @@ Major release, unreleased
.. _#2412: https://github.com/pallets/flask/pull/2412
.. _#2414: https://github.com/pallets/flask/pull/2414
.. _#2416: https://github.com/pallets/flask/pull/2416
.. _#2436: https://github.com/pallets/flask/pull/2436

Version 0.12.2
--------------
Expand Down
6 changes: 4 additions & 2 deletions flask/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def make_test_environ_builder(
url_scheme = app.config['PREFERRED_URL_SCHEME']

url = url_parse(path)
base_url = '{0}://{1}/{2}'.format(
url_scheme, url.netloc or http_host, app_root.lstrip('/')
base_url = '{scheme}://{netloc}/{path}'.format(
scheme=url.scheme or url_scheme,
netloc=url.netloc or http_host,
path=app_root.lstrip('/')
)
path = url.path

Expand Down
8 changes: 8 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def index():
assert rv.data == b'https://localhost/'


def test_path_is_url(app):
eb = make_test_environ_builder(app, 'https://example.com/')
assert eb.url_scheme == 'https'
assert eb.host == 'example.com'
assert eb.script_root == ''
assert eb.path == '/'


def test_blueprint_with_subdomain(app, client):
app.config['SERVER_NAME'] = 'example.com:1234'
app.config['APPLICATION_ROOT'] = '/foo'
Expand Down