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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
879e136d
Commit
879e136d
authored
Jul 23, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Oct 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: DummyMailHostMixin message is bytes() (
!1751
).
Co-authored-by:
Arnaud Fontaine
<
arnaud.fontaine@nexedi.com
>
parent
d56f662d
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
55 additions
and
27 deletions
+55
-27
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
+2
-2
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
+2
-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 @
879e136d
...
@@ -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 @
879e136d
...
@@ -645,7 +645,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
...
@@ -645,7 +645,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 @
879e136d
...
@@ -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
...
@@ -34,7 +35,10 @@ from AccessControl.SecurityManagement import getSecurityManager
...
@@ -34,7 +35,10 @@ 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
from
Products.ERP5Type.Utils
import
unicode2str
from
Products.ERP5Type.Utils
import
unicode2str
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
...
@@ -48,7 +52,7 @@ def decode_email(file_):
...
@@ -48,7 +52,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 @
879e136d
...
@@ -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 @
879e136d
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#
#
##############################################################################
##############################################################################
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
...
@@ -33,7 +34,11 @@ from Products.ERP5Type.tests.utils import DummyMailHost
...
@@ -33,7 +34,11 @@ from Products.ERP5Type.tests.utils import DummyMailHost
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.Utils
import
unicode2str
from
Products.ERP5Type.Utils
import
unicode2str
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
...
@@ -173,7 +178,7 @@ class TestERP5Credential(ERP5TypeTestCase):
...
@@ -173,7 +178,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_
for
key
,
value
in
msg
.
items
():
for
key
,
value
in
msg
.
items
():
...
...
bt5/erp5_crm/TestTemplateItem/portal_components/test.erp5.testCRM.py
View file @
879e136d
...
@@ -2044,7 +2044,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -2044,7 +2044,7 @@ 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
,
bytes2str
(
message_info
[
-
1
])
)
message
=
message_from_bytes
(
message_info
[
-
1
])
message
=
message_from_bytes
(
message_info
[
-
1
])
self
.
assertTrue
(
DateTime
(
message
.
get
(
"Date"
)).
isCurrentDay
())
self
.
assertTrue
(
DateTime
(
message
.
get
(
"Date"
)).
isCurrentDay
())
...
@@ -2062,7 +2062,7 @@ class TestCRMMailSend(BaseTestCRM):
...
@@ -2062,7 +2062,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
)
...
...
bt5/erp5_forge/TestTemplateItem/portal_components/test.erp5.testBug.py
View file @
879e136d
...
@@ -29,13 +29,17 @@
...
@@ -29,13 +29,17 @@
##############################################################################
##############################################################################
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
Products.ERP5Type.Utils
import
bytes2str
from
Products.ERP5Type.Utils
import
bytes2str
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
...
@@ -219,7 +223,7 @@ class TestBug(ERP5TypeTestCase):
...
@@ -219,7 +223,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
,
...
@@ -233,7 +237,7 @@ class TestBug(ERP5TypeTestCase):
...
@@ -233,7 +237,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 @
879e136d
...
@@ -63,6 +63,7 @@ import transaction
...
@@ -63,6 +63,7 @@ import transaction
from
App.config
import
getConfiguration
from
App.config
import
getConfiguration
import
socket
import
socket
from
six.moves
import
range
from
six.moves
import
range
from
Products.ERP5Type.Utils
import
bytes2str
class
CommitFailed
(
Exception
):
class
CommitFailed
(
Exception
):
pass
pass
...
@@ -1141,6 +1142,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -1141,6 +1142,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
=
bytes2str
(
mail
)
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 @
879e136d
...
@@ -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_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
]
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 @
879e136d
...
@@ -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