From b97144dcc970750b265b8e9605f9a4da0cee50e4 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 8 Jan 2013 13:31:16 +0100 Subject: [PATCH] tests: More instances where a fresh database is not needed Save test runtime by not dumping the databases when not needed. --- mediagoblin/tests/test_auth.py | 10 +++++----- mediagoblin/tests/test_csrf_middleware.py | 17 +++++++---------- mediagoblin/tests/test_messages.py | 13 +++++++------ mediagoblin/tests/test_misc.py | 12 +++++------- mediagoblin/tests/test_tags.py | 6 +++--- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index f4a31a81..a40c9cbc 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -22,7 +22,7 @@ from nose.tools import assert_equal from mediagoblin import mg_globals from mediagoblin.auth import lib as auth_lib from mediagoblin.db.models import User -from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user +from mediagoblin.tests.tools import get_test_app, fixture_add_user from mediagoblin.tools import template, mail @@ -67,11 +67,11 @@ def test_bcrypt_gen_password_hash(): 'notthepassword', hashed_pw, '3><7R45417') -@setup_fresh_app -def test_register_views(test_app): +def test_register_views(): """ Massive test function that all our registration-related views all work. """ + test_app = get_test_app(dump_old_app=False) # Test doing a simple GET on the page # ----------------------------------- @@ -311,11 +311,11 @@ def test_register_views(test_app): 'mediagoblin/root.html') -@setup_fresh_app -def test_authentication_views(test_app): +def test_authentication_views(): """ Test logging in and logging out """ + test_app = get_test_app(dump_old_app=False) # Make a new user test_user = fixture_add_user(active_user=False) diff --git a/mediagoblin/tests/test_csrf_middleware.py b/mediagoblin/tests/test_csrf_middleware.py index d730909f..3aa405e0 100644 --- a/mediagoblin/tests/test_csrf_middleware.py +++ b/mediagoblin/tests/test_csrf_middleware.py @@ -14,13 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.tests.tools import setup_fresh_app +from mediagoblin.tests.tools import get_test_app from mediagoblin import mg_globals -@setup_fresh_app -def test_csrf_cookie_set(test_app): - +def test_csrf_cookie_set(): + test_app = get_test_app(dump_old_app=False) cookie_name = mg_globals.app_config['csrf_cookie_name'] # get login page @@ -34,9 +33,8 @@ def test_csrf_cookie_set(test_app): assert response.headers.get('Vary', False) == 'Cookie' -@setup_fresh_app -def test_csrf_token_must_match(test_app): - +def test_csrf_token_must_match(): + test_app = get_test_app(dump_old_app=False) # construct a request with no cookie or form token assert test_app.post('/auth/login/', extra_environ={'gmg.verify_csrf': True}, @@ -65,9 +63,8 @@ def test_csrf_token_must_match(test_app): extra_environ={'gmg.verify_csrf': True}).\ status_int == 200 -@setup_fresh_app -def test_csrf_exempt(test_app): - +def test_csrf_exempt(): + test_app = get_test_app(dump_old_app=False) # monkey with the views to decorate a known endpoint import mediagoblin.auth.views from mediagoblin.meddleware.csrf import csrf_exempt diff --git a/mediagoblin/tests/test_messages.py b/mediagoblin/tests/test_messages.py index d3b84828..c587e599 100644 --- a/mediagoblin/tests/test_messages.py +++ b/mediagoblin/tests/test_messages.py @@ -15,30 +15,31 @@ # along with this program. If not, see . from mediagoblin.messages import fetch_messages, add_message -from mediagoblin.tests.tools import setup_fresh_app +from mediagoblin.tests.tools import get_test_app from mediagoblin.tools import template -@setup_fresh_app -def test_messages(test_app): + +def test_messages(): """ Added messages should show up in the request.session, fetched messages should be the same as the added ones, and fetching should clear the message list. """ + test_app = get_test_app(dump_old_app=False) # Aquire a request object test_app.get('/') context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] request = context['request'] - + # The message queue should be empty assert request.session.get('messages', []) == [] - + # Adding a message should modify the session accordingly add_message(request, 'herp_derp', 'First!') test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}] assert request.session['messages'] == test_msg_queue - + # fetch_messages should return and empty the queue assert fetch_messages(request) == test_msg_queue assert request.session.get('messages') == [] diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 94ae5a51..8a96e7d0 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,11 +16,9 @@ from nose.tools import assert_equal -from mediagoblin.tests.tools import setup_fresh_app +from mediagoblin.tests.tools import get_test_app - -@setup_fresh_app -def test_404_for_non_existent(test_app): - assert_equal(test_app.get('/does-not-exist/', - expect_errors=True).status_int, - 404) +def test_404_for_non_existent(): + test_app = get_test_app(dump_old_app=False) + res = test_app.get('/does-not-exist/', expect_errors=True) + assert_equal(res.status_int, 404) diff --git a/mediagoblin/tests/test_tags.py b/mediagoblin/tests/test_tags.py index bc657660..73af2eea 100644 --- a/mediagoblin/tests/test_tags.py +++ b/mediagoblin/tests/test_tags.py @@ -14,17 +14,17 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.tests.tools import setup_fresh_app +from mediagoblin.tests.tools import get_test_app from mediagoblin.tools import text -@setup_fresh_app -def test_list_of_dicts_conversion(test_app): +def test_list_of_dicts_conversion(): """ When the user adds tags to a media entry, the string from the form is converted into a list of tags, where each tag is stored in the database as a dict. Each tag dict should contain the tag's name and slug. Another function performs the reverse operation when populating a form to edit tags. """ + test_app = get_test_app(dump_old_app=False) # Leading, trailing, and internal whitespace should be removed and slugified assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [ {'name': u'sleep', 'slug': u'sleep'}, -- 2.25.1