diff --git a/examples/flaskr/README b/examples/flaskr/README index 90860ff2..22ae857f 100644 --- a/examples/flaskr/README +++ b/examples/flaskr/README @@ -9,9 +9,11 @@ ~ How do I use it? - 1. edit the configuration in the flaskr.py file or + 1. edit the configuration in the factory.py file or export an FLASKR_SETTINGS environment variable - pointing to a configuration file. + pointing to a configuration file or pass in a + dictionary with config values using the create_app + function. 2. install the app from the root of the project directory @@ -19,7 +21,7 @@ 3. Instruct flask to use the right application - export FLASK_APP=flaskr + export FLASK_APP=flaskr._cliapp 4. initialize the database with this command: diff --git a/examples/flaskr/flaskr/_cliapp.py b/examples/flaskr/flaskr/_cliapp.py index faed660c..b13bf79a 100644 --- a/examples/flaskr/flaskr/_cliapp.py +++ b/examples/flaskr/flaskr/_cliapp.py @@ -1,3 +1,15 @@ +# -*- coding: utf-8 -*- +""" + Flaskr + ~~~~~~ + + A microblog example application written as Flask tutorial with + Flask and sqlite3. + + :copyright: (c) 2015 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" + from flaskr.factory import create_app app = create_app() \ No newline at end of file diff --git a/examples/flaskr/flaskr/factory.py b/examples/flaskr/flaskr/factory.py index e71a6704..a0f2d235 100644 --- a/examples/flaskr/flaskr/factory.py +++ b/examples/flaskr/flaskr/factory.py @@ -1,3 +1,15 @@ +# -*- coding: utf-8 -*- +""" + Flaskr + ~~~~~~ + + A microblog example application written as Flask tutorial with + Flask and sqlite3. + + :copyright: (c) 2015 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" + import os from flask import Flask, g from werkzeug.utils import find_modules, import_string diff --git a/examples/flaskr/setup.cfg b/examples/flaskr/setup.cfg index db50667a..9af7e6f1 100644 --- a/examples/flaskr/setup.cfg +++ b/examples/flaskr/setup.cfg @@ -1,2 +1,2 @@ -[tool:pytest] -test=pytest +[aliases] +test=pytest \ No newline at end of file diff --git a/examples/flaskr/setup.py b/examples/flaskr/setup.py index f52aacd8..7f1dae53 100644 --- a/examples/flaskr/setup.py +++ b/examples/flaskr/setup.py @@ -1,3 +1,14 @@ +# -*- coding: utf-8 -*- +""" + Flaskr Tests + ~~~~~~~~~~~~ + + Tests the Flaskr application. + + :copyright: (c) 2015 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" + from setuptools import setup, find_packages setup( diff --git a/examples/flaskr/tests/test_flaskr.py b/examples/flaskr/tests/test_flaskr.py index c8115829..b5ade2ec 100644 --- a/examples/flaskr/tests/test_flaskr.py +++ b/examples/flaskr/tests/test_flaskr.py @@ -16,20 +16,31 @@ from flaskr.factory import create_app from flaskr.blueprints.flaskr import init_db -test_app = create_app() +@pytest.fixture +def app(request): + + db_fd, temp_db_location = tempfile.mkstemp() + config = { + 'DATABASE': temp_db_location, + 'TESTING': True, + 'DB_FD': db_fd + } + + app = create_app(config=config) + + with app.app_context(): + init_db() + yield app @pytest.fixture -def client(request): - db_fd, test_app.config['DATABASE'] = tempfile.mkstemp() - test_app.config['TESTING'] = True - client = test_app.test_client() - with test_app.app_context(): - init_db() +def client(request, app): + + client = app.test_client() def teardown(): - os.close(db_fd) - os.unlink(test_app.config['DATABASE']) + os.close(app.config['DB_FD']) + os.unlink(app.config['DATABASE']) request.addfinalizer(teardown) return client @@ -52,25 +63,25 @@ def test_empty_db(client): assert b'No entries here so far' in rv.data -def test_login_logout(client): +def test_login_logout(client, app): """Make sure login and logout works""" - rv = login(client, test_app.config['USERNAME'], - test_app.config['PASSWORD']) + rv = login(client, app.config['USERNAME'], + app.config['PASSWORD']) assert b'You were logged in' in rv.data rv = logout(client) assert b'You were logged out' in rv.data - rv = login(client,test_app.config['USERNAME'] + 'x', - test_app.config['PASSWORD']) + rv = login(client,app.config['USERNAME'] + 'x', + app.config['PASSWORD']) assert b'Invalid username' in rv.data - rv = login(client, test_app.config['USERNAME'], - test_app.config['PASSWORD'] + 'x') + rv = login(client, app.config['USERNAME'], + app.config['PASSWORD'] + 'x') assert b'Invalid password' in rv.data -def test_messages(client): +def test_messages(client, app): """Test that messages work""" - login(client, test_app.config['USERNAME'], - test_app.config['PASSWORD']) + login(client, app.config['USERNAME'], + app.config['PASSWORD']) rv = client.post('/add', data=dict( title='', text='HTML allowed here'