From 05f66ad73543db207791ea5d6a2de2e8eaaf1640 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 22 May 2013 17:05:48 +0200 Subject: [PATCH] Fix some literals --- flask/testsuite/basic.py | 111 +++++++++++++++++----------------- flask/testsuite/blueprints.py | 74 +++++++++++------------ flask/testsuite/helpers.py | 16 ++--- flask/testsuite/regression.py | 4 +- flask/testsuite/reqctx.py | 4 +- flask/testsuite/signals.py | 4 +- flask/testsuite/templating.py | 16 ++--- flask/testsuite/testing.py | 8 +-- flask/testsuite/views.py | 14 ++--- 9 files changed, 125 insertions(+), 126 deletions(-) diff --git a/flask/testsuite/basic.py b/flask/testsuite/basic.py index 974b4ebc..1636bee7 100644 --- a/flask/testsuite/basic.py +++ b/flask/testsuite/basic.py @@ -32,7 +32,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): return 'Hello World' rv = app.test_client().open('/', method='OPTIONS') self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) - self.assert_equal(rv.data, '') + self.assert_equal(rv.data, b'') def test_options_on_multiple_rules(self): app = flask.Flask(__name__) @@ -72,15 +72,15 @@ class BasicFunctionalityTestCase(FlaskTestCase): return flask.request.method c = app.test_client() - self.assert_equal(c.get('/').data, 'GET') + self.assert_equal(c.get('/').data, b'GET') rv = c.post('/') self.assert_equal(rv.status_code, 405) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) rv = c.head('/') self.assert_equal(rv.status_code, 200) self.assert_(not rv.data) # head truncates - self.assert_equal(c.post('/more').data, 'POST') - self.assert_equal(c.get('/more').data, 'GET') + self.assert_equal(c.post('/more').data, b'POST') + self.assert_equal(c.get('/more').data, b'GET') rv = c.delete('/more') self.assert_equal(rv.status_code, 405) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) @@ -96,15 +96,15 @@ class BasicFunctionalityTestCase(FlaskTestCase): app.add_url_rule('/more', 'more', more, methods=['GET', 'POST']) c = app.test_client() - self.assert_equal(c.get('/').data, 'GET') + self.assert_equal(c.get('/').data, b'GET') rv = c.post('/') self.assert_equal(rv.status_code, 405) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) rv = c.head('/') self.assert_equal(rv.status_code, 200) self.assert_(not rv.data) # head truncates - self.assert_equal(c.post('/more').data, 'POST') - self.assert_equal(c.get('/more').data, 'GET') + self.assert_equal(c.post('/more').data, b'POST') + self.assert_equal(c.get('/more').data, b'GET') rv = c.delete('/more') self.assert_equal(rv.status_code, 405) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) @@ -124,8 +124,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): app.view_functions['index'] = index c = app.test_client() - self.assert_equal(c.get('/foo/').data, 'index') - self.assert_equal(c.get('/foo/bar').data, 'bar') + self.assert_equal(c.get('/foo/').data, b'index') + self.assert_equal(c.get('/foo/bar').data, b'bar') def test_endpoint_decorator(self): from werkzeug.routing import Submount, Rule @@ -144,8 +144,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): return 'index' c = app.test_client() - self.assert_equal(c.get('/foo/').data, 'index') - self.assert_equal(c.get('/foo/bar').data, 'bar') + self.assert_equal(c.get('/foo/').data, b'index') + self.assert_equal(c.get('/foo/bar').data, b'bar') def test_session(self): app = flask.Flask(__name__) @@ -159,8 +159,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): return flask.session['value'] c = app.test_client() - self.assert_equal(c.post('/set', data={'value': '42'}).data, 'value set') - self.assert_equal(c.get('/get').data, '42') + self.assert_equal(c.post('/set', data={'value': '42'}).data, b'value set') + self.assert_equal(c.get('/get').data, b'42') def test_session_using_server_name(self): app = flask.Flask(__name__) @@ -289,7 +289,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): self.assert_equal(expires.day, expected.day) rv = client.get('/test') - self.assert_equal(rv.data, 'True') + self.assert_equal(rv.data, b'True') permanent = False rv = app.test_client().get('/') @@ -311,8 +311,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): return repr(flask.session.get('foo')) c = app.test_client() - self.assert_equal(c.get('/').data, 'None') - self.assert_equal(c.get('/').data, '42') + self.assert_equal(c.get('/').data, b'None') + self.assert_equal(c.get('/').data, b'42') def test_session_special_types(self): app = flask.Flask(__name__) @@ -454,7 +454,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): self.assert_('after' not in evts) rv = app.test_client().get('/').data self.assert_('after' in evts) - self.assert_equal(rv, 'request|after') + self.assert_equal(rv, b'request|after') def test_after_request_processing(self): app = flask.Flask(__name__) @@ -483,7 +483,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): return "Response" rv = app.test_client().get('/') self.assert_equal(rv.status_code, 200) - self.assert_('Response' in rv.data) + self.assert_(b'Response' in rv.data) self.assert_equal(len(called), 1) def test_teardown_request_handler_debug_mode(self): @@ -499,7 +499,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): return "Response" rv = app.test_client().get('/') self.assert_equal(rv.status_code, 200) - self.assert_('Response' in rv.data) + self.assert_(b'Response' in rv.data) self.assert_equal(len(called), 1) def test_teardown_request_handler_error(self): @@ -532,7 +532,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): 1/0 rv = app.test_client().get('/') self.assert_equal(rv.status_code, 500) - self.assert_('Internal Server Error' in rv.data) + self.assert_(b'Internal Server Error' in rv.data) self.assert_equal(len(called), 2) def test_before_after_request_order(self): @@ -562,7 +562,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): def index(): return '42' rv = app.test_client().get('/') - self.assert_equal(rv.data, '42') + self.assert_equal(rv.data, b'42') self.assert_equal(called, [1, 2, 3, 4, 5, 6]) def test_error_handling(self): @@ -582,10 +582,10 @@ class BasicFunctionalityTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/') self.assert_equal(rv.status_code, 404) - self.assert_equal(rv.data, 'not found') + self.assert_equal(rv.data, b'not found') rv = c.get('/error') self.assert_equal(rv.status_code, 500) - self.assert_equal('internal server error', rv.data) + self.assert_equal(b'internal server error', rv.data) def test_before_request_and_routing_errors(self): app = flask.Flask(__name__) @@ -597,7 +597,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): return flask.g.something, 404 rv = app.test_client().get('/') self.assert_equal(rv.status_code, 404) - self.assert_equal(rv.data, 'value') + self.assert_equal(rv.data, b'value') def test_user_error_handling(self): class MyException(Exception): @@ -613,7 +613,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): raise MyException() c = app.test_client() - self.assert_equal(c.get('/').data, '42') + self.assert_equal(c.get('/').data, b'42') def test_trapping_of_bad_request_key_errors(self): app = flask.Flask(__name__) @@ -687,7 +687,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8')) self.assert_equal(c.get('/string').data, u'Hällo Wörld'.encode('utf-8')) rv = c.get('/args') - self.assert_equal(rv.data, 'Meh') + self.assert_equal(rv.data, b'Meh') self.assert_equal(rv.headers['X-Foo'], 'Testing') self.assert_equal(rv.status_code, 400) self.assert_equal(rv.mimetype, 'text/plain') @@ -697,17 +697,17 @@ class BasicFunctionalityTestCase(FlaskTestCase): with app.test_request_context(): rv = flask.make_response() self.assert_equal(rv.status_code, 200) - self.assert_equal(rv.data, '') + self.assert_equal(rv.data, b'') self.assert_equal(rv.mimetype, 'text/html') rv = flask.make_response('Awesome') self.assert_equal(rv.status_code, 200) - self.assert_equal(rv.data, 'Awesome') + self.assert_equal(rv.data, b'Awesome') self.assert_equal(rv.mimetype, 'text/html') rv = flask.make_response('W00t', 404) self.assert_equal(rv.status_code, 404) - self.assert_equal(rv.data, 'W00t') + self.assert_equal(rv.data, b'W00t') self.assert_equal(rv.mimetype, 'text/html') def test_make_response_with_response_instance(self): @@ -716,14 +716,13 @@ class BasicFunctionalityTestCase(FlaskTestCase): rv = flask.make_response( flask.jsonify({'msg': 'W00t'}), 400) self.assertEqual(rv.status_code, 400) - self.assertEqual(rv.data, - '{\n "msg": "W00t"\n}') + self.assertEqual(rv.data, b'{\n "msg": "W00t"\n}') self.assertEqual(rv.mimetype, 'application/json') rv = flask.make_response( flask.Response(''), 400) self.assertEqual(rv.status_code, 400) - self.assertEqual(rv.data, '') + self.assertEqual(rv.data, b'') self.assertEqual(rv.mimetype, 'text/html') rv = flask.make_response( @@ -783,13 +782,13 @@ class BasicFunctionalityTestCase(FlaskTestCase): def index(args): return '|'.join(args) c = app.test_client() - self.assert_equal(c.get('/1,2,3').data, '1|2|3') + self.assert_equal(c.get('/1,2,3').data, b'1|2|3') def test_static_files(self): app = flask.Flask(__name__) rv = app.test_client().get('/static/index.html') self.assert_equal(rv.status_code, 200) - self.assert_equal(rv.data.strip(), '

Hello World!

') + self.assert_equal(rv.data.strip(), b'

Hello World!

') with app.test_request_context(): self.assert_equal(flask.url_for('static', filename='index.html'), '/static/index.html') @@ -825,17 +824,17 @@ class BasicFunctionalityTestCase(FlaskTestCase): return 'Foo SubDomain' rv = app.test_client().get('/') - self.assert_equal(rv.data, 'Foo') + self.assert_equal(rv.data, b'Foo') rv = app.test_client().get('/', 'http://localhost.localdomain:5000') - self.assert_equal(rv.data, 'Foo') + self.assert_equal(rv.data, b'Foo') rv = app.test_client().get('/', 'https://localhost.localdomain:5000') - self.assert_equal(rv.data, 'Foo') + self.assert_equal(rv.data, b'Foo') app.config.update(SERVER_NAME='localhost.localdomain') rv = app.test_client().get('/', 'https://localhost.localdomain') - self.assert_equal(rv.data, 'Foo') + self.assert_equal(rv.data, b'Foo') try: app.config.update(SERVER_NAME='localhost.localdomain:443') @@ -860,7 +859,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): "server name from the WSGI environment ('foo.localhost')") rv = app.test_client().get('/', 'http://foo.localhost.localdomain') - self.assert_equal(rv.data, 'Foo SubDomain') + self.assert_equal(rv.data, b'Foo SubDomain') def test_exception_propagation(self): def apprunner(configkey): @@ -906,7 +905,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): c = app.test_client() rv = c.post('/accept', data={'myfile': 'foo' * 100}) - self.assert_equal(rv.data, '42') + self.assert_equal(rv.data, b'42') def test_url_processors(self): app = flask.Flask(__name__) @@ -935,9 +934,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): c = app.test_client() - self.assert_equal(c.get('/de/').data, '/de/about') - self.assert_equal(c.get('/de/about').data, '/foo') - self.assert_equal(c.get('/foo').data, '/en/about') + self.assert_equal(c.get('/de/').data, b'/de/about') + self.assert_equal(c.get('/de/about').data, b'/foo') + self.assert_equal(c.get('/foo').data, b'/en/about') def test_inject_blueprint_url_defaults(self): app = flask.Flask(__name__) @@ -969,7 +968,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): def index(): return 'Awesome' self.assert_(not app.got_first_request) - self.assert_equal(app.test_client().get('/').data, 'Awesome') + self.assert_equal(app.test_client().get('/').data, b'Awesome') try: @app.route('/foo') def broken(): @@ -983,7 +982,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): @app.route('/foo') def working(): return 'Meh' - self.assert_equal(app.test_client().get('/foo').data, 'Meh') + self.assert_equal(app.test_client().get('/foo').data, b'Meh') self.assert_(app.got_first_request) def test_before_first_request_functions(self): @@ -1016,12 +1015,12 @@ class BasicFunctionalityTestCase(FlaskTestCase): self.fail('Expected exception') rv = c.get('/foo', data={}, follow_redirects=True) - self.assert_equal(rv.data, 'success') + self.assert_equal(rv.data, b'success') app.debug = False with app.test_client() as c: rv = c.post('/foo', data={}, follow_redirects=True) - self.assert_equal(rv.data, 'success') + self.assert_equal(rv.data, b'success') def test_route_decorator_custom_endpoint(self): app = flask.Flask(__name__) @@ -1045,9 +1044,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): assert flask.url_for('123') == '/bar/123' c = app.test_client() - self.assertEqual(c.get('/foo/').data, 'foo') - self.assertEqual(c.get('/bar/').data, 'bar') - self.assertEqual(c.get('/bar/123').data, '123') + self.assertEqual(c.get('/foo/').data, b'foo') + self.assertEqual(c.get('/bar/').data, b'bar') + self.assertEqual(c.get('/bar/123').data, b'123') def test_preserve_only_once(self): app = flask.Flask(__name__) @@ -1084,10 +1083,10 @@ class SubdomainTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/', 'http://localhost/') - self.assert_equal(rv.data, 'normal index') + self.assert_equal(rv.data, b'normal index') rv = c.get('/', 'http://test.localhost/') - self.assert_equal(rv.data, 'test index') + self.assert_equal(rv.data, b'test index') @emits_module_deprecation_warning def test_module_static_path_subdomain(self): @@ -1108,7 +1107,7 @@ class SubdomainTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/', 'http://mitsuhiko.localhost/') - self.assert_equal(rv.data, 'index for mitsuhiko') + self.assert_equal(rv.data, b'index for mitsuhiko') def test_subdomain_matching_with_ports(self): app = flask.Flask(__name__) @@ -1119,7 +1118,7 @@ class SubdomainTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/', 'http://mitsuhiko.localhost:3000/') - self.assert_equal(rv.data, 'index for mitsuhiko') + self.assert_equal(rv.data, b'index for mitsuhiko') @emits_module_deprecation_warning def test_module_subdomain_support(self): @@ -1139,9 +1138,9 @@ class SubdomainTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/test', 'http://testing.localhost/') - self.assert_equal(rv.data, 'Test') + self.assert_equal(rv.data, b'Test') rv = c.get('/outside', 'http://xtesting.localhost/') - self.assert_equal(rv.data, 'Outside') + self.assert_equal(rv.data, b'Outside') def suite(): diff --git a/flask/testsuite/blueprints.py b/flask/testsuite/blueprints.py index 331854a6..28256b63 100644 --- a/flask/testsuite/blueprints.py +++ b/flask/testsuite/blueprints.py @@ -46,10 +46,10 @@ class ModuleTestCase(FlaskTestCase): return 'the index' app.register_module(admin) c = app.test_client() - self.assert_equal(c.get('/').data, 'the index') - self.assert_equal(c.get('/admin/').data, 'admin index') - self.assert_equal(c.get('/admin/login').data, 'admin login') - self.assert_equal(c.get('/admin/logout').data, 'admin logout') + self.assert_equal(c.get('/').data, b'the index') + self.assert_equal(c.get('/admin/').data, b'admin index') + self.assert_equal(c.get('/admin/login').data, b'admin login') + self.assert_equal(c.get('/admin/logout').data, b'admin logout') @emits_module_deprecation_warning def test_default_endpoint_name(self): @@ -60,7 +60,7 @@ class ModuleTestCase(FlaskTestCase): mod.add_url_rule('/', view_func=index) app.register_module(mod) rv = app.test_client().get('/') - self.assert_equal(rv.data, 'Awesome') + self.assert_equal(rv.data, b'Awesome') with app.test_request_context(): self.assert_equal(flask.url_for('frontend.index'), '/') @@ -92,11 +92,11 @@ class ModuleTestCase(FlaskTestCase): app.register_module(admin) c = app.test_client() - self.assert_equal(c.get('/').data, 'the index') + self.assert_equal(c.get('/').data, b'the index') self.assert_equal(catched, ['before-app', 'after-app']) del catched[:] - self.assert_equal(c.get('/admin/').data, 'the admin') + self.assert_equal(c.get('/admin/').data, b'the admin') self.assert_equal(catched, ['before-app', 'before-admin', 'after-admin', 'after-app']) @@ -121,8 +121,8 @@ class ModuleTestCase(FlaskTestCase): return flask.render_template_string('{{ a }}{{ b }}{{ c }}') app.register_module(admin) c = app.test_client() - self.assert_equal(c.get('/').data, '13') - self.assert_equal(c.get('/admin/').data, '123') + self.assert_equal(c.get('/').data, b'13') + self.assert_equal(c.get('/admin/').data, b'123') @emits_module_deprecation_warning def test_late_binding(self): @@ -132,7 +132,7 @@ class ModuleTestCase(FlaskTestCase): def index(): return '42' app.register_module(admin, url_prefix='/admin') - self.assert_equal(app.test_client().get('/admin/').data, '42') + self.assert_equal(app.test_client().get('/admin/').data, b'42') @emits_module_deprecation_warning def test_error_handling(self): @@ -154,7 +154,7 @@ class ModuleTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/') self.assert_equal(rv.status_code, 404) - self.assert_equal(rv.data, 'not found') + self.assert_equal(rv.data, b'not found') rv = c.get('/error') self.assert_equal(rv.status_code, 500) self.assert_equal('internal server error', rv.data) @@ -165,11 +165,11 @@ class ModuleTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/') - self.assert_equal(rv.data, 'Hello from the Frontend') + self.assert_equal(rv.data, b'Hello from the Frontend') rv = c.get('/admin/') - self.assert_equal(rv.data, 'Hello from the Admin') + self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/index2') - self.assert_equal(rv.data, 'Hello from the Admin') + self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/static/test.txt') self.assert_equal(rv.data.strip(), 'Admin File') rv = c.get('/admin/static/css/test.css') @@ -248,8 +248,8 @@ class ModuleTestCase(FlaskTestCase): app.register_module(module) c = app.test_client() - self.assert_equal(c.get('/foo/').data, 'index') - self.assert_equal(c.get('/foo/bar').data, 'bar') + self.assert_equal(c.get('/foo/').data, b'index') + self.assert_equal(c.get('/foo/bar').data, b'bar') class BlueprintTestCase(FlaskTestCase): @@ -290,9 +290,9 @@ class BlueprintTestCase(FlaskTestCase): c = app.test_client() - self.assert_equal(c.get('/frontend-no').data, 'frontend says no') - self.assert_equal(c.get('/backend-no').data, 'backend says no') - self.assert_equal(c.get('/what-is-a-sideend').data, 'application itself says no') + self.assert_equal(c.get('/frontend-no').data, b'frontend says no') + self.assert_equal(c.get('/backend-no').data, b'backend says no') + self.assert_equal(c.get('/what-is-a-sideend').data, b'application itself says no') def test_blueprint_url_definitions(self): bp = flask.Blueprint('test', __name__) @@ -339,19 +339,19 @@ class BlueprintTestCase(FlaskTestCase): c = app.test_client() - self.assert_equal(c.get('/de/').data, '/de/about') - self.assert_equal(c.get('/de/about').data, '/de/') + self.assert_equal(c.get('/de/').data, b'/de/about') + self.assert_equal(c.get('/de/about').data, b'/de/') def test_templates_and_static(self): from blueprintapp import app c = app.test_client() rv = c.get('/') - self.assert_equal(rv.data, 'Hello from the Frontend') + self.assert_equal(rv.data, b'Hello from the Frontend') rv = c.get('/admin/') - self.assert_equal(rv.data, 'Hello from the Admin') + self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/index2') - self.assert_equal(rv.data, 'Hello from the Admin') + self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/static/test.txt') self.assert_equal(rv.data.strip(), 'Admin File') rv = c.get('/admin/static/css/test.css') @@ -451,8 +451,8 @@ class BlueprintTestCase(FlaskTestCase): app.register_blueprint(bp) c = app.test_client() - self.assert_equal(c.get('/').data, '1') - self.assert_equal(c.get('/page/2').data, '2') + self.assert_equal(c.get('/').data, b'1') + self.assert_equal(c.get('/page/2').data, b'2') def test_route_decorator_custom_endpoint(self): @@ -482,11 +482,11 @@ class BlueprintTestCase(FlaskTestCase): return flask.request.endpoint c = app.test_client() - self.assertEqual(c.get('/').data, 'index') - self.assertEqual(c.get('/py/foo').data, 'bp.foo') - self.assertEqual(c.get('/py/bar').data, 'bp.bar') - self.assertEqual(c.get('/py/bar/123').data, 'bp.123') - self.assertEqual(c.get('/py/bar/foo').data, 'bp.bar_foo') + self.assertEqual(c.get('/').data, b'index') + self.assertEqual(c.get('/py/foo').data, b'bp.foo') + self.assertEqual(c.get('/py/bar').data, b'bp.bar') + self.assertEqual(c.get('/py/bar/123').data, b'bp.123') + self.assertEqual(c.get('/py/bar/foo').data, b'bp.bar_foo') def test_route_decorator_custom_endpoint_with_dots(self): bp = flask.Blueprint('bp', __name__) @@ -533,7 +533,7 @@ class BlueprintTestCase(FlaskTestCase): app.register_blueprint(bp, url_prefix='/py') c = app.test_client() - self.assertEqual(c.get('/py/foo').data, 'bp.foo') + self.assertEqual(c.get('/py/foo').data, b'bp.foo') # The rule's din't actually made it through rv = c.get('/py/bar') assert rv.status_code == 404 @@ -595,7 +595,7 @@ class BlueprintTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_template_filter_after_route_with_template(self): app = flask.Flask(__name__) @@ -608,7 +608,7 @@ class BlueprintTestCase(FlaskTestCase): return s[::-1] app.register_blueprint(bp, url_prefix='/py') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_add_template_filter_with_template(self): bp = flask.Blueprint('bp', __name__) @@ -621,7 +621,7 @@ class BlueprintTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_template_filter_with_name_and_template(self): bp = flask.Blueprint('bp', __name__) @@ -634,7 +634,7 @@ class BlueprintTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_add_template_filter_with_name_and_template(self): bp = flask.Blueprint('bp', __name__) @@ -647,7 +647,7 @@ class BlueprintTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_template_test(self): bp = flask.Blueprint('bp', __name__) diff --git a/flask/testsuite/helpers.py b/flask/testsuite/helpers.py index 2808a409..fbdcbff4 100644 --- a/flask/testsuite/helpers.py +++ b/flask/testsuite/helpers.py @@ -99,7 +99,7 @@ class JSONTestCase(FlaskTestCase): c = app.test_client() rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}), content_type='application/json') - self.assert_equal(rv.data, '3') + self.assert_equal(rv.data, b'3') def test_template_escaping(self): app = flask.Flask(__name__) @@ -140,7 +140,7 @@ class JSONTestCase(FlaskTestCase): rv = c.post('/', data=flask.json.dumps({ 'x': {'_foo': 42} }), content_type='application/json') - self.assertEqual(rv.data, '"<42>"') + self.assertEqual(rv.data, b'"<42>"') def test_modified_url_encoding(self): class ModifiedRequest(flask.Request): @@ -212,14 +212,14 @@ class SendfileTestCase(FlaskTestCase): with catch_warnings() as captured: f = StringIO('Test') rv = flask.send_file(f) - self.assert_equal(rv.data, 'Test') + self.assert_equal(rv.data, b'Test') self.assert_equal(rv.mimetype, 'application/octet-stream') # etags self.assert_equal(len(captured), 1) with catch_warnings() as captured: f = StringIO('Test') rv = flask.send_file(f, mimetype='text/plain') - self.assert_equal(rv.data, 'Test') + self.assert_equal(rv.data, b'Test') self.assert_equal(rv.mimetype, 'text/plain') # etags self.assert_equal(len(captured), 1) @@ -385,7 +385,7 @@ class LoggingTestCase(FlaskTestCase): for trigger in 'before', 'after': rv = app.test_client().get('/') self.assert_equal(rv.status_code, 500) - self.assert_equal(rv.data, 'Hello Server Error') + self.assert_equal(rv.data, b'Hello Server Error') def test_url_for_with_anchor(self): app = flask.Flask(__name__) @@ -477,7 +477,7 @@ class StreamingTestCase(FlaskTestCase): return flask.Response(flask.stream_with_context(generate())) c = app.test_client() rv = c.get('/?name=World') - self.assertEqual(rv.data, 'Hello World!') + self.assertEqual(rv.data, b'Hello World!') def test_streaming_with_context_as_decorator(self): app = flask.Flask(__name__) @@ -492,7 +492,7 @@ class StreamingTestCase(FlaskTestCase): return flask.Response(generate()) c = app.test_client() rv = c.get('/?name=World') - self.assertEqual(rv.data, 'Hello World!') + self.assertEqual(rv.data, b'Hello World!') def test_streaming_with_context_and_custom_close(self): app = flask.Flask(__name__) @@ -517,7 +517,7 @@ class StreamingTestCase(FlaskTestCase): Wrapper(generate()))) c = app.test_client() rv = c.get('/?name=World') - self.assertEqual(rv.data, 'Hello World!') + self.assertEqual(rv.data, b'Hello World!') self.assertEqual(called, [42]) diff --git a/flask/testsuite/regression.py b/flask/testsuite/regression.py index b8140d6f..e516dc0f 100644 --- a/flask/testsuite/regression.py +++ b/flask/testsuite/regression.py @@ -66,7 +66,7 @@ class MemoryTestCase(FlaskTestCase): with app.test_client() as c: rv = c.get('/') self.assert_equal(rv.status_code, 200) - self.assert_equal(rv.data, '

