[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/develop] Add unittests for bridgedb.parse.addr.normalizeEmail().
commit e33c55bd62fcced148e5fcdcb7319583ea982538
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Wed Apr 23 06:58:06 2014 +0000
Add unittests for bridgedb.parse.addr.normalizeEmail().
---
lib/bridgedb/test/test_parse_addr.py | 57 ++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/lib/bridgedb/test/test_parse_addr.py b/lib/bridgedb/test/test_parse_addr.py
index 1e6af83..55f0f60 100644
--- a/lib/bridgedb/test/test_parse_addr.py
+++ b/lib/bridgedb/test/test_parse_addr.py
@@ -122,6 +122,63 @@ class ExtractEmailAddressTests(unittest.TestCase):
self.assertEqual(domain, 'gmail.com')
+class NormalizeEmailTests(unittest.TestCase):
+ """Unittests for :func:`bridgedb.parse.addr.normalizeEmail`."""
+
+ def test_permitted(self):
+ """A valid email address from a permitted domain should return
+ unchanged.
+ """
+ domainrules = {}
+ domainmap = {'foo.example.com': 'example.com'}
+ emailaddr = 'alice@xxxxxxxxxxxxxxx'
+ normalized = addr.normalizeEmail(emailaddr, domainmap, domainrules)
+ self.assertEqual(emailaddr, normalized)
+
+ def test_notPermitted(self):
+ """A valid email address from a non-permitted domain should raise an
+ UnsupportedDomain error.
+ """
+ domainrules = {}
+ domainmap = {'bar.example.com': 'example.com'}
+ emailaddr = 'Alice <alice@xxxxxxxxxxxxxxx>'
+ self.assertRaises(addr.UnsupportedDomain,
+ addr.normalizeEmail,
+ emailaddr, domainmap, domainrules)
+
+ def test_ignoreDots(self):
+ """A valid email address with a '.' should remove the '.' if
+ 'ignore_dots' is in domainrules.
+ """
+ domainrules = {'example.com': 'ignore_dots'}
+ domainmap = {'foo.example.com': 'example.com'}
+ emailaddr = 'alice.bridges@xxxxxxxxxxxxxxx'
+ normalized = addr.normalizeEmail(emailaddr, domainmap, domainrules)
+ self.assertEqual('alicebridges@xxxxxxxxxxxxxxx', normalized)
+
+ def test_ignorePlus(self):
+ """A valid email address with a '+' and some extra stuff, from a
+ permitted domain, should remove the '+' stuff if 'ignore_plus' is
+ enabled.
+ """
+ domainrules = {}
+ domainmap = {'foo.example.com': 'example.com'}
+ emailaddr = 'alice+bridges@xxxxxxxxxxxxxxx'
+ normalized = addr.normalizeEmail(emailaddr, domainmap, domainrules)
+ self.assertEqual('alice@xxxxxxxxxxxxxxx', normalized)
+
+ def test_dontIgnorePlus(self):
+ """A valid email address with a '+' and some extra stuff, from a
+ permitted domain, should return unchanged if 'ignore_plus' is disabled.
+ """
+ domainrules = {}
+ domainmap = {'foo.example.com': 'example.com'}
+ emailaddr = 'alice+bridges@xxxxxxxxxxxxxxx'
+ normalized = addr.normalizeEmail(emailaddr, domainmap, domainrules,
+ ignorePlus=False)
+ self.assertEqual(emailaddr, normalized)
+
+
class ParseAddrIsIPAddressTests(unittest.TestCase):
"""Unittests for :func:`bridgedb.parse.addr.isIPAddress`.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits