author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 10 Aug 2010 16:05:00 +0200 | |
changeset 6089 | b0975c6f2e44 |
parent 5424 | 8ecbcbff9777 |
child 6340 | 470d8e828fda |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
19 |
"""unit tests for module cubicweb.mail |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
21 |
""" |
0 | 22 |
|
23 |
import os |
|
3153 | 24 |
import sys |
0 | 25 |
|
26 |
from logilab.common.testlib import unittest_main |
|
27 |
from logilab.common.umessage import message_from_string |
|
28 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
29 |
from cubicweb.devtools.testlib import CubicWebTC |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
30 |
from cubicweb.mail import format_mail |
0 | 31 |
|
32 |
||
33 |
def getlogin(): |
|
34 |
"""avoid usinng os.getlogin() because of strange tty / stdin problems |
|
35 |
(man 3 getlogin) |
|
36 |
Another solution would be to use $LOGNAME, $USER or $USERNAME |
|
37 |
""" |
|
3153 | 38 |
if sys.platform != 'win32': |
39 |
import pwd |
|
40 |
return pwd.getpwuid(os.getuid())[0] |
|
41 |
else: |
|
42 |
return os.environ.get('USERNAME') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
43 |
|
0 | 44 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
class EmailTC(CubicWebTC): |
0 | 46 |
|
47 |
def test_format_mail(self): |
|
48 |
self.set_option('sender-addr', 'bim@boum.fr') |
|
49 |
self.set_option('sender-name', 'BimBam') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
50 |
|
0 | 51 |
mail = format_mail({'name': 'oim', 'email': 'oim@logilab.fr'}, |
52 |
['test@logilab.fr'], u'un petit cöucou', u'bïjour', |
|
53 |
config=self.config) |
|
54 |
self.assertLinesEquals(mail.as_string(), """\ |
|
55 |
MIME-Version: 1.0 |
|
56 |
Content-Type: text/plain; charset="utf-8" |
|
57 |
Content-Transfer-Encoding: base64 |
|
58 |
Subject: =?utf-8?q?b=C3=AFjour?= |
|
59 |
From: =?utf-8?q?oim?= <oim@logilab.fr> |
|
60 |
Reply-to: =?utf-8?q?oim?= <oim@logilab.fr>, =?utf-8?q?BimBam?= <bim@boum.fr> |
|
61 |
X-CW: data |
|
62 |
To: test@logilab.fr |
|
63 |
||
64 |
dW4gcGV0aXQgY8O2dWNvdQ== |
|
65 |
""") |
|
66 |
msg = message_from_string(mail.as_string()) |
|
67 |
self.assertEquals(msg.get('subject'), u'bïjour') |
|
68 |
self.assertEquals(msg.get('from'), u'oim <oim@logilab.fr>') |
|
69 |
self.assertEquals(msg.get('to'), u'test@logilab.fr') |
|
70 |
self.assertEquals(msg.get('reply-to'), u'oim <oim@logilab.fr>, BimBam <bim@boum.fr>') |
|
71 |
self.assertEquals(msg.get_payload(decode=True), u'un petit cöucou') |
|
72 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
73 |
|
0 | 74 |
def test_format_mail_euro(self): |
75 |
mail = format_mail({'name': u'oîm', 'email': u'oim@logilab.fr'}, |
|
76 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €') |
|
77 |
self.assertLinesEquals(mail.as_string(), """\ |
|
78 |
MIME-Version: 1.0 |
|
79 |
Content-Type: text/plain; charset="utf-8" |
|
80 |
Content-Transfer-Encoding: base64 |
|
81 |
Subject: =?utf-8?b?YsOvam91ciDigqw=?= |
|
82 |
From: =?utf-8?q?o=C3=AEm?= <oim@logilab.fr> |
|
83 |
Reply-to: =?utf-8?q?o=C3=AEm?= <oim@logilab.fr> |
|
84 |
To: test@logilab.fr |
|
85 |
||
86 |
dW4gcGV0aXQgY8O2dWNvdSDigqw= |
|
87 |
""") |
|
88 |
msg = message_from_string(mail.as_string()) |
|
89 |
self.assertEquals(msg.get('subject'), u'bïjour €') |
|
90 |
self.assertEquals(msg.get('from'), u'oîm <oim@logilab.fr>') |
|
91 |
self.assertEquals(msg.get('to'), u'test@logilab.fr') |
|
92 |
self.assertEquals(msg.get('reply-to'), u'oîm <oim@logilab.fr>') |
|
93 |
self.assertEquals(msg.get_payload(decode=True), u'un petit cöucou €') |
|
94 |
||
95 |
||
96 |
def test_format_mail_from_reply_to(self): |
|
97 |
# no sender-name, sender-addr in the configuration |
|
98 |
self.set_option('sender-name', '') |
|
99 |
self.set_option('sender-addr', '') |
|
100 |
msg = format_mail({'name': u'', 'email': u''}, |
|
101 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €', |
|
102 |
config=self.config) |
|
103 |
self.assertEquals(msg.get('from'), u'') |
|
104 |
self.assertEquals(msg.get('reply-to'), None) |
|
105 |
msg = format_mail({'name': u'tutu', 'email': u'tutu@logilab.fr'}, |
|
106 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €', |
|
107 |
config=self.config) |
|
108 |
msg = message_from_string(msg.as_string()) |
|
109 |
self.assertEquals(msg.get('from'), u'tutu <tutu@logilab.fr>') |
|
110 |
self.assertEquals(msg.get('reply-to'), u'tutu <tutu@logilab.fr>') |
|
111 |
msg = format_mail({'name': u'tutu', 'email': u'tutu@logilab.fr'}, |
|
112 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €') |
|
113 |
msg = message_from_string(msg.as_string()) |
|
114 |
self.assertEquals(msg.get('from'), u'tutu <tutu@logilab.fr>') |
|
115 |
self.assertEquals(msg.get('reply-to'), u'tutu <tutu@logilab.fr>') |
|
116 |
# set sender name and address as expected |
|
117 |
self.set_option('sender-name', 'cubicweb-test') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
118 |
self.set_option('sender-addr', 'cubicweb-test@logilab.fr') |
0 | 119 |
# anonymous notification: no name and no email specified |
120 |
msg = format_mail({'name': u'', 'email': u''}, |
|
121 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €', |
|
122 |
config=self.config) |
|
123 |
msg = message_from_string(msg.as_string()) |
|
124 |
self.assertEquals(msg.get('from'), u'cubicweb-test <cubicweb-test@logilab.fr>') |
|
125 |
self.assertEquals(msg.get('reply-to'), u'cubicweb-test <cubicweb-test@logilab.fr>') |
|
126 |
# anonymous notification: only email specified |
|
127 |
msg = format_mail({'email': u'tutu@logilab.fr'}, |
|
128 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €', |
|
129 |
config=self.config) |
|
130 |
msg = message_from_string(msg.as_string()) |
|
131 |
self.assertEquals(msg.get('from'), u'cubicweb-test <tutu@logilab.fr>') |
|
132 |
self.assertEquals(msg.get('reply-to'), u'cubicweb-test <tutu@logilab.fr>, cubicweb-test <cubicweb-test@logilab.fr>') |
|
133 |
# anonymous notification: only name specified |
|
134 |
msg = format_mail({'name': u'tutu'}, |
|
135 |
['test@logilab.fr'], u'un petit cöucou €', u'bïjour €', |
|
136 |
config=self.config) |
|
137 |
msg = message_from_string(msg.as_string()) |
|
138 |
self.assertEquals(msg.get('from'), u'tutu <cubicweb-test@logilab.fr>') |
|
139 |
self.assertEquals(msg.get('reply-to'), u'tutu <cubicweb-test@logilab.fr>') |
|
140 |
||
141 |
||
142 |
||
143 |
if __name__ == '__main__': |
|
144 |
unittest_main() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
145 |