forked from orbit-oss/flask
fix minitwit/flaskr test errors, improve docs about file open mode
app.open_resource needs to get called with the correct mode param (python3 will read bytes [not str] if the wrong mode is used), add mode param docs. rv.data is bytes, fix the data type we compare it with to be also bytes
This commit is contained in:
parent
85ba8c96e9
commit
8bb972e5ae
8 changed files with 42 additions and 40 deletions
|
|
@ -31,7 +31,7 @@ def init_db():
|
|||
"""Creates the database tables."""
|
||||
with app.app_context():
|
||||
db = get_db()
|
||||
with app.open_resource('schema.sql') as f:
|
||||
with app.open_resource('schema.sql', mode='r') as f:
|
||||
db.cursor().executescript(f.read())
|
||||
db.commit()
|
||||
|
||||
|
|
|
|||
|
|
@ -42,21 +42,21 @@ class FlaskrTestCase(unittest.TestCase):
|
|||
def test_empty_db(self):
|
||||
"""Start with a blank database."""
|
||||
rv = self.app.get('/')
|
||||
assert 'No entries here so far' in rv.data
|
||||
assert b'No entries here so far' in rv.data
|
||||
|
||||
def test_login_logout(self):
|
||||
"""Make sure login and logout works"""
|
||||
rv = self.login(flaskr.app.config['USERNAME'],
|
||||
flaskr.app.config['PASSWORD'])
|
||||
assert 'You were logged in' in rv.data
|
||||
assert b'You were logged in' in rv.data
|
||||
rv = self.logout()
|
||||
assert 'You were logged out' in rv.data
|
||||
assert b'You were logged out' in rv.data
|
||||
rv = self.login(flaskr.app.config['USERNAME'] + 'x',
|
||||
flaskr.app.config['PASSWORD'])
|
||||
assert 'Invalid username' in rv.data
|
||||
assert b'Invalid username' in rv.data
|
||||
rv = self.login(flaskr.app.config['USERNAME'],
|
||||
flaskr.app.config['PASSWORD'] + 'x')
|
||||
assert 'Invalid password' in rv.data
|
||||
assert b'Invalid password' in rv.data
|
||||
|
||||
def test_messages(self):
|
||||
"""Test that messages work"""
|
||||
|
|
@ -66,9 +66,9 @@ class FlaskrTestCase(unittest.TestCase):
|
|||
title='<Hello>',
|
||||
text='<strong>HTML</strong> allowed here'
|
||||
), follow_redirects=True)
|
||||
assert 'No entries here so far' not in rv.data
|
||||
assert '<Hello>' in rv.data
|
||||
assert '<strong>HTML</strong> allowed here' in rv.data
|
||||
assert b'No entries here so far' not in rv.data
|
||||
assert b'<Hello>' in rv.data
|
||||
assert b'<strong>HTML</strong> allowed here' in rv.data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue