~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/mail/_tests/test_sendmail.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
    MoinMoin - MoinMoin.mail.sendmail Tests
 
4
 
 
5
    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
 
6
    @license: GNU GPL, see COPYING for details.
 
7
"""
 
8
 
 
9
from email.Charset import Charset, QP
 
10
from email.Header import Header
 
11
from MoinMoin.mail import sendmail
 
12
from MoinMoin import config
 
13
 
 
14
 
 
15
class TestdecodeSpamSafeEmail:
 
16
    """mail.sendmail: testing mail"""
 
17
 
 
18
    _tests = (
 
19
        ('', ''),
 
20
        ('AT', '@'),
 
21
        ('DOT', '.'),
 
22
        ('DASH', '-'),
 
23
        ('CAPS', ''),
 
24
        ('Mixed', 'Mixed'),
 
25
        ('lower', 'lower'),
 
26
        ('Firstname DOT Lastname AT example DOT net',
 
27
         'Firstname.Lastname@example.net'),
 
28
        ('Firstname . Lastname AT exa mp le DOT n e t',
 
29
         'Firstname.Lastname@example.net'),
 
30
        ('Firstname I DONT WANT SPAM . Lastname@example DOT net',
 
31
         'Firstname.Lastname@example.net'),
 
32
        ('First name I Lastname DONT AT WANT SPAM example DOT n e t',
 
33
         'FirstnameLastname@example.net'),
 
34
        ('first.last@example.com', 'first.last@example.com'),
 
35
        ('first . last @ example . com', 'first.last@example.com'),
 
36
        )
 
37
 
 
38
    def testDecodeSpamSafeMail(self):
 
39
        """mail.sendmail: decoding spam safe mail"""
 
40
        for coded, expected in self._tests:
 
41
            assert sendmail.decodeSpamSafeEmail(coded) == expected
 
42
 
 
43
 
 
44
class TestEncodeAddress:
 
45
    """ Address encoding tests
 
46
 
 
47
    See http://www.faqs.org/rfcs/rfc2822.html section 3.4.
 
48
    Address Specification.
 
49
 
 
50
    mailbox     =   name-addr / addr-spec
 
51
    name-addr   =   [display-name] angle-addr
 
52
    angle-addr  =   [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
 
53
    """
 
54
    charset = Charset(config.charset)
 
55
    charset.header_encoding = QP
 
56
    charset.body_encoding = QP
 
57
 
 
58
    def testSimpleAddress(self):
 
59
        """ mail.sendmail: encode simple address: local@domain """
 
60
        address = u'local@domain'
 
61
        expected = address.encode(config.charset)
 
62
        assert sendmail.encodeAddress(address, self.charset) == expected
 
63
 
 
64
    def testComposite(self):
 
65
        """ mail.sendmail: encode address: 'Phrase <local@domain>' """
 
66
        address = u'Phrase <local@domain>'
 
67
        phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
 
68
        expected = phrase + '<local@domain>'
 
69
        assert sendmail.encodeAddress(address, self.charset) == expected
 
70
 
 
71
    def testCompositeUnicode(self):
 
72
        """ mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """
 
73
        address = u'ויקי <local@domain>'
 
74
        phrase = str(Header(u'ויקי '.encode('utf-8'), self.charset))
 
75
        expected = phrase + '<local@domain>'
 
76
        assert sendmail.encodeAddress(address, self.charset) == expected
 
77
 
 
78
    def testEmptyPhrase(self):
 
79
        """ mail.sendmail: encode address with empty phrase: '<local@domain>' """
 
80
        address = u'<local@domain>'
 
81
        expected = address.encode(config.charset)
 
82
        assert sendmail.encodeAddress(address, self.charset) == expected
 
83
 
 
84
    def testEmptyAddress(self):
 
85
        """ mail.sendmail: encode address with empty address: 'Phrase <>'
 
86
 
 
87
        Let the smtp server handle this. We may raise error in such
 
88
        case, but we don't do error checking for mail addresses.
 
89
        """
 
90
        address = u'Phrase <>'
 
91
        phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
 
92
        expected = phrase + '<>'
 
93
        assert sendmail.encodeAddress(address, self.charset) == expected
 
94
 
 
95
    def testInvalidAddress(self):
 
96
        """ mail.sendmail: encode invalid address 'Phrase <blah'
 
97
 
 
98
        Assume that this is a simple address. This address will
 
99
        probably cause an error when trying to send mail. Junk in, junk
 
100
        out.
 
101
        """
 
102
        address = u'Phrase <blah'
 
103
        expected = address.encode(config.charset)
 
104
        assert sendmail.encodeAddress(address, self.charset) == expected
 
105
 
 
106
 
 
107
coverage_modules = ['MoinMoin.mail.sendmail']
 
108