You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/09/29 17:31:59 UTC

[4/4] git commit: [#5700] Refactored & improved tests

[#5700] Refactored & improved tests


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/b020149b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/b020149b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/b020149b

Branch: refs/heads/master
Commit: b020149b6954c22574f51562c73b1efd3d9b2620
Parents: 6a489c0
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Fri Sep 26 12:06:16 2014 -0700
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Sep 29 15:31:41 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                 |  2 +-
 Allura/allura/tests/functional/test_auth.py | 23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/b020149b/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 504a5f6..bf4696f 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -274,7 +274,7 @@ class AuthenticationProvider(object):
         raise NotImplementedError, 'get_last_password_updated'
 
     def get_primary_email_address(self, user_record):
-        return user_record.get_pref('email_address')
+        return user_record.get_pref('email_address') if user_record else None
 
 
     def is_password_expired(self, user):

http://git-wip-us.apache.org/repos/asf/allura/blob/b020149b/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 665f4ae..4514725 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -839,6 +839,8 @@ class TestPreferences(TestController):
 
 class TestPasswordReset(TestController):
 
+    test_primary_email = 'testprimaryaddr@mail.com'
+
     @patch('allura.tasks.mail_tasks.sendmail')
     @patch('allura.lib.helpers.gen_message_id')
     def test_email_unconfirmed(self, gen_message_id, sendmail):
@@ -867,31 +869,36 @@ class TestPasswordReset(TestController):
     @patch('allura.lib.helpers.gen_message_id')
     def test_only_primary_email_reset_allowed(self, gen_message_id, sendmail):
         user = M.User.query.get(username='test-admin')
-        user.claim_address('aaa@aaa.com')
-        user.set_pref('email_address', 'aaa@aaa.com')
-        email = M.EmailAddress.query.find({'email': 'aaa@aaa.com'}).first()
+        user.claim_address(self.test_primary_email)
+        user.set_pref('email_address', self.test_primary_email)
+
+        email = M.EmailAddress.query.find({'email': self.test_primary_email}).first()
         email.confirmed = True
         ThreadLocalORMSession.flush_all()
+
         with h.push_config(config, **{'auth.allow_non_primary_email_password_reset': 'false'}):
-            self.app.post('/auth/password_recovery_hash', {'email': email.email})
+            self.app.post('/auth/password_recovery_hash', {'email': self.test_primary_email})
             hash = user.get_tool_data('AuthPasswordReset', 'hash')
             assert hash is not None
-
+            args, kwargs = sendmail.post.call_args
+            assert_equal(kwargs['toaddr'], self.test_primary_email)
 
     @patch('allura.tasks.mail_tasks.sendsimplemail')
     @patch('allura.lib.helpers.gen_message_id')
     def test_non_primary_email_reset_allowed(self, gen_message_id, sendmail):
         user = M.User.query.get(username='test-admin')
         email1 = M.EmailAddress.query.find({'claimed_by_user_id': user._id}).first()
-        user.claim_address('aaa@aaa.com')
-        user.set_pref('email_address', 'aaa@aaa.com')
-        email = M.EmailAddress.query.find({'email': 'aaa@aaa.com'}).first()
+        user.claim_address(self.test_primary_email)
+        user.set_pref('email_address', self.test_primary_email)
+        email = M.EmailAddress.query.find({'email': self.test_primary_email}).first()
         email.confirmed = True
         ThreadLocalORMSession.flush_all()
         with h.push_config(config, **{'auth.allow_non_primary_email_password_reset': 'true'}):
             self.app.post('/auth/password_recovery_hash', {'email': email1.email})
             hash = user.get_tool_data('AuthPasswordReset', 'hash')
             assert hash is not None
+            args, kwargs = sendmail.post.call_args
+            assert_equal(kwargs['toaddr'], email1.email)
 
 
     @patch('allura.tasks.mail_tasks.sendsimplemail')