Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (53 sloc) 1.994 kb
# -*- coding: utf-8 -*-
Flaskr Tests
Tests the Flaskr application.
:copyright: (c) 2010 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
import flaskr
import unittest
import tempfile
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
"""Before each test, set up a blank database"""
self.db = tempfile.NamedTemporaryFile() =
flaskr.DATABASE =
def login(self, username, password):
return'/login', data=dict(
), follow_redirects=True)
def logout(self):
return'/logout', follow_redirects=True)
# testing functions
def test_empty_db(self):
"""Start with a blank database."""
rv ='/')
assert 'No entries here so far' in
def test_login_logout(self):
"""Make sure login and logout works"""
rv = self.login(flaskr.USERNAME, flaskr.PASSWORD)
assert 'You were logged in' in
rv = self.logout()
assert 'You were logged out' in
rv = self.login(flaskr.USERNAME + 'x', flaskr.PASSWORD)
assert 'Invalid username' in
rv = self.login(flaskr.USERNAME, flaskr.PASSWORD + 'x')
assert 'Invalid password' in
def test_messages(self):
"""Test that messages work"""
self.login(flaskr.USERNAME, flaskr.PASSWORD)
rv ='/add', data=dict(
text='<strong>HTML</strong> allowed here'
), follow_redirects=True)
assert 'No entries here so far' not in
self.login(flaskr.USERNAME, flaskr.PASSWORD)
assert '&lt;Hello&gt' in
assert '<strong>HTML</strong> allowed here' in
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.