Cleanup test_blueprint.py to use test fixtures
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Modify several tests to use the app and client test fixtures.
authored by Randy Liou · committed by Randy Liou · parent 39f7aaa · Browse files · 1 file·+10 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+10 added−18 removed
- tests:+10 added−18 removed
Provenance
- Commit
c03a827- Tree
5de014f- Author
Randy Liou <dawran6@gmail.com>- Committer
Randy Liou <dawran6@gmail.com>- Parent
39f7aaa
1 file changed+10 added−18 removed
modified:tests/test_blueprints.py+10 added-18 removed
200 unmodified lines201 with flask.Flask(__name__).test_request_context():202 assert flask.render_template('nested/nested.txt') == 'I\'m nested'203 204 205-def test_default_static_cache_timeout():206- app = flask.Flask(__name__)207-205+def test_default_static_cache_timeout(app):206 class MyBlueprint(flask.Blueprint):207 def get_send_file_max_age(self, filename):208 return 100209 447 unmodified lines657 rv = client.get('/')658 assert b'Success!' in rv.data659 660 663-def test_context_processing():664- app = flask.Flask(__name__)661+def test_context_processing(app, client):662 answer_bp = flask.Blueprint('answer_bp', __name__)663 664 template_string = lambda: flask.render_template_string(665 '{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}'21 unmodified lines687 688 # Register the blueprint689 app.register_blueprint(answer_bp)690 694- c = app.test_client()691+ app_page_bytes = client.get('/').data692+ answer_page_bytes = client.get('/bp').data693 696- app_page_bytes = c.get('/').data697- answer_page_bytes = c.get('/bp').data698-694 assert b'43' in app_page_bytes695 assert b'42' not in app_page_bytes696 697 assert b'42' in answer_page_bytes698 assert b'43' in answer_page_bytes699 700 706-def test_template_global():707- app = flask.Flask(__name__)701+def test_template_global(app):702 bp = flask.Blueprint('bp', __name__)703 704 @bp.app_template_global()705 def get_answer():11 unmodified lines717 with app.app_context():718 rv = flask.render_template_string('{{ get_answer() }}')719 assert rv == '42'720 727-def test_request_processing():728- app = flask.Flask(__name__)721+def test_request_processing(app, client):722 bp = flask.Blueprint('bp', __name__)723 evts = []724 @bp.before_request725 def before_bp():14 unmodified lines740 741 app.register_blueprint(bp)742 743 assert evts == []751- rv = app.test_client().get('/bp')744+ rv = client.get('/bp')745 assert rv.data == b'request|after'746 assert evts == ['before', 'after', 'teardown']747 755-def test_app_request_processing():756- app = flask.Flask(__name__)748+def test_app_request_processing(app, client):749 bp = flask.Blueprint('bp', __name__)750 evts = []751 752 @bp.before_app_first_request21 unmodified lines774 # before first request775 assert evts == []776 777 # first request786- resp = app.test_client().get('/').data778+ resp = client.get('/').data779 assert resp == b'request|after'780 assert evts == ['first', 'before', 'after', 'teardown']781 782 # second request791- resp = app.test_client().get('/').data783+ resp = client.get('/').data784 assert resp == b'request|after'785 assert evts == ['first'] + ['before', 'after', 'teardown'] * 2