42

') + self.assert_equal(rv.data, b'

42

') # Trigger caches fire() @@ -105,7 +105,7 @@ class ExceptionTestCase(FlaskTestCase): rv = c.get('/') self.assertEqual(rv.headers['Location'], 'http://localhost/test') rv = c.get('/test') - self.assertEqual(rv.data, '42') + self.assertEqual(rv.data, b'42') def suite(): diff --git a/flask/testsuite/reqctx.py b/flask/testsuite/reqctx.py index 0f0282e5..6e379448 100644 --- a/flask/testsuite/reqctx.py +++ b/flask/testsuite/reqctx.py @@ -145,7 +145,7 @@ class RequestContextTestCase(FlaskTestCase): return 'Hello World!' rv = app.test_client().get('/?foo=bar') - self.assert_equal(rv.data, 'Hello World!') + self.assert_equal(rv.data, b'Hello World!') result = greenlets[0].run() self.assert_equal(result, 42) @@ -168,7 +168,7 @@ class RequestContextTestCase(FlaskTestCase): return 'Hello World!' rv = app.test_client().get('/?foo=bar') - self.assert_equal(rv.data, 'Hello World!') + self.assert_equal(rv.data, b'Hello World!') result = greenlets[0].run() self.assert_equal(result, 42) diff --git a/flask/testsuite/signals.py b/flask/testsuite/signals.py index 637c2c66..843c2f83 100644 --- a/flask/testsuite/signals.py +++ b/flask/testsuite/signals.py @@ -45,7 +45,7 @@ class SignalsTestCase(FlaskTestCase): calls.append('before-signal') def after_request_signal(sender, response): - self.assert_equal(response.data, 'stuff') + self.assert_equal(response.data, b'stuff') calls.append('after-signal') @app.before_request @@ -68,7 +68,7 @@ class SignalsTestCase(FlaskTestCase): try: rv = app.test_client().get('/') - self.assert_equal(rv.data, 'stuff') + self.assert_equal(rv.data, b'stuff') self.assert_equal(calls, ['before-signal', 'before-handler', 'handler', 'after-handler', diff --git a/flask/testsuite/templating.py b/flask/testsuite/templating.py index c8d1dd22..c36a282e 100644 --- a/flask/testsuite/templating.py +++ b/flask/testsuite/templating.py @@ -25,7 +25,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template('context_template.html', value=23) rv = app.test_client().get('/') - self.assert_equal(rv.data, '

