make_test_environ_builder was not working correctly with subdomains #604

Closed
wants to merge 1 commit into
from

Conversation

2 participants
@tomasd

tomasd commented Oct 3, 2012

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='<company_id>')
        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('/<company_id>')
        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)
make_test_environ_builder when used with subdomains was not working c…
…orrectly, now it uses urlparse module for detecting full URL and changing path and base_url correctly
@mitsuhiko

This comment has been minimized.

Show comment Hide comment
@mitsuhiko

mitsuhiko Oct 7, 2012

Member

Applied with tests. Thanks.

Member

mitsuhiko commented Oct 7, 2012

Applied with tests. Thanks.

@mitsuhiko mitsuhiko closed this Oct 7, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment