From: Christopher Allan Webber Date: Mon, 6 Jun 2011 12:45:18 +0000 (-0500) Subject: A setup_fresh_app decorator which should make writing tests a bit easier. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3aa4c668b9bfe53ed58d4ae21ed91210df7ad9ff;p=mediagoblin.git A setup_fresh_app decorator which should make writing tests a bit easier. Setting test_register_views() to use it also. --- diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index cf6d48f5..cdfeccab 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -19,7 +19,7 @@ import urlparse from nose.tools import assert_equal from mediagoblin.auth import lib as auth_lib -from mediagoblin.tests.tools import get_test_app +from mediagoblin.tests.tools import setup_fresh_app from mediagoblin import globals as mgoblin_globals from mediagoblin import util @@ -65,13 +65,11 @@ def test_bcrypt_gen_password_hash(): 'notthepassword', hashed_pw, '3><7R45417') -def test_register_views(): +@setup_fresh_app +def test_register_views(test_app): """ Massive test function that all our registration-related views all work. """ - util.clear_test_template_context() - test_app = get_test_app() - # Test doing a simple GET on the page # ----------------------------------- diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index a51402e9..342b54b7 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -21,6 +21,8 @@ import os, shutil from paste.deploy import appconfig, loadapp from webtest import TestApp +from mediagoblin import util +from mediagoblin.decorators import _make_safe from mediagoblin.db.open import setup_connection_and_db_from_config @@ -91,3 +93,17 @@ def get_test_app(dump_old_app=True): 'config:' + TEST_APP_CONFIG) return TestApp(test_app) + + +def setup_fresh_app(func): + """ + Decorator to setup a fresh test application for this function. + + Cleans out test buckets and passes in a new, fresh test_app. + """ + def wrapper(*args, **kwargs): + test_app = get_test_app() + util.clear_test_buckets() + return func(test_app, *args, **kwargs) + + return _make_safe(wrapper, func)