~rashi007/mailman/docsfix

« back to all changes in this revision

Viewing changes to src/mailman/model/tests/test_address.py

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Test addresses."""
19
19
 
20
 
from __future__ import absolute_import, print_function, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
20
__all__ = [
24
21
    'TestAddress',
25
22
    ]
28
25
import unittest
29
26
 
30
27
from mailman.email.validate import InvalidEmailAddressError
 
28
from mailman.interfaces.address import ExistingAddressError
 
29
from mailman.interfaces.usermanager import IUserManager
31
30
from mailman.model.address import Address
32
31
from mailman.testing.layers import ConfigLayer
 
32
from zope.component import getUtility
33
33
 
34
34
 
35
35
 
38
38
 
39
39
    layer = ConfigLayer
40
40
 
 
41
    def setUp(self):
 
42
        self._usermgr = getUtility(IUserManager)
 
43
        self._address = self._usermgr.create_address('FPERSON@example.com')
 
44
 
41
45
    def test_invalid_email_string_raises_exception(self):
42
46
        with self.assertRaises(InvalidEmailAddressError):
43
47
            Address('not_a_valid_email_string', '')
 
48
 
 
49
    def test_local_part_differs_only_by_case(self):
 
50
        with self.assertRaises(ExistingAddressError) as cm:
 
51
            self._usermgr.create_address('fperson@example.com')
 
52
        self.assertEqual(cm.exception.address, 'FPERSON@example.com')
 
53
 
 
54
    def test_domain_part_differs_only_by_case(self):
 
55
        with self.assertRaises(ExistingAddressError) as cm:
 
56
            self._usermgr.create_address('fperson@EXAMPLE.COM')
 
57
        self.assertEqual(cm.exception.address, 'FPERSON@example.com')
 
58
 
 
59
    def test_mixed_case_exact_match(self):
 
60
        with self.assertRaises(ExistingAddressError) as cm:
 
61
            self._usermgr.create_address('FPERSON@example.com')
 
62
        self.assertEqual(cm.exception.address, 'FPERSON@example.com')