tests: More instances where a fresh database is not needed

Save test runtime by not dumping the databases when not needed.
This commit is contained in:
Sebastian Spaeth 2013-01-08 13:31:16 +01:00
parent 40cec2b444
commit b97144dcc9
5 changed files with 27 additions and 31 deletions

View File

@ -22,7 +22,7 @@ from nose.tools import assert_equal
from mediagoblin import mg_globals from mediagoblin import mg_globals
from mediagoblin.auth import lib as auth_lib from mediagoblin.auth import lib as auth_lib
from mediagoblin.db.models import User 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 from mediagoblin.tools import template, mail
@ -67,11 +67,11 @@ def test_bcrypt_gen_password_hash():
'notthepassword', hashed_pw, '3><7R45417') 'notthepassword', hashed_pw, '3><7R45417')
@setup_fresh_app def test_register_views():
def test_register_views(test_app):
""" """
Massive test function that all our registration-related views all work. 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 # Test doing a simple GET on the page
# ----------------------------------- # -----------------------------------
@ -311,11 +311,11 @@ def test_register_views(test_app):
'mediagoblin/root.html') 'mediagoblin/root.html')
@setup_fresh_app def test_authentication_views():
def test_authentication_views(test_app):
""" """
Test logging in and logging out Test logging in and logging out
""" """
test_app = get_test_app(dump_old_app=False)
# Make a new user # Make a new user
test_user = fixture_add_user(active_user=False) test_user = fixture_add_user(active_user=False)

View File

@ -14,13 +14,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin.tests.tools import setup_fresh_app from mediagoblin.tests.tools import get_test_app
from mediagoblin import mg_globals from mediagoblin import mg_globals
@setup_fresh_app def test_csrf_cookie_set():
def test_csrf_cookie_set(test_app): test_app = get_test_app(dump_old_app=False)
cookie_name = mg_globals.app_config['csrf_cookie_name'] cookie_name = mg_globals.app_config['csrf_cookie_name']
# get login page # get login page
@ -34,9 +33,8 @@ def test_csrf_cookie_set(test_app):
assert response.headers.get('Vary', False) == 'Cookie' assert response.headers.get('Vary', False) == 'Cookie'
@setup_fresh_app def test_csrf_token_must_match():
def test_csrf_token_must_match(test_app): test_app = get_test_app(dump_old_app=False)
# construct a request with no cookie or form token # construct a request with no cookie or form token
assert test_app.post('/auth/login/', assert test_app.post('/auth/login/',
extra_environ={'gmg.verify_csrf': True}, extra_environ={'gmg.verify_csrf': True},
@ -65,9 +63,8 @@ def test_csrf_token_must_match(test_app):
extra_environ={'gmg.verify_csrf': True}).\ extra_environ={'gmg.verify_csrf': True}).\
status_int == 200 status_int == 200
@setup_fresh_app def test_csrf_exempt():
def test_csrf_exempt(test_app): test_app = get_test_app(dump_old_app=False)
# monkey with the views to decorate a known endpoint # monkey with the views to decorate a known endpoint
import mediagoblin.auth.views import mediagoblin.auth.views
from mediagoblin.meddleware.csrf import csrf_exempt from mediagoblin.meddleware.csrf import csrf_exempt

View File

@ -15,30 +15,31 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin.messages import fetch_messages, add_message 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 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, Added messages should show up in the request.session,
fetched messages should be the same as the added ones, fetched messages should be the same as the added ones,
and fetching should clear the message list. and fetching should clear the message list.
""" """
test_app = get_test_app(dump_old_app=False)
# Aquire a request object # Aquire a request object
test_app.get('/') test_app.get('/')
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
request = context['request'] request = context['request']
# The message queue should be empty # The message queue should be empty
assert request.session.get('messages', []) == [] assert request.session.get('messages', []) == []
# Adding a message should modify the session accordingly # Adding a message should modify the session accordingly
add_message(request, 'herp_derp', 'First!') add_message(request, 'herp_derp', 'First!')
test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}] test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}]
assert request.session['messages'] == test_msg_queue assert request.session['messages'] == test_msg_queue
# fetch_messages should return and empty the queue # fetch_messages should return and empty the queue
assert fetch_messages(request) == test_msg_queue assert fetch_messages(request) == test_msg_queue
assert request.session.get('messages') == [] assert request.session.get('messages') == []

View File

@ -16,11 +16,9 @@
from nose.tools import assert_equal from nose.tools import assert_equal
from mediagoblin.tests.tools import setup_fresh_app from mediagoblin.tests.tools import get_test_app
def test_404_for_non_existent():
@setup_fresh_app test_app = get_test_app(dump_old_app=False)
def test_404_for_non_existent(test_app): res = test_app.get('/does-not-exist/', expect_errors=True)
assert_equal(test_app.get('/does-not-exist/', assert_equal(res.status_int, 404)
expect_errors=True).status_int,
404)

View File

@ -14,17 +14,17 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin.tests.tools import setup_fresh_app from mediagoblin.tests.tools import get_test_app
from mediagoblin.tools import text from mediagoblin.tools import text
@setup_fresh_app def test_list_of_dicts_conversion():
def test_list_of_dicts_conversion(test_app):
""" """
When the user adds tags to a media entry, the string from the form is 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 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 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. 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 # Leading, trailing, and internal whitespace should be removed and slugified
assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [ assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
{'name': u'sleep', 'slug': u'sleep'}, {'name': u'sleep', 'slug': u'sleep'},