Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 261c4a6 · Browse files · 2 files+44 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+44 added−1 removed

  • other:+44 added−1 removed

2 files+44 added−1 removed

modified:flask/testsuite/testing.py+39 added
196 unmodified lines
197 self.assert_equal(called, [None])198 self.assert_equal(called, [None, None])199200201class SubdomainTestCase(FlaskTestCase):202203 def setUp(self):204 self.app = flask.Flask(__name__)205 self.app.config['SERVER_NAME'] = 'example.com'206 self.client = self.app.test_client()207208 self._ctx = self.app.test_request_context()209 self._ctx.push()210211 def tearDown(self):212 if self._ctx is not None:213 self._ctx.pop()214215 def test_subdomain(self):216 @self.app.route('/', subdomain='<company_id>')217 def view(company_id):218 return company_id219220 url = flask.url_for('view', company_id='xxx')221 response = self.client.get(url)222223 self.assertEquals(200, response.status_code)224 self.assertEquals('xxx', response.data)225226227 def test_nosubdomain(self):228 @self.app.route('/<company_id>')229 def view(company_id):230 return company_id231232 url = flask.url_for('view', company_id='xxx')233 response = self.client.get(url)234235 self.assertEquals(200, response.status_code)236 self.assertEquals('xxx', response.data)237238239def suite():240 suite = unittest.TestSuite()241 suite.addTest(unittest.makeSuite(TestToolsTestCase))242 suite.addTest(unittest.makeSuite(SubdomainTestCase))243 return suite
modified:flask/testing.py+5 added-1 removed
13 unmodified lines
1415from contextlib import contextmanager16from werkzeug.test import Client, EnvironBuilder17from flask import _request_ctx_stack18from urlparse import urlparse192021def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):22 """Creates a new test builder with some application defaults thrown in."""23 http_host = app.config.get('SERVER_NAME')24 app_root = app.config.get('APPLICATION_ROOT')25 if base_url is None:26 url = urlparse(path)25 base_url = 'http://%s/' % (http_host or 'localhost')27 base_url = 'http://%s/' % (url.netloc or http_host or 'localhost')28 if app_root:29 base_url += app_root.lstrip('/')30 if url.netloc:31 path = url.path32 return EnvironBuilder(path, base_url, *args, **kwargs)333435class FlaskClient(Client):
87 unmodified lines