23|42') + self.assert_equal(rv.data, b'

23|42') def test_original_win(self): app = flask.Flask(__name__) @@ -33,7 +33,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template_string('{{ config }}', config=42) rv = app.test_client().get('/') - self.assert_equal(rv.data, '42') + self.assert_equal(rv.data, b'42') def test_request_less_rendering(self): app = flask.Flask(__name__) @@ -139,7 +139,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_add_template_filter_with_template(self): app = flask.Flask(__name__) @@ -150,7 +150,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_template_filter_with_name_and_template(self): app = flask.Flask(__name__) @@ -161,7 +161,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_add_template_filter_with_name_and_template(self): app = flask.Flask(__name__) @@ -172,7 +172,7 @@ class TemplatingTestCase(FlaskTestCase): def index(): return flask.render_template('template_filter.html', value='abcd') rv = app.test_client().get('/') - self.assert_equal(rv.data, 'dcba') + self.assert_equal(rv.data, b'dcba') def test_template_test(self): app = flask.Flask(__name__) @@ -277,7 +277,7 @@ class TemplatingTestCase(FlaskTestCase): return flask.render_template('index.html') c = app.test_client() rv = c.get('/') - self.assert_equal(rv.data, 'Hello Custom World!') + self.assert_equal(rv.data, b'Hello Custom World!') def test_iterable_loader(self): app = flask.Flask(__name__) @@ -293,7 +293,7 @@ class TemplatingTestCase(FlaskTestCase): value=23) rv = app.test_client().get('/') - self.assert_equal(rv.data, '

Jameson

') + self.assert_equal(rv.data, b'

Jameson

') def suite(): diff --git a/flask/testsuite/testing.py b/flask/testsuite/testing.py index a37f6e6c..8b1b7d62 100644 --- a/flask/testsuite/testing.py +++ b/flask/testsuite/testing.py @@ -30,7 +30,7 @@ class TestToolsTestCase(FlaskTestCase): self.assert_equal(ctx.request.url, 'http://example.com:1234/foo/') with app.test_client() as c: rv = c.get('/') - self.assert_equal(rv.data, 'http://example.com:1234/foo/') + self.assert_equal(rv.data, b'http://example.com:1234/foo/') def test_environ_defaults(self): app = flask.Flask(__name__) @@ -43,7 +43,7 @@ class TestToolsTestCase(FlaskTestCase): self.assert_equal(ctx.request.url, 'http://localhost/') with app.test_client() as c: rv = c.get('/') - self.assert_equal(rv.data, 'http://localhost/') + self.assert_equal(rv.data, b'http://localhost/') def test_redirect_keep_session(self): app = flask.Flask(__name__) @@ -92,7 +92,7 @@ class TestToolsTestCase(FlaskTestCase): sess['foo'] = [42] self.assert_equal(len(sess), 1) rv = c.get('/') - self.assert_equal(rv.data, '[42]') + self.assert_equal(rv.data, b'[42]') with c.session_transaction() as sess: self.assert_equal(len(sess), 1) self.assert_equal(sess['foo'], [42]) @@ -148,7 +148,7 @@ class TestToolsTestCase(FlaskTestCase): with app.test_client() as c: resp = c.get('/') self.assert_equal(flask.g.value, 42) - self.assert_equal(resp.data, 'Hello World!') + self.assert_equal(resp.data, b'Hello World!') self.assert_equal(resp.status_code, 200) resp = c.get('/other') diff --git a/flask/testsuite/views.py b/flask/testsuite/views.py index 6c3ae816..9dd463f2 100644 --- a/flask/testsuite/views.py +++ b/flask/testsuite/views.py @@ -20,8 +20,8 @@ class ViewTestCase(FlaskTestCase): def common_test(self, app): c = app.test_client() - self.assert_equal(c.get('/').data, 'GET') - self.assert_equal(c.post('/').data, 'POST') + self.assert_equal(c.get('/').data, b'GET') + self.assert_equal(c.post('/').data, b'POST') self.assert_equal(c.put('/').status_code, 405) meths = parse_set_header(c.open('/', method='OPTIONS').headers['Allow']) self.assert_equal(sorted(meths), ['GET', 'HEAD', 'OPTIONS', 'POST']) @@ -108,7 +108,7 @@ class ViewTestCase(FlaskTestCase): c = app.test_client() rv = c.get('/') self.assert_equal(rv.headers['X-Parachute'], 'awesome') - self.assert_equal(rv.data, 'Awesome') + self.assert_equal(rv.data, b'Awesome') def test_implicit_head(self): app = flask.Flask(__name__) @@ -122,10 +122,10 @@ class ViewTestCase(FlaskTestCase): app.add_url_rule('/', view_func=Index.as_view('index')) c = app.test_client() rv = c.get('/') - self.assert_equal(rv.data, 'Blub') + self.assert_equal(rv.data, b'Blub') self.assert_equal(rv.headers['X-Method'], 'GET') rv = c.head('/') - self.assert_equal(rv.data, '') + self.assert_equal(rv.data, b'') self.assert_equal(rv.headers['X-Method'], 'HEAD') def test_explicit_head(self): @@ -140,9 +140,9 @@ class ViewTestCase(FlaskTestCase): app.add_url_rule('/', view_func=Index.as_view('index')) c = app.test_client() rv = c.get('/') - self.assert_equal(rv.data, 'GET') + self.assert_equal(rv.data, b'GET') rv = c.head('/') - self.assert_equal(rv.data, '') + self.assert_equal(rv.data, b'') self.assert_equal(rv.headers['X-Method'], 'HEAD') def test_endpoint_override(self):