aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/test_auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tests/test_auth.py')
-rw-r--r--mediagoblin/tests/test_auth.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index 1b84b435..a40c9cbc 100644
--- a/mediagoblin/tests/test_auth.py
+++ b/mediagoblin/tests/test_auth.py
@@ -19,9 +19,10 @@ import datetime
from nose.tools import assert_equal
-from mediagoblin.auth import lib as auth_lib
-from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user
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.tools import template, mail
@@ -66,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
# -----------------------------------
@@ -124,7 +125,7 @@ def test_register_views(test_app):
u'Invalid email address.']
## At this point there should be no users in the database ;)
- assert not mg_globals.database.User.find().count()
+ assert not User.query.count()
# Successful register
# -------------------
@@ -153,7 +154,7 @@ def test_register_views(test_app):
## Make sure user is logged in
request = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/user_pages/user.html']['request']
- assert request.session['user_id'] == unicode(new_user._id)
+ assert request.session['user_id'] == unicode(new_user.id)
## Make sure we get email confirmation, and try verifying
assert len(mail.EMAIL_TEST_INBOX) == 1
@@ -170,7 +171,7 @@ def test_register_views(test_app):
### user should have these same parameters
assert parsed_get_params['userid'] == [
- unicode(new_user._id)]
+ unicode(new_user.id)]
assert parsed_get_params['token'] == [
new_user.verification_key]
@@ -178,7 +179,7 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.get(
"/auth/verify_email/?userid=%s&token=total_bs" % unicode(
- new_user._id))
+ new_user.id))
response.follow()
context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/user_pages/user.html']
@@ -253,7 +254,7 @@ def test_register_views(test_app):
# user should have matching parameters
new_user = mg_globals.database.User.find_one({'username': u'happygirl'})
- assert parsed_get_params['userid'] == [unicode(new_user._id)]
+ assert parsed_get_params['userid'] == [unicode(new_user.id)]
assert parsed_get_params['token'] == [new_user.fp_verification_key]
### The forgotten password token should be set to expire in ~ 10 days
@@ -264,8 +265,8 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.get(
"/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode(
- new_user._id), status=404)
- assert_equal(response.status, '404 Not Found')
+ new_user.id), status=404)
+ assert_equal(response.status.split()[0], u'404') # status="404 NOT FOUND"
## Try using an expired token to change password, shouldn't work
template.clear_test_template_context()
@@ -274,7 +275,7 @@ def test_register_views(test_app):
new_user.fp_token_expire = datetime.datetime.now()
new_user.save()
response = test_app.get("%s?%s" % (path, get_params), status=404)
- assert_equal(response.status, '404 Not Found')
+ assert_equal(response.status.split()[0], u'404') # status="404 NOT FOUND"
new_user.fp_token_expire = real_token_expiration
new_user.save()
@@ -310,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)
@@ -392,7 +393,7 @@ def test_authentication_views(test_app):
# Make sure user is in the session
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
session = context['request'].session
- assert session['user_id'] == unicode(test_user._id)
+ assert session['user_id'] == unicode(test_user.id)
# Successful logout
# -----------------