From eabe6b678a98fd06d9cd8463935a3b842f41485c Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 13 Nov 2011 19:25:06 +0100 Subject: Dot-Notation for "_id" Note: Migrations can't use "Dot Notation"! Migrations run on pymongo, not mongokit. So they can't use the "Dot Notation". This isn't really a big issue, as migrations are anyway quite mongo specific. --- mediagoblin/tests/test_auth.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 40961eca..153c6e53 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -168,7 +168,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 @@ -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'] @@ -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,7 +280,7 @@ 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) + new_user._id), status=400) assert response.status == '400 Bad Request' ## Try using an expired token to change password, shouldn't work @@ -412,7 +412,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 # ----------------- -- cgit v1.2.3 From 9754802d4bca036b8fb0b50db948dd2eb8f64bd6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 1 Dec 2011 23:33:47 +0100 Subject: fixture_add_user: Factoring a unit test tool Some unit tests need a user in the database, especially to act as that user. Some routines did that on their own. So factored this whole thing into a new function and use it around. --- mediagoblin/tests/test_auth.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 153c6e53..acef3d26 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -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 @@ -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 # --------- -- cgit v1.2.3 From 93e4622491ff6bed339267cea2a0a98a7af3c8d8 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 2 Dec 2011 00:09:13 +0100 Subject: Expect 404 in unit tests, if we now use 404. Our unit tests for auth were expecting a 400. Well, now we give a 404. So expect that! I'm not completely sure, if the 404 is the right thing here, but that's another topic. --- mediagoblin/tests/test_auth.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 153c6e53..ee085761 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -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() -- cgit v1.2.3 From 4facc7a0a21a57023f0d3707f1a3483ca7a560c8 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 18:54:52 +0100 Subject: Dot-Notation for Users.email_verified --- mediagoblin/tests/test_auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 2faf0f25..ad9a5bca 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -163,7 +163,7 @@ def test_register_views(test_app): {'username': 'happygirl'}) assert new_user assert new_user['status'] == u'needs_email_verification' - assert new_user['email_verified'] == False + assert new_user.email_verified == False ## Make sure user is logged in request = template.TEMPLATE_TEST_CONTEXT[ @@ -203,7 +203,7 @@ def test_register_views(test_app): {'username': 'happygirl'}) assert new_user assert new_user['status'] == u'needs_email_verification' - assert new_user['email_verified'] == False + assert new_user.email_verified == False ## Verify the email activation works template.clear_test_template_context() @@ -217,7 +217,7 @@ def test_register_views(test_app): {'username': 'happygirl'}) assert new_user assert new_user['status'] == u'active' - assert new_user['email_verified'] == True + assert new_user.email_verified == True # Uniqueness checks # ----------------- -- cgit v1.2.3 From 7a3d00ec217cc3fd44788b9d8c63ab9f7b1d05a7 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 19:01:26 +0100 Subject: Dot-Notation for Users.status --- mediagoblin/tests/test_auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index ad9a5bca..bd79a407 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -162,7 +162,7 @@ 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.status == u'needs_email_verification' assert new_user.email_verified == False ## Make sure user is logged in @@ -202,7 +202,7 @@ 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.status == u'needs_email_verification' assert new_user.email_verified == False ## Verify the email activation works @@ -216,7 +216,7 @@ 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.status == u'active' assert new_user.email_verified == True # Uniqueness checks -- cgit v1.2.3 From 00bb95502e01f8c8fcaa5652889a5ed423051d7c Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 19:04:13 +0100 Subject: Dot-Notation for Users.verification_key --- mediagoblin/tests/test_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index bd79a407..7cb867d7 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -187,7 +187,7 @@ def test_register_views(test_app): assert parsed_get_params['userid'] == [ unicode(new_user._id)] assert parsed_get_params['token'] == [ - new_user['verification_key']] + new_user.verification_key] ## Try verifying with bs verification key, shouldn't work template.clear_test_template_context() -- cgit v1.2.3 From dc39e4555c9e104ae9d7b38f231a848fe106d1a0 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 19:21:33 +0100 Subject: Dot-Notation for Users.fp_verification_key --- mediagoblin/tests/test_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 7cb867d7..2dcb5c14 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -270,7 +270,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['token'] == [new_user['fp_verification_key']] + assert parsed_get_params['token'] == [new_user.fp_verification_key] ### The forgotten password token should be set to expire in ~ 10 days # A few ticks have expired so there are only 9 full days left... -- cgit v1.2.3 From 2d540fed8b511c76819a836da3d62875d20b6547 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 19:24:15 +0100 Subject: Dot-Notation for Users.fp_token_expire --- mediagoblin/tests/test_auth.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 2dcb5c14..d3b8caf1 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -274,7 +274,7 @@ def test_register_views(test_app): ### The forgotten password token should be set to expire in ~ 10 days # A few ticks have expired so there are only 9 full days left... - assert (new_user['fp_token_expire'] - datetime.datetime.now()).days == 9 + assert (new_user.fp_token_expire - datetime.datetime.now()).days == 9 ## Try using a bs password-changing verification key, shouldn't work template.clear_test_template_context() @@ -285,12 +285,12 @@ def test_register_views(test_app): ## 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() + 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=404) assert_equal(response.status, '404 Not Found') - new_user['fp_token_expire'] = real_token_expiration + new_user.fp_token_expire = real_token_expiration new_user.save() ## Verify step 1 of password-change works -- can see form to change password -- cgit v1.2.3 From 7c7ba01ee3450ded81f3ec9630cde0818865ed03 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Fri, 30 Dec 2011 19:11:47 +0100 Subject: Fixed broken confirm_password test --- mediagoblin/tests/test_auth.py | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index d3b8caf1..9b0dea66 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -89,7 +89,6 @@ def test_register_views(test_app): form = context['register_form'] assert form.username.errors == [u'This field is required.'] assert form.password.errors == [u'This field is required.'] - assert form.confirm_password.errors == [u'This field is required.'] assert form.email.errors == [u'This field is required.'] # Try to register with fields that are known to be invalid @@ -101,7 +100,6 @@ def test_register_views(test_app): '/auth/register/', { 'username': 'l', 'password': 'o', - 'confirm_password': 'o', 'email': 'l'}) context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html'] form = context['register_form'] @@ -125,18 +123,6 @@ def test_register_views(test_app): assert form.email.errors == [ u'Invalid email address.'] - ## mismatching passwords - template.clear_test_template_context() - test_app.post( - '/auth/register/', { - 'password': 'herpderp', - 'confirm_password': 'derpherp'}) - context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html'] - form = context['register_form'] - - assert form.password.errors == [ - u'Passwords must match.'] - ## At this point there should be no users in the database ;) assert not mg_globals.database.User.find().count() @@ -147,7 +133,6 @@ def test_register_views(test_app): '/auth/register/', { 'username': 'happygirl', 'password': 'iamsohappy', - 'confirm_password': 'iamsohappy', 'email': 'happygrrl@example.org'}) response.follow() @@ -227,7 +212,6 @@ def test_register_views(test_app): '/auth/register/', { 'username': 'happygirl', 'password': 'iamsohappy2', - 'confirm_password': 'iamsohappy2', 'email': 'happygrrl2@example.org'}) context = template.TEMPLATE_TEST_CONTEXT[ @@ -304,7 +288,6 @@ def test_register_views(test_app): '/auth/forgot_password/verify/', { 'userid': parsed_get_params['userid'], 'password': 'iamveryveryhappy', - 'confirm_password': 'iamveryveryhappy', 'token': parsed_get_params['token']}) response.follow() assert template.TEMPLATE_TEST_CONTEXT.has_key( -- cgit v1.2.3 From 4601c30c2e80734cf3a18472c2e29a7f920b9604 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 31 Dec 2011 22:57:08 +0100 Subject: Fixed submission error handling and broken tests - Fixed broken test_auth test - Fixed error handling on submission, it now raises the exception if it is not explicitly relevant to file submission. --- mediagoblin/tests/test_auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 9b0dea66..e54ffa5a 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -233,9 +233,9 @@ def test_register_views(test_app): ## Did we redirect to the proper page? Use the right template? assert_equal( urlparse.urlsplit(response.location)[2], - '/auth/forgot_password/email_sent/') + '/auth/login/') assert template.TEMPLATE_TEST_CONTEXT.has_key( - 'mediagoblin/auth/fp_email_sent.html') + 'mediagoblin/auth/login.html') ## Make sure link to change password is sent by email assert len(mail.EMAIL_TEST_INBOX) == 1 -- cgit v1.2.3 From 445d811043c5cb8b801b91604da6e3967d7ba3b7 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 1 Jan 2012 19:20:38 +0100 Subject: Fix unit tests for new forget password flow After changing the password, the login page is now shown. It contains a message. (we can't test for that easily currently. There is a bug open on this problem.) At least for the login page being shown now. --- mediagoblin/tests/test_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests/test_auth.py') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index e54ffa5a..411b4539 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -291,7 +291,7 @@ def test_register_views(test_app): 'token': parsed_get_params['token']}) response.follow() assert template.TEMPLATE_TEST_CONTEXT.has_key( - 'mediagoblin/auth/fp_changed_success.html') + 'mediagoblin/auth/login.html') ## Verify step 2.2 of password-change works -- login w/ new password success template.clear_test_template_context() -- cgit v1.2.3