Save test runtime by not dumping the databases when not needed.
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
'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
# -----------------------------------
'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)
# 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/>.
-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
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},
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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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') == []
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)
# 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/>.
-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'},