diff options
| author | Barry Warsaw | 2014-04-14 23:00:41 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2014-04-14 23:00:41 -0400 |
| commit | 00ea00ffa489501993035bb96734506bbe939ab9 (patch) | |
| tree | 35b25abcef92ff627b586b791f1a0adbc1260689 /src/mailman/model | |
| parent | 243b4dd66d1c6bd412ae0ce3770e36aebd3b6a36 (diff) | |
| parent | 5b3b837431f24fd7afdbd368d6d6b7989d1fd54a (diff) | |
| download | mailman-00ea00ffa489501993035bb96734506bbe939ab9.tar.gz mailman-00ea00ffa489501993035bb96734506bbe939ab9.tar.zst mailman-00ea00ffa489501993035bb96734506bbe939ab9.zip | |
Add an email address to an existing user via the REST API.
Diffstat (limited to 'src/mailman/model')
| -rw-r--r-- | src/mailman/model/address.py | 5 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_address.py | 43 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py index f5e7ddbfd..f69679210 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..130ec3bae --- /dev/null +++ b/src/mailman/model/tests/test_address.py @@ -0,0 +1,43 @@ +# 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, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestAddress', + ] + + +import unittest + +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', '') |
