From 1be247b36e58c8c71a974b65dff7194f28483f12 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 18 Jan 2013 11:40:40 +0100 Subject: [PATCH] Rename get_test_app to get_app. nosetests runs everything that even vaguely looks like a test case... even our get_test_app. And as it is imported everywhere... it is run everywhere as a test case. Renaming it saves us about 10+ tests and a few seconds of time. --- mediagoblin/tests/test_api.py | 4 ++-- mediagoblin/tests/test_auth.py | 10 +++++----- mediagoblin/tests/test_csrf_middleware.py | 8 ++++---- mediagoblin/tests/test_edit.py | 4 ++-- mediagoblin/tests/test_http_callback.py | 4 ++-- mediagoblin/tests/test_messages.py | 4 ++-- mediagoblin/tests/test_misc.py | 4 ++-- mediagoblin/tests/test_oauth.py | 4 ++-- mediagoblin/tests/test_submission.py | 4 ++-- mediagoblin/tests/test_tags.py | 4 ++-- mediagoblin/tests/test_tests.py | 10 +++++----- mediagoblin/tests/tools.py | 4 ++-- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 4b784da3..82b1c1b4 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -22,7 +22,7 @@ from pkg_resources import resource_filename from mediagoblin import mg_globals from mediagoblin.tools import template, pluginapi -from mediagoblin.tests.tools import get_test_app, fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user _log = logging.getLogger(__name__) @@ -44,7 +44,7 @@ BIG_BLUE = resource('bigblue.png') class TestAPI(object): def setUp(self): - self.app = get_test_app(dump_old_app=False) + self.app = get_app(dump_old_app=False) self.db = mg_globals.database self.user_password = u'4cc355_70k3N' diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index a40c9cbc..103bea6b 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 get_test_app, fixture_add_user +from mediagoblin.tests.tools import setup_fresh_app, get_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') -def test_register_views(): +@setup_fresh_app +def test_register_views(test_app): """ 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 # ----------------------------------- @@ -125,7 +125,7 @@ def test_register_views(): u'Invalid email address.'] ## At this point there should be no users in the database ;) - assert not User.query.count() + assert_equal(User.query.count(), 0) # Successful register # ------------------- @@ -315,7 +315,7 @@ def test_authentication_views(): """ Test logging in and logging out """ - test_app = get_test_app(dump_old_app=False) + test_app = get_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 22a0eb04..e720264c 100644 --- a/mediagoblin/tests/test_csrf_middleware.py +++ b/mediagoblin/tests/test_csrf_middleware.py @@ -14,12 +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 get_test_app +from mediagoblin.tests.tools import get_app from mediagoblin import mg_globals def test_csrf_cookie_set(): - test_app = get_test_app(dump_old_app=False) + test_app = get_app(dump_old_app=False) cookie_name = mg_globals.app_config['csrf_cookie_name'] # get login page @@ -37,7 +37,7 @@ def test_csrf_token_must_match(): # We need a fresh app for this test on webtest < 1.3.6. # We do not understand why, but it fixes the tests. # If we require webtest >= 1.3.6, we can switch to a non fresh app here. - test_app = get_test_app(dump_old_app=True) + test_app = get_app(dump_old_app=True) # construct a request with no cookie or form token assert test_app.post('/auth/login/', @@ -68,7 +68,7 @@ def test_csrf_token_must_match(): status_int == 200 def test_csrf_exempt(): - test_app = get_test_app(dump_old_app=False) + test_app = get_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_edit.py b/mediagoblin/tests/test_edit.py index 4bea9243..7db6eaea 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -18,13 +18,13 @@ from nose.tools import assert_equal from mediagoblin import mg_globals from mediagoblin.db.models import User -from mediagoblin.tests.tools import get_test_app, fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user from mediagoblin.tools import template from mediagoblin.auth.lib import bcrypt_check_password class TestUserEdit(object): def setUp(self): - self.app = get_test_app(dump_old_app=False) + self.app = get_app(dump_old_app=False) # set up new user self.user_password = u'toast' self.user = fixture_add_user(password = self.user_password) diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py index 0f6e489f..8bee7045 100644 --- a/mediagoblin/tests/test_http_callback.py +++ b/mediagoblin/tests/test_http_callback.py @@ -20,14 +20,14 @@ from urlparse import urlparse, parse_qs from mediagoblin import mg_globals from mediagoblin.tools import processing -from mediagoblin.tests.tools import get_test_app, fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user from mediagoblin.tests.test_submission import GOOD_PNG from mediagoblin.tests import test_oauth as oauth class TestHTTPCallback(object): def setUp(self): - self.app = get_test_app(dump_old_app=False) + self.app = get_app(dump_old_app=False) self.db = mg_globals.database self.user_password = u'secret' diff --git a/mediagoblin/tests/test_messages.py b/mediagoblin/tests/test_messages.py index c587e599..4c0f3e2e 100644 --- a/mediagoblin/tests/test_messages.py +++ b/mediagoblin/tests/test_messages.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from mediagoblin.messages import fetch_messages, add_message -from mediagoblin.tests.tools import get_test_app +from mediagoblin.tests.tools import get_app from mediagoblin.tools import template @@ -26,7 +26,7 @@ def test_messages(): 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) + test_app = get_app(dump_old_app=False) # Aquire a request object test_app.get('/') context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 8a96e7d0..ae5d7e50 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,9 +16,9 @@ from nose.tools import assert_equal -from mediagoblin.tests.tools import get_test_app +from mediagoblin.tests.tools import get_app def test_404_for_non_existent(): - test_app = get_test_app(dump_old_app=False) + test_app = get_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_oauth.py b/mediagoblin/tests/test_oauth.py index a72f766e..94ba5dab 100644 --- a/mediagoblin/tests/test_oauth.py +++ b/mediagoblin/tests/test_oauth.py @@ -21,7 +21,7 @@ from urlparse import parse_qs, urlparse from mediagoblin import mg_globals from mediagoblin.tools import template, pluginapi -from mediagoblin.tests.tools import get_test_app, fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user _log = logging.getLogger(__name__) @@ -29,7 +29,7 @@ _log = logging.getLogger(__name__) class TestOAuth(object): def setUp(self): - self.app = get_test_app() + self.app = get_app() self.db = mg_globals.database self.pman = pluginapi.PluginManager() diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 53330c48..606c0e27 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -24,7 +24,7 @@ import os from nose.tools import assert_equal, assert_true from pkg_resources import resource_filename -from mediagoblin.tests.tools import get_test_app, \ +from mediagoblin.tests.tools import get_app, \ fixture_add_user from mediagoblin import mg_globals from mediagoblin.tools import template @@ -50,7 +50,7 @@ REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request'] class TestSubmission: def setUp(self): - self.test_app = get_test_app(dump_old_app=False) + self.test_app = get_app(dump_old_app=False) # TODO: Possibly abstract into a decorator like: # @as_authenticated_user('chris') diff --git a/mediagoblin/tests/test_tags.py b/mediagoblin/tests/test_tags.py index 73af2eea..ccb93085 100644 --- a/mediagoblin/tests/test_tags.py +++ b/mediagoblin/tests/test_tags.py @@ -14,7 +14,7 @@ # 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 get_test_app +from mediagoblin.tests.tools import get_app from mediagoblin.tools import text def test_list_of_dicts_conversion(): @@ -24,7 +24,7 @@ def test_list_of_dicts_conversion(): 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) + test_app = get_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'}, diff --git a/mediagoblin/tests/test_tests.py b/mediagoblin/tests/test_tests.py index d09e8f28..d539f1e0 100644 --- a/mediagoblin/tests/test_tests.py +++ b/mediagoblin/tests/test_tests.py @@ -15,22 +15,22 @@ # along with this program. If not, see . from mediagoblin import mg_globals -from mediagoblin.tests.tools import get_test_app, fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user from mediagoblin.db.models import User -def test_get_test_app_wipes_db(): +def test_get_app_wipes_db(): """ Make sure we get a fresh database on every wipe :) """ - get_test_app(dump_old_app=True) + get_app(dump_old_app=True) assert User.query.count() == 0 fixture_add_user() assert User.query.count() == 1 - get_test_app(dump_old_app=False) + get_app(dump_old_app=False) assert User.query.count() == 1 - get_test_app(dump_old_app=True) + get_app(dump_old_app=True) assert User.query.count() == 0 diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 3e78b2e3..30218ede 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -103,7 +103,7 @@ def suicide_if_bad_celery_environ(): raise BadCeleryEnviron(BAD_CELERY_MESSAGE) -def get_test_app(dump_old_app=True): +def get_app(dump_old_app=True): suicide_if_bad_celery_environ() # Make sure we've turned on testing @@ -164,7 +164,7 @@ def setup_fresh_app(func): """ @wraps(func) def wrapper(*args, **kwargs): - test_app = get_test_app() + test_app = get_app() testing.clear_test_buckets() return func(test_app, *args, **kwargs) -- 2.25.1