Skip to content
Myr

Added more tests for the new stack behavior.

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 307d1bc · Browse files · 3 files+33 added−2 removed
This commit

State

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

Diff stats

3 files+33 added−2 removed

  • other:+33 added−2 removed

3 files+33 added−2 removed

modified:flask/testsuite/appctx.py+23 added-1 removed
16 unmodified lines
171819class AppContextTestCase(FlaskTestCase):2021 def test_basic_support(self):21 def test_basic_url_generation(self):22 app = flask.Flask(__name__)23 app.config['SERVER_NAME'] = 'localhost'24 app.config['PREFERRED_URL_SCHEME'] = 'https'25
4 unmodified lines
30 with app.app_context():31 rv = flask.url_for('index')32 self.assert_equal(rv, 'https://localhost/')3334 def test_url_generation_requires_server_name(self):35 app = flask.Flask(__name__)36 with app.app_context():37 with self.assert_raises(RuntimeError):38 flask.url_for('index')3940 def test_url_generation_without_context_fails(self):41 with self.assert_raises(RuntimeError):42 flask.url_for('index')4344 def test_request_context_means_app_context(self):45 app = flask.Flask(__name__)46 with app.test_request_context():47 self.assert_equal(flask.current_app._get_current_object(), app)48 self.assert_equal(flask._app_ctx_stack.top, None)4950 def test_app_context_provides_current_app(self):51 app = flask.Flask(__name__)52 with app.app_context():53 self.assert_equal(flask.current_app._get_current_object(), app)54 self.assert_equal(flask._app_ctx_stack.top, None)555657def suite():58 suite = unittest.TestSuite()59 suite.addTest(unittest.makeSuite(AppContextTestCase))60 return suite
modified:flask/__init__.py+2 added-1 removed
21 unmodified lines
22from .config import Config23from .helpers import url_for, jsonify, json_available, flash, \24 send_file, send_from_directory, get_flashed_messages, \25 get_template_attribute, make_response, safe_join26from .globals import current_app, g, request, session, _request_ctx_stack26from .globals import current_app, g, request, session, _request_ctx_stack, \27 _app_ctx_stack28from .ctx import has_request_context29from .module import Module30from .blueprints import Blueprint31from .templating import render_template, render_template_string
11 unmodified lines
modified:flask/helpers.py+8 added
198 unmodified lines
199 :param _method: if provided this explicitly specifies an HTTP method.200 """201 appctx = _app_ctx_stack.top202 reqctx = _request_ctx_stack.top203 if appctx is None:204 raise RuntimeError('Attempted to generate a URL with the application '205 'context being pushed. This has to be executed ')206207 # If request specific information is available we have some extra208 # features that support "relative" urls.209 if reqctx is not None:
17 unmodified lines
227 # Otherwise go with the url adapter from the appctx and make228 # the urls external by default.229 else:230 url_adapter = appctx.url_adapter231 if url_adapter is None:232 raise RuntimeError('Application was not able to create a URL '233 'adapter for request independent URL generation. '234 'You might be able to fix this by setting '235 'the SERVER_NAME config variable.')236 external = values.pop('_external', True)237238 anchor = values.pop('_anchor', None)239 method = values.pop('_method', None)
471 unmodified lines