diff options
| author | Florian Fuchs | 2014-04-14 13:47:58 -0400 |
|---|---|---|
| committer | Florian Fuchs | 2014-04-14 13:47:58 -0400 |
| commit | e4a141e068d9c4132f8b143dc49faabe095a95c8 (patch) | |
| tree | a9745afdc0529d5c8ad05fa4c95d1b56d1121360 /src | |
| parent | 3a306dec00019225cb6ebb8415077657bb2022b1 (diff) | |
| download | mailman-e4a141e068d9c4132f8b143dc49faabe095a95c8.tar.gz mailman-e4a141e068d9c4132f8b143dc49faabe095a95c8.tar.zst mailman-e4a141e068d9c4132f8b143dc49faabe095a95c8.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/model/address.py | 5 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_address.py | 45 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py index f5e7ddbfd..890047445 100644 --- a/src/mailman/model/address.py +++ b/src/mailman/model/address.py @@ -27,11 +27,13 @@ __all__ = [ from email.utils import formataddr from storm.locals import DateTime, Int, Reference, Unicode +from zope.component import getUtility from zope.event import notify from zope.interface import implementer from mailman.database.model import Model -from mailman.interfaces.address import AddressVerificationEvent, IAddress +from mailman.interfaces.address import (AddressVerificationEvent, IAddress, + IEmailValidator) from mailman.utilities.datetime import now @@ -54,6 +56,7 @@ class Address(Model): def __init__(self, email, display_name): super(Address, self).__init__() + getUtility(IEmailValidator).validate(email) lower_case = email.lower() self.email = lower_case self.display_name = display_name diff --git a/src/mailman/model/tests/test_address.py b/src/mailman/model/tests/test_address.py new file mode 100644 index 000000000..f436bacf7 --- /dev/null +++ b/src/mailman/model/tests/test_address.py @@ -0,0 +1,45 @@ +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test addresses.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestAddress', + ] + + +import unittest + +from zope.component import getUtility + +from mailman.email.validate import InvalidEmailAddressError +from mailman.model.address import Address +from mailman.testing.layers import ConfigLayer + + + +class TestAddress(unittest.TestCase): + """Test addresses.""" + + layer = ConfigLayer + + def test_invalid_email_string_raises_exception(self): + with self.assertRaises(InvalidEmailAddressError): + Address('not_a_valid_email_string', '') |
