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
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
erp5
Commits
dc93a97d
Commit
dc93a97d
authored
Jan 31, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CRM py3
parent
ab0546f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
29 deletions
+33
-29
bt5/erp5_crm/TestTemplateItem/portal_components/test.erp5.testCRM.py
...m/TestTemplateItem/portal_components/test.erp5.testCRM.py
+33
-29
No files found.
bt5/erp5_crm/TestTemplateItem/portal_components/test.erp5.testCRM.py
View file @
dc93a97d
...
...
@@ -50,9 +50,6 @@ def makeFilePath(name):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
Products
.
ERP5
.
tests
.
__file__
),
'test_data'
,
'crm_emails'
,
name
)
def
makeFileUpload
(
name
):
path
=
makeFilePath
(
name
)
return
FileUpload
(
path
,
name
)
clear_module_name_list
=
"""
campaign_module
...
...
@@ -80,6 +77,13 @@ class BaseTestCRM(ERP5TypeTestCase):
self
.
tic
()
super
(
BaseTestCRM
,
self
).
beforeTearDown
()
def
makeFileUpload
(
self
,
name
):
path
=
makeFilePath
(
name
)
fu
=
FileUpload
(
path
,
name
)
self
.
addCleanup
(
fu
.
close
)
return
fu
class
TestCRM
(
BaseTestCRM
):
def
getTitle
(
self
):
return
"CRM"
...
...
@@ -885,7 +889,7 @@ class TestCRMMailIngestion(BaseTestCRM):
return
object_list
[
-
1
]
portal
=
self
.
portal
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
message
.
replace_header
(
'subject'
,
'Visit:Company A'
)
data
=
message
.
as_string
()
self
.
_ingestMail
(
data
=
data
)
...
...
@@ -893,7 +897,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
getLastCreatedEvent
(
portal
.
event_module
)
self
.
assertEqual
(
document
.
getPortalType
(),
'Visit'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
message
.
replace_header
(
'subject'
,
'Fax:Company B'
)
data
=
message
.
as_string
()
self
.
_ingestMail
(
data
=
data
)
...
...
@@ -901,7 +905,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
getLastCreatedEvent
(
portal
.
event_module
)
self
.
assertEqual
(
document
.
getPortalType
(),
'Fax Message'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
message
.
replace_header
(
'subject'
,
'TEST:Company B'
)
data
=
message
.
as_string
()
self
.
_ingestMail
(
data
=
data
)
...
...
@@ -909,7 +913,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
getLastCreatedEvent
(
portal
.
event_module
)
self
.
assertEqual
(
document
.
getPortalType
(),
'Mail Message'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
message
.
replace_header
(
'subject'
,
'visit:Company A'
)
data
=
message
.
as_string
()
self
.
_ingestMail
(
data
=
data
)
...
...
@@ -925,7 +929,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
portal
.
event_module
[
portal
.
event_module
.
objectIds
()[
-
1
]]
self
.
assertEqual
(
document
.
getPortalType
(),
'Phone Call'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
message
.
replace_header
(
'subject'
,
'LETTER:Company C'
)
data
=
message
.
as_string
()
self
.
_ingestMail
(
data
=
data
)
...
...
@@ -933,7 +937,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
getLastCreatedEvent
(
portal
.
event_module
)
self
.
assertEqual
(
document
.
getPortalType
(),
'Letter'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
body
=
message
.
get_payload
()
message
.
set_payload
(
'Visit:%s'
%
body
)
data
=
message
.
as_string
()
...
...
@@ -942,7 +946,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document
=
getLastCreatedEvent
(
portal
.
event_module
)
self
.
assertEqual
(
document
.
getPortalType
(),
'Visit'
)
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
))
message
=
message_from_string
(
self
.
_readTestData
(
'simple'
)
.
decode
()
)
body
=
message
.
get_payload
()
message
.
set_payload
(
'PHONE CALL:%s'
%
body
)
data
=
message
.
as_string
()
...
...
@@ -1153,14 +1157,14 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
self
.
assertEqual
(
event
.
getTextContent
(),
text_content
)
message
=
message_from_string
(
messageText
)
message
=
message_from_string
(
messageText
.
decode
()
)
self
.
assertEqual
(
'A Mail'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
])
part
=
None
for
i
in
message
.
get_payload
():
if
i
.
get_content_type
()
==
'text/plain'
:
part
=
i
self
.
assertEqual
(
text_content
,
part
.
get_payload
(
decode
=
True
))
self
.
assertEqual
(
text_content
,
part
.
get_payload
(
decode
=
True
)
.
decode
()
)
#
# Test multiple recipients.
...
...
@@ -1237,13 +1241,13 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
'"Me," <me@erp5.org>'
,
mfrom
)
self
.
assertEqual
([
'"Recipient," <recipient@example.com>'
],
mto
)
message
=
message_from_string
(
messageText
)
message
=
message_from_string
(
messageText
.
decode
()
)
part
=
None
for
i
in
message
.
get_payload
():
if
i
.
get_content_type
()
==
'text/html'
:
part
=
i
self
.
assertNotEqual
(
part
,
None
)
self
.
assertEqual
(
'<html><body>%s</body></html>'
%
text_content
,
part
.
get_payload
(
decode
=
True
))
self
.
assertEqual
(
'<html><body>%s</body></html>'
%
text_content
,
part
.
get_payload
(
decode
=
True
)
.
decode
()
)
def
test_MailMessageEncoding
(
self
):
# test sending a mail message with non ascii characters
...
...
@@ -1260,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?Recipient=2C_=F0=9F=90=88_fan?= <recipient@example.com>'
],
mto
)
message
=
message_from_string
(
messageText
)
message
=
message_from_string
(
messageText
.
decode
()
)
self
.
assertEqual
(
'Héhé'
,
decode_header
(
message
[
'Subject'
])[
0
][
0
])
self
.
assertEqual
(
'Me, 🐈 fan'
,
decode_header
(
message
[
'From'
])[
0
][
0
])
...
...
@@ -1269,7 +1273,7 @@ class TestCRMMailSend(BaseTestCRM):
for
i
in
message
.
get_payload
():
if
i
.
get_content_type
()
==
'text/plain'
:
part
=
i
self
.
assertEqual
(
'Hàhà'
,
part
.
get_payload
(
decode
=
True
))
self
.
assertEqual
(
u'Hàhà'
,
part
.
get_payload
(
decode
=
True
).
decode
(
'utf-8'
))
def
test_MailAttachmentPdf
(
self
):
"""
...
...
@@ -1278,7 +1282,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached.
# pdf
filename
=
'sample_attachment.pdf'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_object
)
self
.
tic
()
...
...
@@ -1325,7 +1329,7 @@ class TestCRMMailSend(BaseTestCRM):
"""
# Add a document which will be attached.
filename
=
'sample_attachment.odt'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_object
)
self
.
tic
()
...
...
@@ -1372,7 +1376,7 @@ class TestCRMMailSend(BaseTestCRM):
"""
# Add a document which will be attached.
filename
=
'sample_attachment.zip'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_object
)
self
.
tic
()
...
...
@@ -1417,7 +1421,7 @@ class TestCRMMailSend(BaseTestCRM):
"""
# Add a document which will be attached.
filename
=
'sample_attachment.gif'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_object
)
self
.
tic
()
...
...
@@ -1514,7 +1518,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached.
# pdf
filename
=
'sample_attachment.pdf'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
# Add a ticket
ticket
=
self
.
portal
.
campaign_module
.
newContent
(
portal_type
=
'Campaign'
,
...
...
@@ -1562,7 +1566,7 @@ class TestCRMMailSend(BaseTestCRM):
"""
# Add a document which will be attached.
filename
=
'sample_attachment.zip'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
# Add a ticket
ticket
=
self
.
portal
.
campaign_module
.
newContent
(
portal_type
=
'Campaign'
,
...
...
@@ -1611,7 +1615,7 @@ class TestCRMMailSend(BaseTestCRM):
"""
# Add a document which will be attached.
filename
=
'sample_attachment.zip'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
# Add a ticket
ticket
=
self
.
portal
.
campaign_module
.
newContent
(
portal_type
=
'Campaign'
,
...
...
@@ -1688,7 +1692,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached.
def
add_document
(
filename
,
container
,
portal_type
):
f
=
makeFileUpload
(
filename
)
f
=
self
.
makeFileUpload
(
filename
)
document
=
container
.
newContent
(
portal_type
=
portal_type
)
document
.
edit
(
file
=
f
,
reference
=
filename
)
return
document
...
...
@@ -1745,7 +1749,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached.
def
add_document
(
filename
,
container
,
portal_type
):
f
=
makeFileUpload
(
filename
)
f
=
self
.
makeFileUpload
(
filename
)
document
=
container
.
newContent
(
portal_type
=
portal_type
)
document
.
edit
(
file
=
f
,
reference
=
filename
)
return
document
...
...
@@ -1821,7 +1825,7 @@ class TestCRMMailSend(BaseTestCRM):
self
.
tic
()
new_event
=
event
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
assertFalse
(
new_event
.
hasFile
(),
'%r has a file'
%
(
new_event
,))
self
.
assertEqual
(
new_event
.
getData
(),
''
)
self
.
assertEqual
(
new_event
.
getData
(),
b
''
)
self
.
assertEqual
(
new_event
.
getTitle
(),
real_title
)
self
.
assertEqual
(
new_event
.
getTextContent
(),
real_content
)
self
.
assertNotEqual
(
new_event
.
getReference
(),
event
.
getReference
())
...
...
@@ -2036,8 +2040,8 @@ class TestCRMMailSend(BaseTestCRM):
self
.
assertEqual
(
5
,
len
(
self
.
portal
.
MailHost
.
_message_list
))
for
message_info
in
self
.
portal
.
MailHost
.
_message_list
:
self
.
assertIn
(
mail_text_content
,
message_info
[
-
1
])
message
=
message_from_string
(
message_info
[
-
1
])
self
.
assertIn
(
mail_text_content
,
message_info
[
-
1
]
.
decode
()
)
message
=
message_from_string
(
message_info
[
-
1
]
.
decode
()
)
self
.
assertTrue
(
DateTime
(
message
.
get
(
"Date"
)).
isCurrentDay
())
def
test_MailMessage_send_simple_case
(
self
):
...
...
@@ -2069,7 +2073,7 @@ class TestCRMMailSend(BaseTestCRM):
mail_message
.
send
(
extra_header_dict
=
{
"X-test-header"
:
"test"
})
self
.
tic
()
(
_
,
_
,
last_message
,),
=
self
.
portal
.
MailHost
.
_message_list
message
=
message_from_string
(
last_message
)
message
=
message_from_string
(
last_message
.
decode
()
)
self
.
assertEqual
(
"test"
,
message
.
get
(
"X-test-header"
))
...
...
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