Dot-Notation for Users.status
[mediagoblin.git] / mediagoblin / tests / test_auth.py
index 40961eca02621263837b222a8d6edc1b78e4bd3e..bd79a40750ad6c859dfde9672c79f3e902f00147 100644 (file)
@@ -20,7 +20,7 @@ import datetime
 from nose.tools import assert_equal
 
 from mediagoblin.auth import lib as auth_lib
-from mediagoblin.tests.tools import setup_fresh_app
+from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user
 from mediagoblin import mg_globals
 from mediagoblin.tools import template, mail
 
@@ -162,13 +162,13 @@ def test_register_views(test_app):
     new_user = mg_globals.database.User.find_one(
         {'username': 'happygirl'})
     assert new_user
-    assert new_user['status'] == u'needs_email_verification'
-    assert new_user['email_verified'] == False
+    assert new_user.status == u'needs_email_verification'
+    assert new_user.email_verified == False
 
     ## 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
@@ -185,7 +185,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']]
 
@@ -193,7 +193,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']
@@ -202,8 +202,8 @@ def test_register_views(test_app):
     new_user = mg_globals.database.User.find_one(
         {'username': 'happygirl'})
     assert new_user
-    assert new_user['status'] == u'needs_email_verification'
-    assert new_user['email_verified'] == False
+    assert new_user.status == u'needs_email_verification'
+    assert new_user.email_verified == False
 
     ## Verify the email activation works
     template.clear_test_template_context()
@@ -216,8 +216,8 @@ def test_register_views(test_app):
     new_user = mg_globals.database.User.find_one(
         {'username': 'happygirl'})
     assert new_user
-    assert new_user['status'] == u'active'
-    assert new_user['email_verified'] == True
+    assert new_user.status == u'active'
+    assert new_user.email_verified == True
 
     # Uniqueness checks
     # -----------------
@@ -269,7 +269,7 @@ def test_register_views(test_app):
 
     # user should have matching parameters
     new_user = mg_globals.database.User.find_one({'username': '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
@@ -280,16 +280,16 @@ 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=400)
-    assert response.status == '400 Bad Request'
+            new_user._id), status=404)
+    assert_equal(response.status, '404 Not Found')
 
     ## Try using an expired token to change password, shouldn't work
     template.clear_test_template_context()
     real_token_expiration = new_user['fp_token_expire']
     new_user['fp_token_expire'] = datetime.datetime.now()
     new_user.save()
-    response = test_app.get("%s?%s" % (path, get_params), status=400)
-    assert response.status == '400 Bad Request'
+    response = test_app.get("%s?%s" % (path, get_params), status=404)
+    assert_equal(response.status, '404 Not Found')
     new_user['fp_token_expire'] = real_token_expiration
     new_user.save()
 
@@ -332,11 +332,7 @@ def test_authentication_views(test_app):
     Test logging in and logging out
     """
     # Make a new user
-    test_user = mg_globals.database.User()
-    test_user['username'] = u'chris'
-    test_user['email'] = u'chris@example.com'
-    test_user['pw_hash'] = auth_lib.bcrypt_gen_password_hash('toast')
-    test_user.save()
+    test_user = fixture_add_user(active_user=False)
 
     # Get login
     # ---------
@@ -412,7 +408,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
     # -----------------