Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
138
Merge Requests
138
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
e3d0519a
Commit
e3d0519a
authored
Jul 23, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Aug 28, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: DummyMailHostMixin message is bytes().
Co-authored-by:
Arnaud Fontaine
<
arnaud.fontaine@nexedi.com
>
parent
641f4d34
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
32 deletions
+64
-32
bt5/erp5_accounting_l10n_fr/TestTemplateItem/portal_components/test.erp5.testAccounting_l10n_fr.py
...tem/portal_components/test.erp5.testAccounting_l10n_fr.py
+6
-2
bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py
...m/portal_components/test.erp5.testAuthenticationPolicy.py
+1
-1
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testNotificationTool.py
...eItem/portal_components/test.erp5.testNotificationTool.py
+6
-2
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPasswordTool.py
...plateItem/portal_components/test.erp5.testPasswordTool.py
+1
-1
bt5/erp5_credential/TestTemplateItem/portal_components/test.erp5.testERP5Credential.py
...ateItem/portal_components/test.erp5.testERP5Credential.py
+7
-2
bt5/erp5_crm/TestTemplateItem/portal_components/test.erp5.testCRM.py
...m/TestTemplateItem/portal_components/test.erp5.testCRM.py
+12
-7
bt5/erp5_forge/TestTemplateItem/portal_components/test.erp5.testBug.py
...e/TestTemplateItem/portal_components/test.erp5.testBug.py
+7
-3
product/CMFActivity/tests/testCMFActivity.py
product/CMFActivity/tests/testCMFActivity.py
+1
-0
product/ERP5OOo/tests/testDeferredStyle.py
product/ERP5OOo/tests/testDeferredStyle.py
+16
-11
product/ERP5Type/tests/utils.py
product/ERP5Type/tests/utils.py
+7
-3
No files found.
bt5/erp5_accounting_l10n_fr/TestTemplateItem/portal_components/test.erp5.testAccounting_l10n_fr.py
View file @
e3d0519a
...
@@ -30,9 +30,13 @@
...
@@ -30,9 +30,13 @@
"""Test suite for erp5_accounting_l10n_fr
"""Test suite for erp5_accounting_l10n_fr
"""
"""
import
six
import
unittest
import
unittest
import
zipfile
import
zipfile
import
email
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
import
os.path
import
os.path
import
io
import
io
from
DateTime
import
DateTime
from
DateTime
import
DateTime
...
@@ -118,7 +122,7 @@ class TestAccounting_l10n_fr(AccountingTestCase):
...
@@ -118,7 +122,7 @@ class TestAccounting_l10n_fr(AccountingTestCase):
self
.
assertNotEqual
((),
last_message
)
self
.
assertNotEqual
((),
last_message
)
_
,
mto
,
message_text
=
last_message
_
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
file_name
=
part
.
get_filename
()
file_name
=
part
.
get_filename
()
...
...
bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py
View file @
e3d0519a
...
@@ -644,7 +644,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
...
@@ -644,7 +644,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
self
.
tic
()
self
.
tic
()
_
,
(
to
,),
message
=
self
.
portal
.
MailHost
.
_last_message
_
,
(
to
,),
message
=
self
.
portal
.
MailHost
.
_last_message
self
.
assertEqual
(
to
,
'user@example.com'
)
self
.
assertEqual
(
to
,
'user@example.com'
)
self
.
assertIn
(
'Password Recovery'
,
message
)
self
.
assertIn
(
b
'Password Recovery'
,
message
)
def
test_HttpRequest
(
self
):
def
test_HttpRequest
(
self
):
"""
"""
...
...
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testNotificationTool.py
View file @
e3d0519a
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#
#
##############################################################################
##############################################################################
import
six
import
unittest
import
unittest
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
...
@@ -33,7 +34,10 @@ from AccessControl.SecurityManagement import newSecurityManager
...
@@ -33,7 +34,10 @@ from AccessControl.SecurityManagement import newSecurityManager
from
AccessControl.SecurityManagement
import
getSecurityManager
from
AccessControl.SecurityManagement
import
getSecurityManager
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
Products.ERP5Type.tests.utils
import
DummyMailHost
import
email
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
from
email.header
import
decode_header
,
make_header
from
email.header
import
decode_header
,
make_header
from
email.utils
import
parseaddr
from
email.utils
import
parseaddr
...
@@ -47,7 +51,7 @@ def decode_email(file_):
...
@@ -47,7 +51,7 @@ def decode_email(file_):
'headers'
:
{}
'headers'
:
{}
}
}
# Get Message
# Get Message
msg
=
email
.
message_from_string
(
file_
)
msg
=
message_from_bytes
(
file_
)
# Back up original file
# Back up original file
theMail
[
'__original__'
]
=
file_
theMail
[
'__original__'
]
=
file_
for
key
,
value
in
msg
.
items
():
for
key
,
value
in
msg
.
items
():
...
...
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPasswordTool.py
View file @
e3d0519a
...
@@ -125,7 +125,7 @@ class TestPasswordTool(ERP5TypeTestCase):
...
@@ -125,7 +125,7 @@ class TestPasswordTool(ERP5TypeTestCase):
self
.
assertEqual
([
'userA@example.invalid'
],
mto
)
self
.
assertEqual
([
'userA@example.invalid'
],
mto
)
reset_key
,
=
list
(
six
.
iterkeys
(
self
.
portal
.
portal_password
.
_password_request_dict
))
reset_key
,
=
list
(
six
.
iterkeys
(
self
.
portal
.
portal_password
.
_password_request_dict
))
self
.
assertIn
(
self
.
assertIn
(
(
'PasswordTool_viewResetPassword?reset_key='
+
reset_key
)
.
encode
()
,
(
'PasswordTool_viewResetPassword?reset_key='
+
reset_key
),
mbody
)
mbody
)
ret
=
self
.
portal
.
portal_password
.
changeUserPassword
(
ret
=
self
.
portal
.
portal_password
.
changeUserPassword
(
...
...
bt5/erp5_credential/TestTemplateItem/portal_components/test.erp5.testERP5Credential.py
View file @
e3d0519a
...
@@ -26,13 +26,18 @@
...
@@ -26,13 +26,18 @@
#
#
##############################################################################
##############################################################################
import
six
import
unittest
import
unittest
from
Products.ERP5Type.tests.utils
import
reindex
from
Products.ERP5Type.tests.utils
import
reindex
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
DateTime
import
DateTime
from
DateTime
import
DateTime
import
email
,
re
import
re
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
from
email.header
import
decode_header
,
make_header
from
email.header
import
decode_header
,
make_header
from
email.utils
import
parseaddr
from
email.utils
import
parseaddr
import
six.moves.urllib.parse
import
six.moves.urllib.parse
...
@@ -172,7 +177,7 @@ class TestERP5Credential(ERP5TypeTestCase):
...
@@ -172,7 +177,7 @@ class TestERP5Credential(ERP5TypeTestCase):
'headers'
:
{}
'headers'
:
{}
}
}
# Get Message
# Get Message
msg
=
email
.
message_from_string
(
file_
)
msg
=
message_from_bytes
(
file_
)
# Back up original file
# Back up original file
theMail
[
'__original__'
]
=
file_
theMail
[
'__original__'
]
=
file_
# Recode headers to UTF-8 if needed
# Recode headers to UTF-8 if needed
...
...
bt5/erp5_crm/TestTemplateItem/portal_components/test.erp5.testCRM.py
View file @
e3d0519a
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#
#
##############################################################################
##############################################################################
import
six
import
unittest
import
unittest
import
six.moves.urllib.parse
import
six.moves.urllib.parse
import
os
import
os
...
@@ -41,6 +42,10 @@ from email.mime.multipart import MIMEMultipart
...
@@ -41,6 +42,10 @@ from email.mime.multipart import MIMEMultipart
from
email.mime.base
import
MIMEBase
from
email.mime.base
import
MIMEBase
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email
import
encoders
,
message_from_string
from
email
import
encoders
,
message_from_string
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
from
DateTime
import
DateTime
from
DateTime
import
DateTime
import
Products.ERP5.tests
import
Products.ERP5.tests
...
@@ -1152,7 +1157,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -1152,7 +1157,7 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
self
.
assertEqual
(
event
.
getTextContent
(),
text_content
)
self
.
assertEqual
(
event
.
getTextContent
(),
text_content
)
message
=
message_from_
string
(
messageText
)
message
=
message_from_
bytes
(
messageText
)
self
.
assertEqual
(
'A Mail'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
])
self
.
assertEqual
(
'A Mail'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
])
part
=
None
part
=
None
...
@@ -1236,7 +1241,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -1236,7 +1241,7 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
message
=
message_from_
string
(
messageText
)
message
=
message_from_
bytes
(
messageText
)
part
=
None
part
=
None
for
i
in
message
.
get_payload
():
for
i
in
message
.
get_payload
():
if
i
.
get_content_type
()
==
'text/html'
:
if
i
.
get_content_type
()
==
'text/html'
:
...
@@ -1259,7 +1264,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -1259,7 +1264,7 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'=?utf-8?q?Me=2C_=F0=9F=90=88_fan?= <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
(
'=?utf-8?q?Me=2C_=F0=9F=90=88_fan?= <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
([
'=?utf-8?q?Recipient=2C_=F0=9F=90=88_fan?= <recipient@example.com>'
],
mto
)
self
.
assertEqual
([
'=?utf-8?q?Recipient=2C_=F0=9F=90=88_fan?= <recipient@example.com>'
],
mto
)
message
=
message_from_
string
(
messageText
)
message
=
message_from_
bytes
(
messageText
)
self
.
assertEqual
(
u'Héhé'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
].
decode
(
'utf-8'
))
self
.
assertEqual
(
u'Héhé'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
].
decode
(
'utf-8'
))
self
.
assertEqual
(
u'Me, 🐈 fan'
,
decode_header
(
message
[
'From'
])[
0
][
0
].
decode
(
'utf-8'
))
self
.
assertEqual
(
u'Me, 🐈 fan'
,
decode_header
(
message
[
'From'
])[
0
][
0
].
decode
(
'utf-8'
))
...
@@ -2035,8 +2040,8 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -2035,8 +2040,8 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
5
,
len
(
self
.
portal
.
MailHost
.
_message_list
))
self
.
assertEqual
(
5
,
len
(
self
.
portal
.
MailHost
.
_message_list
))
for
message_info
in
self
.
portal
.
MailHost
.
_message_list
:
for
message_info
in
self
.
portal
.
MailHost
.
_message_list
:
self
.
assertIn
(
mail_text_content
,
message_info
[
-
1
])
self
.
assertIn
(
mail_text_content
,
message_info
[
-
1
]
.
decode
()
)
message
=
message_from_
string
(
message_info
[
-
1
])
message
=
message_from_
bytes
(
message_info
[
-
1
])
self
.
assertTrue
(
DateTime
(
message
.
get
(
"Date"
)).
isCurrentDay
())
self
.
assertTrue
(
DateTime
(
message
.
get
(
"Date"
)).
isCurrentDay
())
def
test_MailMessage_send_simple_case
(
self
):
def
test_MailMessage_send_simple_case
(
self
):
...
@@ -2053,7 +2058,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -2053,7 +2058,7 @@ class TestCRMMailSend(BaseTestCRM):
attachment_list
=
[])
attachment_list
=
[])
self
.
tic
()
self
.
tic
()
(
from_url
,
to_url
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
(
from_url
,
to_url
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
self
.
assertIn
(
"Body Simple Case"
,
last_message
)
self
.
assertIn
(
b
"Body Simple Case"
,
last_message
)
self
.
assertEqual
(
'FG ER <eee@eee.com>'
,
from_url
)
self
.
assertEqual
(
'FG ER <eee@eee.com>'
,
from_url
)
self
.
assertEqual
([
'Expert User <expert@in24.test>'
],
to_url
)
self
.
assertEqual
([
'Expert User <expert@in24.test>'
],
to_url
)
...
@@ -2068,7 +2073,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -2068,7 +2073,7 @@ class TestCRMMailSend(BaseTestCRM):
mail_message
.
send
(
extra_header_dict
=
{
"X-test-header"
:
"test"
})
mail_message
.
send
(
extra_header_dict
=
{
"X-test-header"
:
"test"
})
self
.
tic
()
self
.
tic
()
(
_
,
_
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
(
_
,
_
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
message
=
message_from_
string
(
last_message
)
message
=
message_from_
bytes
(
last_message
)
self
.
assertEqual
(
"test"
,
message
.
get
(
"X-test-header"
))
self
.
assertEqual
(
"test"
,
message
.
get
(
"X-test-header"
))
...
...
bt5/erp5_forge/TestTemplateItem/portal_components/test.erp5.testBug.py
View file @
e3d0519a
...
@@ -29,12 +29,16 @@
...
@@ -29,12 +29,16 @@
##############################################################################
##############################################################################
import
six
import
unittest
import
unittest
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
email
import
message_from_string
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
from
email.header
import
decode_header
from
email.header
import
decode_header
...
@@ -218,7 +222,7 @@ class TestBug(ERP5TypeTestCase):
...
@@ -218,7 +222,7 @@ class TestBug(ERP5TypeTestCase):
mfrom
,
mto
,
messageText
=
last_message
mfrom
,
mto
,
messageText
=
last_message
self
.
assertEqual
(
'dummy <loggedperson@localhost>'
,
mfrom
)
self
.
assertEqual
(
'dummy <loggedperson@localhost>'
,
mfrom
)
self
.
assertEqual
([
'person1@localhost'
],
mto
)
self
.
assertEqual
([
'person1@localhost'
],
mto
)
message
=
message_from_
string
(
messageText
)
message
=
message_from_
bytes
(
messageText
)
self
.
assertTrue
(
decode_header
(
message
[
'Subject'
])[
0
][
0
].
endswith
(
bug
.
getTitle
()))
self
.
assertTrue
(
decode_header
(
message
[
'Subject'
])[
0
][
0
].
endswith
(
bug
.
getTitle
()))
def
stepCheckBugMessageNotification
(
self
,
sequence
=
None
,
def
stepCheckBugMessageNotification
(
self
,
sequence
=
None
,
...
@@ -232,7 +236,7 @@ class TestBug(ERP5TypeTestCase):
...
@@ -232,7 +236,7 @@ class TestBug(ERP5TypeTestCase):
mfrom
,
mto
,
messageText
=
last_message
mfrom
,
mto
,
messageText
=
last_message
self
.
assertEqual
(
'person2@localhost'
,
mfrom
)
self
.
assertEqual
(
'person2@localhost'
,
mfrom
)
self
.
assertEqual
([
'person1@localhost'
],
mto
)
self
.
assertEqual
([
'person1@localhost'
],
mto
)
message
=
message_from_
string
(
messageText
)
message
=
message_from_
bytes
(
messageText
)
self
.
assertTrue
(
decode_header
(
message
[
'Subject'
])[
0
][
0
].
endswith
(
bug
.
getTitle
()))
self
.
assertTrue
(
decode_header
(
message
[
'Subject'
])[
0
][
0
].
endswith
(
bug
.
getTitle
()))
def
stepSetSourceProject
(
self
,
sequence
=
None
,
sequence_list
=
None
,
**
kw
):
def
stepSetSourceProject
(
self
,
sequence
=
None
,
sequence_list
=
None
,
**
kw
):
...
...
product/CMFActivity/tests/testCMFActivity.py
View file @
e3d0519a
...
@@ -1141,6 +1141,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -1141,6 +1141,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self
.
flushAllActivities
(
silent
=
1
,
loop_size
=
100
)
self
.
flushAllActivities
(
silent
=
1
,
loop_size
=
100
)
# Check there is a traceback in the email notification
# Check there is a traceback in the email notification
sender
,
recipients
,
mail
=
message_list
.
pop
()
sender
,
recipients
,
mail
=
message_list
.
pop
()
mail
=
mail
.
decode
()
self
.
assertIn
(
"Module %s, line %s, in failingMethod"
%
(
self
.
assertIn
(
"Module %s, line %s, in failingMethod"
%
(
__name__
,
inspect
.
getsourcelines
(
failingMethod
)[
1
]),
mail
)
__name__
,
inspect
.
getsourcelines
(
failingMethod
)[
1
]),
mail
)
self
.
assertIn
(
"ValueError:"
,
mail
)
self
.
assertIn
(
"ValueError:"
,
mail
)
...
...
product/ERP5OOo/tests/testDeferredStyle.py
View file @
e3d0519a
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#
#
##############################################################################
##############################################################################
import
six
import
textwrap
import
textwrap
import
unittest
import
unittest
import
textwrap
import
textwrap
...
@@ -36,7 +37,11 @@ from AccessControl.SecurityManagement import newSecurityManager
...
@@ -36,7 +37,11 @@ from AccessControl.SecurityManagement import newSecurityManager
from
Acquisition
import
aq_base
from
Acquisition
import
aq_base
from
Products.ERP5OOo.tests.utils
import
Validator
from
Products.ERP5OOo.tests.utils
import
Validator
from
lxml
import
html
from
lxml
import
html
import
email
,
six
.
moves
.
urllib
.
parse
,
six
.
moves
.
http_client
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_bytes
else
:
from
email
import
message_from_bytes
import
six.moves.urllib.parse
,
six
.
moves
.
http_client
from
Products.Formulator.MethodField
import
Method
from
Products.Formulator.MethodField
import
Method
...
@@ -133,7 +138,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -133,7 +138,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
file_name
=
part
.
get_filename
()
file_name
=
part
.
get_filename
()
...
@@ -198,7 +203,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -198,7 +203,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
if
content_type
==
"text/html"
:
if
content_type
==
"text/html"
:
...
@@ -236,7 +241,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -236,7 +241,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
if
content_type
==
"text/html"
:
if
content_type
==
"text/html"
:
...
@@ -260,7 +265,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -260,7 +265,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
if
content_type
==
"text/html"
:
if
content_type
==
"text/html"
:
...
@@ -285,7 +290,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -285,7 +290,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
if
content_type
==
self
.
content_type
:
if
content_type
==
self
.
content_type
:
...
@@ -315,7 +320,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -315,7 +320,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
'HTTP_ACCEPT_LANGUAGE'
:
'fr;q=0.9,en;q=0.8'
,
'HTTP_ACCEPT_LANGUAGE'
:
'fr;q=0.9,en;q=0.8'
,
})
})
self
.
tic
()
self
.
tic
()
mail_message
=
email
.
message_from_string
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
mail_message
=
message_from_bytes
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
# mail subject is translated
# mail subject is translated
self
.
assertEqual
(
'Historique'
,
mail_message
[
'subject'
])
self
.
assertEqual
(
'Historique'
,
mail_message
[
'subject'
])
# content is translated
# content is translated
...
@@ -345,11 +350,11 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -345,11 +350,11 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
'HTTP_COOKIE'
:
'LOCALIZER_LANGUAGE="fr"'
,
'HTTP_COOKIE'
:
'LOCALIZER_LANGUAGE="fr"'
,
})
})
self
.
tic
()
self
.
tic
()
mail_message
=
email
.
message_from_string
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
mail_message
=
message_from_bytes
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
# mail subject is translated
# mail subject is translated
self
.
assertEqual
(
'Historique'
,
mail_message
[
'subject'
])
self
.
assertEqual
(
'Historique'
,
mail_message
[
'subject'
])
# content is translated
# content is translated
mail_message
=
email
.
message_from_string
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
mail_message
=
message_from_string
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
part
,
=
[
x
for
x
in
mail_message
.
walk
()
if
x
.
get_content_type
()
==
self
.
content_type
]
part
,
=
[
x
for
x
in
mail_message
.
walk
()
if
x
.
get_content_type
()
==
self
.
content_type
]
self
.
assertIn
(
self
.
assertIn
(
b'Historique'
,
b'Historique'
,
...
@@ -450,7 +455,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
...
@@ -450,7 +455,7 @@ class TestDeferredStyleBase(DeferredStyleTestCase):
# inspect the report as text and check the selection was initialized from
# inspect the report as text and check the selection was initialized from
# request parameter.
# request parameter.
mail_message
=
email
.
message_from_string
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
mail_message
=
message_from_bytes
(
self
.
portal
.
MailHost
.
_last_message
[
2
])
part
,
=
[
x
for
x
in
mail_message
.
walk
()
if
x
.
get_content_type
()
==
self
.
content_type
]
part
,
=
[
x
for
x
in
mail_message
.
walk
()
if
x
.
get_content_type
()
==
self
.
content_type
]
doc
=
self
.
portal
.
document_module
.
newContent
(
doc
=
self
.
portal
.
document_module
.
newContent
(
...
@@ -487,7 +492,7 @@ class TestODSDeferredStyle(TestDeferredStyleBase):
...
@@ -487,7 +492,7 @@ class TestODSDeferredStyle(TestDeferredStyleBase):
self
.
assertNotEqual
(
last_message
,
())
self
.
assertNotEqual
(
last_message
,
())
mfrom
,
mto
,
message_text
=
last_message
mfrom
,
mto
,
message_text
=
last_message
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
self
.
assertEqual
(
'"%s" <%s>'
%
(
self
.
first_name
,
self
.
recipient_email_address
),
mto
[
0
])
mail_message
=
email
.
message_from_string
(
message_text
)
mail_message
=
message_from_bytes
(
message_text
)
for
part
in
mail_message
.
walk
():
for
part
in
mail_message
.
walk
():
content_type
=
part
.
get_content_type
()
content_type
=
part
.
get_content_type
()
file_name
=
part
.
get_filename
()
file_name
=
part
.
get_filename
()
...
...
product/ERP5Type/tests/utils.py
View file @
e3d0519a
...
@@ -49,7 +49,6 @@ from Zope2.Startup.datatypes import ZopeDatabase
...
@@ -49,7 +49,6 @@ from Zope2.Startup.datatypes import ZopeDatabase
from
Testing
import
ZopeTestCase
from
Testing
import
ZopeTestCase
import
Products.ERP5Type
import
Products.ERP5Type
from
Products.MailHost.MailHost
import
MailHost
from
Products.MailHost.MailHost
import
MailHost
from
email
import
message_from_string
from
Products.ERP5Type.Globals
import
PersistentMapping
from
Products.ERP5Type.Globals
import
PersistentMapping
from
Products.ERP5Type.Utils
import
simple_decorator
from
Products.ERP5Type.Utils
import
simple_decorator
from
Products.ZSQLCatalog.SQLCatalog
import
Catalog
from
Products.ZSQLCatalog.SQLCatalog
import
Catalog
...
@@ -59,9 +58,11 @@ import lxml.html
...
@@ -59,9 +58,11 @@ import lxml.html
if
six
.
PY2
:
if
six
.
PY2
:
FileIO
=
file
FileIO
=
file
from
email
import
message_from_string
as
message_from_bytes
else
:
else
:
from
io
import
FileIO
from
io
import
FileIO
from
importlib
import
reload
from
importlib
import
reload
from
email
import
message_from_bytes
def
canonical_html
(
html
):
def
canonical_html
(
html
):
...
@@ -106,12 +107,15 @@ class DummyMailHostMixin(object):
...
@@ -106,12 +107,15 @@ class DummyMailHostMixin(object):
@
staticmethod
@
staticmethod
def
_decodeMessage
(
messageText
):
def
_decodeMessage
(
messageText
):
# type: (bytes) -> str
""" Decode message"""
""" Decode message"""
message_text
=
messageText
message_text
=
messageText
for
part
in
message_from_
string
(
messageText
).
walk
():
for
part
in
message_from_
bytes
(
messageText
).
walk
():
if
part
.
get_content_type
()
in
[
'text/plain'
,
'text/html'
]
\
if
part
.
get_content_type
()
in
[
'text/plain'
,
'text/html'
]
\
and
not
part
.
is_multipart
():
and
not
part
.
is_multipart
():
message_text
=
part
.
get_payload
(
decode
=
1
)
message_text
=
part
.
get_payload
(
decode
=
True
)
if
six
.
PY3
:
message_text
=
message_text
.
decode
(
part
.
get_content_charset
(
'ascii'
))
return
message_text
return
message_text
security
.
declarePrivate
(
'getMessageList'
)
security
.
declarePrivate
(
'getMessageList'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment