Fix app fixture scope. Make function-scoped to make tests more isolated

master
Steven Loria 11 years ago
parent 338ef8b280
commit 35c32eccc1
  1. 2
      {{cookiecutter.app_name}}/tests/conftest.py
  2. 4
      {{cookiecutter.app_name}}/tests/test_webtests.py
  3. 5
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/settings.py

@ -10,7 +10,7 @@ from {{cookiecutter.app_name}}.app import create_app
from {{cookiecutter.app_name}}.database import db as _db from {{cookiecutter.app_name}}.database import db as _db
@pytest.yield_fixture(scope='session') @pytest.yield_fixture(scope='function')
def app(): def app():
_app = create_app(TestConfig) _app = create_app(TestConfig)
ctx = _app.test_request_context() ctx = _app.test_request_context()

@ -24,7 +24,7 @@ class TestLoggingIn:
form['username'] = user.username form['username'] = user.username
form['password'] = 'myprecious' form['password'] = 'myprecious'
# Submits # Submits
res = form.submit() res = form.submit().follow()
assert res.status_code == 200 assert res.status_code == 200
def test_sees_alert_on_log_out(self, user, testapp): def test_sees_alert_on_log_out(self, user, testapp):
@ -34,7 +34,7 @@ class TestLoggingIn:
form['username'] = user.username form['username'] = user.username
form['password'] = 'myprecious' form['password'] = 'myprecious'
# Submits # Submits
res = form.submit() res = form.submit().follow()
res = testapp.get(url_for('public.logout')).follow() res = testapp.get(url_for('public.logout')).follow()
# sees alert # sees alert
assert 'You are logged out.' in res assert 'You are logged out.' in res

@ -3,10 +3,11 @@ import os
class Config(object): class Config(object):
SECRET_KEY = 'shhhh' SECRET_KEY = 'shhhh' # TODO: Change me
APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir))
BCRYPT_LOG_ROUNDS = 13 BCRYPT_LOG_ROUNDS = 13
ASSETS_DEBUG = False
DEBUG_TB_ENABLED = False # Disable Debug toolbar DEBUG_TB_ENABLED = False # Disable Debug toolbar
DEBUG_TB_INTERCEPT_REDIRECTS = False DEBUG_TB_INTERCEPT_REDIRECTS = False
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc.
@ -16,7 +17,7 @@ class ProdConfig(Config):
"""Production configuration.""" """Production configuration."""
ENV = 'prod' ENV = 'prod'
DEBUG = False DEBUG = False
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' # TODO: Change me
DEBUG_TB_ENABLED = False # Disable Debug toolbar DEBUG_TB_ENABLED = False # Disable Debug toolbar

Loading…
Cancel
Save