Allow to specify subdomain and/or url_scheme in app.test_request_context()

This commit is contained in:
Ivan Velichko 2015-11-20 19:43:49 +03:00
parent 6a6a6d87c2
commit daa3f272da
3 changed files with 52 additions and 5 deletions

View file

@ -45,6 +45,38 @@ class TestToolsTestCase(FlaskTestCase):
rv = c.get('/')
self.assert_equal(rv.data, b'http://localhost/')
def test_specify_url_scheme(self):
app = flask.Flask(__name__)
app.testing = True
@app.route('/')
def index():
return flask.request.url
ctx = app.test_request_context(url_scheme='https')
self.assert_equal(ctx.request.url, 'https://localhost/')
with app.test_client() as c:
rv = c.get('/', url_scheme='https')
self.assert_equal(rv.data, b'https://localhost/')
def test_blueprint_with_subdomain(self):
app = flask.Flask(__name__)
app.testing = True
app.config['SERVER_NAME'] = 'example.com:1234'
app.config['APPLICATION_ROOT'] = '/foo'
bp = flask.Blueprint('company', __name__, subdomain='xxx')
@bp.route('/')
def index():
return flask.request.url
app.register_blueprint(bp)
ctx = app.test_request_context('/', subdomain='xxx')
self.assert_equal(ctx.request.url, 'http://xxx.example.com:1234/foo/')
self.assert_equal(ctx.request.blueprint, bp.name)
with app.test_client() as c:
rv = c.get('/', subdomain='xxx')
self.assert_equal(rv.data, b'http://xxx.example.com:1234/foo/')
def test_redirect_keep_session(self):
app = flask.Flask(__name__)
app.secret_key = 'testing'