allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [2/3] allura git commit: [#7823] ticket:724 Add tests for new EmailAddress.canonical behavior
Date Thu, 12 Feb 2015 14:07:15 GMT
[#7823] ticket:724 Add tests for new EmailAddress.canonical behavior


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

Branch: refs/heads/ib/7823
Commit: 46cb54ab6c6a48553d71a8f8709f9f74cf97195e
Parents: c669825
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Feb 12 10:28:46 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Thu Feb 12 10:39:03 2015 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_auth.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/46cb54ab/Allura/allura/tests/model/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 3356ce1..12db982 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -74,6 +74,7 @@ def test_email_address():
 @with_setup(setUp)
 def test_email_address_lookup_helpers():
     addr = M.EmailAddress.create('TEST@DOMAIN.NET')
+    nobody = M.EmailAddress.create('nobody@example.com')
     ThreadLocalORMSession.flush_all()
     assert_equal(addr.email, 'TEST@domain.net')
 
@@ -81,14 +82,30 @@ def test_email_address_lookup_helpers():
     assert_equal(M.EmailAddress.get(email='TEST@domain.net'), addr)
     assert_equal(M.EmailAddress.get(email='test@domain.net'), None)
     assert_equal(M.EmailAddress.get(email=None), None)
+    assert_equal(M.EmailAddress.get(email='nobody@example.com'), nobody)
+    # invalid email returns None, but not nobody@example.com as before
+    assert_equal(M.EmailAddress.get(email='invalid'), None)
 
     assert_equal(M.EmailAddress.find(dict(email='TEST@DOMAIN.NET')).all(), [addr])
     assert_equal(M.EmailAddress.find(dict(email='TEST@domain.net')).all(), [addr])
     assert_equal(M.EmailAddress.find(dict(email='test@domain.net')).all(), [])
     assert_equal(M.EmailAddress.find(dict(email=None)).all(), [])
+    assert_equal(M.EmailAddress.find(dict(email='nobody@example.com')).all(), [nobody])
+    # invalid email returns empty query, but not nobody@example.com as before
+    assert_equal(M.EmailAddress.find(dict(email='invalid')).all(), [])
 
 
 @with_setup(setUp)
+def test_email_address_canonical():
+    assert_equal(M.EmailAddress.canonical('nobody@EXAMPLE.COM'),
+                 'nobody@example.com')
+    assert_equal(M.EmailAddress.canonical('nobody@example.com'),
+                 'nobody@example.com')
+    assert_equal(M.EmailAddress.canonical('I Am Nobody <nobody@example.com>'),
+                 'nobody@example.com')
+    assert_equal(M.EmailAddress.canonical('invalid'), None)
+
+@with_setup(setUp)
 def test_email_address_send_verification_link():
     addr = M.EmailAddress(email='test_admin@domain.net',
                           claimed_by_user_id=c.user._id)
@@ -178,7 +195,6 @@ def test_user_by_email_address(log):
                            claimed_by_user_id=u1._id)
     addr2 = M.EmailAddress(email='abc123@abc.me', confirmed=True,
                            claimed_by_user_id=u2._id)
-
     # both users are disabled
     u1.disabled, u2.disabled = True, True
     ThreadLocalORMSession.flush_all()
@@ -197,6 +213,14 @@ def test_user_by_email_address(log):
     assert_in(M.User.by_email_address('abc123@abc.me'), [u1, u2])
     assert_equal(log.warn.call_count, 1)
 
+    # invalid email returns None, but not user which claimed
+    # nobody@example.com as before
+    nobody = M.EmailAddress(email='nobody@example.com', confirmed=True,
+                            claimed_by_user_id=u1._id)
+    ThreadLocalORMSession.flush_all()
+    assert_equal(M.User.by_email_address('nobody@example.com'), u1)
+    assert_equal(M.User.by_email_address('invalid'), None)
+
 
 @with_setup(setUp)
 def test_project_role():


Mime
View raw message