mitsuhiko/flask — pull request #604 by tomasd (2012-10-03 09:18:39+00:00)
Title: make_test_environ_builder was not working correctly with subdomains

url_for creates full URL when used for route with subdomain. This is not processed in in make_test_environ_builder, which expects absolute URL without domain.

I've update the code to parse domain with url_parse and change path and base_url correctly.

Here is a test which should pass afterward:

from unittest import TestCase
import flask

class SubdomainTestCase(TestCase):
def setUp(self):
self.app = flask.Flask(__name__)
self.app.config['SERVER_NAME'] = 'example.com'
self.client = self.app.test_client()

self._ctx = self.app.test_request_context()
self._ctx.push()

def tearDown(self):
if self._ctx is not None:
self._ctx.pop()

def test_subdomain(self):
@self.app.route('/', subdomain='')
def view(company_id):
return company_id

url = flask.url_for('view', company_id='xxx')
response = self.client.get(url)

self.assertEquals(200, response.status_code)
self.assertEquals('xxx', response.data)

def test_nosubdomain(self):
@self.app.route('/')
def view(company_id):
return company_id

url = flask.url_for('view', company_id='xxx')
response = self.client.get(url)

self.assertEquals(200, response.status_code)
self.assertEquals('xxx', response.data)