Browse Source

Response data is bytes

pull/739/head
Daniel Neuhäuser 12 years ago
parent
commit
5b89355b1c
  1. 8
      flask/testsuite/basic.py
  2. 34
      flask/testsuite/blueprints.py
  3. 2
      flask/testsuite/helpers.py
  4. 2
      flask/testsuite/subclassing.py
  5. 22
      flask/testsuite/templating.py
  6. 14
      flask/testsuite/testing.py

8
flask/testsuite/basic.py

@ -453,7 +453,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return 'request'
self.assert_('after' not in evts)
rv = app.test_client().get('/').data
self.assert_('after' in evts)
self.assert_(b'after' in evts)
self.assert_equal(rv, b'request|after')
def test_after_request_processing(self):
@ -937,10 +937,10 @@ class BasicFunctionalityTestCase(FlaskTestCase):
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__)
bp = flask.Blueprint('foo.bar.baz', __name__,
bp = flask.Blueprint('foo.bar.baz', __name__,
template_folder='template')
@bp.url_defaults
@ -1096,7 +1096,7 @@ class SubdomainTestCase(FlaskTestCase):
app.register_module(mod)
c = app.test_client()
rv = c.get('/static/hello.txt', 'http://foo.example.com/')
self.assert_equal(rv.data.strip(), 'Hello Subdomain')
self.assert_equal(rv.data.strip(), b'Hello Subdomain')
def test_subdomain_matching(self):
app = flask.Flask(__name__)

34
flask/testsuite/blueprints.py

@ -157,7 +157,7 @@ class ModuleTestCase(FlaskTestCase):
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_templates_and_static(self):
app = moduleapp
@ -171,9 +171,9 @@ class ModuleTestCase(FlaskTestCase):
rv = c.get('/admin/index2')
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')
self.assert_equal(rv.data.strip(), b'Admin File')
rv = c.get('/admin/static/css/test.css')
self.assert_equal(rv.data.strip(), '/* nested file */')
self.assert_equal(rv.data.strip(), b'/* nested file */')
with app.test_request_context():
self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
@ -310,10 +310,10 @@ class BlueprintTestCase(FlaskTestCase):
app.register_blueprint(bp, url_prefix='/2', url_defaults={'bar': 19})
c = app.test_client()
self.assert_equal(c.get('/1/foo').data, u'23/42')
self.assert_equal(c.get('/2/foo').data, u'19/42')
self.assert_equal(c.get('/1/bar').data, u'23')
self.assert_equal(c.get('/2/bar').data, u'19')
self.assert_equal(c.get('/1/foo').data, b'23/42')
self.assert_equal(c.get('/2/foo').data, b'19/42')
self.assert_equal(c.get('/1/bar').data, b'23')
self.assert_equal(c.get('/2/bar').data, b'19')
def test_blueprint_url_processors(self):
bp = flask.Blueprint('frontend', __name__, url_prefix='/<lang_code>')
@ -353,9 +353,9 @@ class BlueprintTestCase(FlaskTestCase):
rv = c.get('/admin/index2')
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')
self.assert_equal(rv.data.strip(), b'Admin File')
rv = c.get('/admin/static/css/test.css')
self.assert_equal(rv.data.strip(), '/* nested file */')
self.assert_equal(rv.data.strip(), b'/* nested file */')
# try/finally, in case other tests use this app for Blueprint tests.
max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
@ -435,9 +435,9 @@ class BlueprintTestCase(FlaskTestCase):
app.register_blueprint(backend)
c = app.test_client()
self.assert_equal(c.get('/fe').data.strip(), '/be')
self.assert_equal(c.get('/fe2').data.strip(), '/fe')
self.assert_equal(c.get('/be').data.strip(), '/fe')
self.assert_equal(c.get('/fe').data.strip(), b'/be')
self.assert_equal(c.get('/fe2').data.strip(), b'/fe')
self.assert_equal(c.get('/be').data.strip(), b'/fe')
def test_empty_url_defaults(self):
bp = flask.Blueprint('bp', __name__)
@ -704,7 +704,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_template_test_after_route_with_template(self):
app = flask.Flask(__name__)
@ -717,7 +717,7 @@ class BlueprintTestCase(FlaskTestCase):
return isinstance(value, bool)
app.register_blueprint(bp, url_prefix='/py')
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_add_template_test_with_template(self):
bp = flask.Blueprint('bp', __name__)
@ -730,7 +730,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_template_test_with_name_and_template(self):
bp = flask.Blueprint('bp', __name__)
@ -743,7 +743,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_add_template_test_with_name_and_template(self):
bp = flask.Blueprint('bp', __name__)
@ -756,7 +756,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def suite():
suite = unittest.TestSuite()

2
flask/testsuite/helpers.py

@ -357,7 +357,7 @@ class LoggingTestCase(FlaskTestCase):
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)
err = out.getvalue()
self.assert_('Exception on / [GET]' in err)

2
flask/testsuite/subclassing.py

@ -34,7 +34,7 @@ class FlaskSubclassingTestCase(FlaskTestCase):
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)
err = out.getvalue()
self.assert_equal(err, '')

22
flask/testsuite/templating.py

@ -61,7 +61,7 @@ class TemplatingTestCase(FlaskTestCase):
{{ session.test }}
''')
rv = app.test_client().get('/?foo=42')
self.assert_equal(rv.data.split(), ['42', '23', 'False', 'aha'])
self.assert_equal(rv.data.split(), [b'42', b'23', b'False', b'aha'])
def test_escaping(self):
text = '<p>Hello World!'
@ -72,12 +72,12 @@ class TemplatingTestCase(FlaskTestCase):
html=flask.Markup(text))
lines = app.test_client().get('/').data.splitlines()
self.assert_equal(lines, [
'&lt;p&gt;Hello World!',
'<p>Hello World!',
'<p>Hello World!',
'<p>Hello World!',
'&lt;p&gt;Hello World!',
'<p>Hello World!'
b'&lt;p&gt;Hello World!',
b'<p>Hello World!',
b'<p>Hello World!',
b'<p>Hello World!',
b'&lt;p&gt;Hello World!',
b'<p>Hello World!'
])
def test_no_escaping(self):
@ -219,7 +219,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_add_template_test_with_template(self):
app = flask.Flask(__name__)
@ -230,7 +230,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_template_test_with_name_and_template(self):
app = flask.Flask(__name__)
@ -241,7 +241,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_add_template_test_with_name_and_template(self):
app = flask.Flask(__name__)
@ -252,7 +252,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_('Success!' in rv.data)
self.assert_(b'Success!' in rv.data)
def test_add_template_global(self):
app = flask.Flask(__name__)

14
flask/testsuite/testing.py

@ -62,20 +62,20 @@ class TestToolsTestCase(FlaskTestCase):
with app.test_client() as c:
rv = c.get('/getsession')
assert rv.data == '<missing>'
assert rv.data == b'<missing>'
rv = c.get('/')
assert rv.data == 'index'
assert rv.data == b'index'
assert flask.session.get('data') == 'foo'
rv = c.post('/', data={}, follow_redirects=True)
assert rv.data == 'foo'
assert rv.data == b'foo'
# This support requires a new Werkzeug version
if not hasattr(c, 'redirect_client'):
assert flask.session.get('data') == 'foo'
rv = c.get('/getsession')
assert rv.data == 'foo'
assert rv.data == b'foo'
def test_session_transactions(self):
app = flask.Flask(__name__)
@ -153,7 +153,7 @@ class TestToolsTestCase(FlaskTestCase):
resp = c.get('/other')
self.assert_(not hasattr(flask.g, 'value'))
self.assert_('Internal Server Error' in resp.data)
self.assert_(b'Internal Server Error' in resp.data)
self.assert_equal(resp.status_code, 500)
flask.g.value = 23
@ -220,7 +220,7 @@ class SubdomainTestCase(FlaskTestCase):
response = self.client.get(url)
self.assertEquals(200, response.status_code)
self.assertEquals('xxx', response.data)
self.assertEquals(b'xxx', response.data)
def test_nosubdomain(self):
@ -232,7 +232,7 @@ class SubdomainTestCase(FlaskTestCase):
response = self.client.get(url)
self.assertEquals(200, response.status_code)
self.assertEquals('xxx', response.data)
self.assertEquals(b'xxx', response.data)
def suite():

Loading…
Cancel
Save