make_test_environ_builder when used with subdomains was not working correctly, now it uses urlparse module for detecting full URL and changing path and base_url correctly

This commit is contained in:
Armin Ronacher 2012-10-07 12:48:19 +02:00
parent 261c4a6aee
commit 4f1cb42123
2 changed files with 44 additions and 1 deletions

View file

@ -15,6 +15,7 @@ from __future__ import with_statement
from contextlib import contextmanager
from werkzeug.test import Client, EnvironBuilder
from flask import _request_ctx_stack
from urlparse import urlparse
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):
@ -22,9 +23,12 @@ def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):
http_host = app.config.get('SERVER_NAME')
app_root = app.config.get('APPLICATION_ROOT')
if base_url is None:
base_url = 'http://%s/' % (http_host or 'localhost')
url = urlparse(path)
base_url = 'http://%s/' % (url.netloc or http_host or 'localhost')
if app_root:
base_url += app_root.lstrip('/')
if url.netloc:
path = url.path
return EnvironBuilder(path, base_url, *args, **kwargs)