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
5afebc71
Commit
5afebc71
authored
Jan 28, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testDms
parent
43d8c9ce
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
212 additions
and
207 deletions
+212
-207
bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py
...ateItem/portal_components/test.erp5.testERP5Discussion.py
+4
-5
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
...s/TestTemplateItem/portal_components/test.erp5.testDms.py
+169
-163
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testOOoConversionCache.py
...tem/portal_components/test.erp5.testOOoConversionCache.py
+12
-12
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testOOoConversionServerRetry.py
...rtal_components/test.erp5.testOOoConversionServerRetry.py
+5
-6
bt5/erp5_dms_conversion_catalog/TestTemplateItem/portal_components/test.erp5.testDmsWithPreConversion.py
...m/portal_components/test.erp5.testDmsWithPreConversion.py
+3
-3
bt5/erp5_km/TestTemplateItem/portal_components/test.erp5.testKM.py
...km/TestTemplateItem/portal_components/test.erp5.testKM.py
+9
-8
bt5/erp5_pdf_merge/TestTemplateItem/portal_components/test.erp5.testERP5PDFMerge.py
...plateItem/portal_components/test.erp5.testERP5PDFMerge.py
+6
-6
bt5/erp5_run_my_doc/TestTemplateItem/portal_components/test.erp5.testRunMyDoc.py
...tTemplateItem/portal_components/test.erp5.testRunMyDoc.py
+4
-4
No files found.
bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py
View file @
5afebc71
...
...
@@ -31,11 +31,10 @@
import
unittest
from
AccessControl.SecurityManagement
import
newSecurityManager
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.test.testDms
import
makeFileUpload
from
erp5.component.test.testDms
import
DocumentUploadTestCase
class
TestERP5Discussion
(
ERP5Type
TestCase
):
class
TestERP5Discussion
(
DocumentUpload
TestCase
):
"""Test for erp5_discussion business template.
"""
...
...
@@ -143,7 +142,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
self
.
assertEqual
(
0
,
len
(
attachment_list
))
# check attachment creation
file_
=
makeFileUpload
(
'TEST-en-002.doc'
)
file_
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
web_section1
.
WebSection_createNewDiscussionThread
(
'test1-new-with-attachment'
,
'test1 body'
,
file
=
file_
)
discussion_thread
,
=
[
x
for
x
in
self
.
portal
.
discussion_thread_module
.
objectValues
()
\
if
x
.
getId
()
not
in
discussion_thread_id_set
]
...
...
@@ -240,7 +239,7 @@ class TestERP5Discussion(ERP5TypeTestCase):
web_site_value
=
self
.
portal
.
web_site_module
.
newContent
(
portal_type
=
'Web Site'
)
web_section_value
=
web_site_value
.
newContent
(
portal_type
=
'Web Section'
)
file_
=
makeFileUpload
(
'simple.csv'
)
file_
=
self
.
makeFileUpload
(
'simple.csv'
)
web_section_value
.
WebSection_createNewDiscussionThread
(
"Thread Title"
,
"Post Content"
,
...
...
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
View file @
5afebc71
...
...
@@ -46,13 +46,12 @@
"""
from
__future__
import
print_function
import
io
import
unittest
import
time
from
six.moves
import
cStringIO
as
StringIO
from
subprocess
import
Popen
,
PIPE
from
unittest
import
expectedFailure
from
Products.ERP5Type.Utils
import
bytes2str
,
str2bytes
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.utils
import
FileUpload
from
Products.ERP5Type.tests.utils
import
DummyLocalizer
...
...
@@ -88,20 +87,25 @@ REFERENCE_REGULAR_EXPRESSION = "(?P<reference>[A-Z]{3,10})(-(?P<language>[a-z]{2
def
makeFilePath
(
name
):
return
os
.
path
.
join
(
TEST_FILES_HOME
,
name
)
def
makeFileUpload
(
name
,
as_name
=
None
):
def
getFileSize
(
name
):
path
=
makeFilePath
(
name
)
with
open
(
path
,
"rb"
)
as
f
:
return
len
(
f
.
read
())
class
DocumentUploadTestCase
(
ERP5TypeTestCase
):
def
makeFileUpload
(
self
,
name
,
as_name
=
None
):
if
as_name
is
None
:
as_name
=
name
path
=
makeFilePath
(
name
)
return
FileUpload
(
path
,
as_name
)
fu
=
FileUpload
(
path
,
as_name
)
self
.
addCleanup
(
fu
.
close
)
return
fu
def
getFileSize
(
name
):
path
=
makeFilePath
(
name
)
f
=
open
(
path
,
"r"
)
file_size
=
len
(
f
.
read
())
f
.
close
()
return
file_size
class
TestDocumentMixin
(
ERP5Type
TestCase
):
class
TestDocumentMixin
(
DocumentUpload
TestCase
):
business_template_list
=
[
'erp5_core_proxy_field_legacy'
,
'erp5_jquery'
,
...
...
@@ -185,6 +189,7 @@ class TestDocumentMixin(ERP5TypeTestCase):
doc_module
.
manage_delObjects
(
list
(
doc_module
.
objectIds
()))
self
.
tic
()
class
TestDocument
(
TestDocumentMixin
):
"""
Test basic document - related operations
...
...
@@ -231,14 +236,18 @@ class TestDocument(TestDocumentMixin):
def
getURLSizeList
(
self
,
uri
,
**
kw
):
# __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password
url
=
'%s?%s
&__ac=%s'
%
(
uri
,
make_query
(
kw
),
'RVJQNVR5cGVUZXN0Q2FzZTo%3D'
)
format_
=
kw
.
get
(
'format'
,
'jpeg'
)
url
=
'%s?%s
'
%
(
uri
,
make_query
(
dict
(
kw
,
__ac
=
'RVJQNVR5cGVUZXN0Q2FzZTo%3D'
))
)
format_
=
kw
.
get
(
'format'
,
'jpeg'
)
infile
=
urlopen
(
url
)
try
:
image_data
=
infile
.
read
()
finally
:
infile
.
close
()
# save as file with proper incl. format filename (for some reasons PIL uses this info)
filename
=
"%s%stest-image-format-resize.%s"
%
(
os
.
getcwd
(),
os
.
sep
,
format_
)
filename
=
"%s%stest-image-format-resize.%s"
%
(
os
.
getcwd
(),
os
.
sep
,
format_
)
with
open
(
filename
,
"wb"
)
as
f
:
f
.
write
(
infile
.
read
())
infile
.
close
()
f
.
write
(
image_data
)
file_size
=
len
(
image_data
)
try
:
from
PIL
import
Image
...
...
@@ -279,7 +288,7 @@ class TestDocument(TestDocumentMixin):
# the same document should now have revision 4 (because it should have done mergeRevision)
# getRevisionList should return (1, 2, 3, 4)
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
document_url
=
document
.
getRelativeUrl
()
...
...
@@ -491,38 +500,38 @@ class TestDocument(TestDocumentMixin):
# create docs to be referenced:
# (1) TEST, 002, en
filename
=
'TEST-en-002.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document1
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# (2) TEST, 002, fr
as_name
=
'TEST-fr-002.odt'
file_
=
makeFileUpload
(
filename
,
as_name
)
file_
=
self
.
makeFileUpload
(
filename
,
as_name
)
document2
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# (3) TEST, 003, en
as_name
=
'TEST-en-003.odt'
file_
=
makeFileUpload
(
filename
,
as_name
)
file_
=
self
.
makeFileUpload
(
filename
,
as_name
)
document3
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# create docs to contain references in text_content:
# REF, 002, en; "I use reference to look up TEST"
filename
=
'REF-en-002.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document5
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# REFLANG, 001, en: "I use reference and language to look up TEST-fr"
filename
=
'REFLANG-en-001.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document6
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# REFVER, 001, en: "I use reference and version to look up TEST-002"
filename
=
'REFVER-en-001.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document7
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en"
filename
=
'REFVERLANG-en-001.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document8
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
...
...
@@ -578,7 +587,7 @@ class TestDocument(TestDocumentMixin):
def
test_catalog_search_by_size
(
self
):
doc
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
,
file
=
makeFileUpload
(
'import_data_list.ods'
))
file
=
self
.
makeFileUpload
(
'import_data_list.ods'
))
self
.
tic
()
self
.
assertEqual
(
[
x
.
getObject
()
for
x
in
self
.
portal
.
portal_catalog
(
size
=
doc
.
getSize
())],
[
doc
])
...
...
@@ -586,8 +595,8 @@ class TestDocument(TestDocumentMixin):
def
testOOoDocument_get_size
(
self
):
# test get_size on OOoDocument
doc
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
)
doc
.
edit
(
file
=
makeFileUpload
(
'import_data_list.ods'
))
self
.
assertEqual
(
len
(
makeFileUpload
(
'import_data_list.ods'
).
read
()),
doc
.
edit
(
file
=
self
.
makeFileUpload
(
'import_data_list.ods'
))
self
.
assertEqual
(
len
(
self
.
makeFileUpload
(
'import_data_list.ods'
).
read
()),
doc
.
get_size
())
def
testTempOOoDocument_get_size
(
self
):
...
...
@@ -600,14 +609,14 @@ class TestDocument(TestDocumentMixin):
# test hasData on OOoDocument
doc
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
)
self
.
assertFalse
(
doc
.
hasData
())
doc
.
edit
(
file
=
makeFileUpload
(
'import_data_list.ods'
))
doc
.
edit
(
file
=
self
.
makeFileUpload
(
'import_data_list.ods'
))
self
.
assertTrue
(
doc
.
hasData
())
def
testTempOOoDocument_hasData
(
self
):
# test hasData on TempOOoDocument
doc
=
self
.
portal
.
newContent
(
temp_object
=
True
,
portal_type
=
'OOo Document'
,
id
=
'tmp'
)
self
.
assertFalse
(
doc
.
hasData
())
doc
.
edit
(
file
=
makeFileUpload
(
'import_data_list.ods'
))
doc
.
edit
(
file
=
self
.
makeFileUpload
(
'import_data_list.ods'
))
self
.
assertTrue
(
doc
.
hasData
())
def
test_Owner_Base_download
(
self
):
...
...
@@ -617,7 +626,7 @@ class TestDocument(TestDocumentMixin):
doc
=
self
.
portal
.
document_module
.
newContent
(
filename
=
'test.ods'
,
portal_type
=
'Spreadsheet'
)
doc
.
edit
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
))
doc
.
edit
(
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
))
self
.
tic
()
uf
=
self
.
portal
.
acl_users
...
...
@@ -627,7 +636,7 @@ class TestDocument(TestDocumentMixin):
response
=
self
.
publish
(
'%s/Base_download'
%
doc
.
getPath
(),
basic
=
'member_user1:secret'
)
self
.
assertEqual
(
makeFileUpload
(
'TEST-en-002.doc'
).
read
(),
self
.
assertEqual
(
self
.
makeFileUpload
(
'TEST-en-002.doc'
).
read
(),
response
.
getBody
())
self
.
assertEqual
(
'application/msword'
,
response
.
headers
[
'content-type'
])
...
...
@@ -656,7 +665,7 @@ class TestDocument(TestDocumentMixin):
doc
=
self
.
portal
.
document_module
.
newContent
(
filename
=
'test.ods'
,
portal_type
=
'Spreadsheet'
)
doc
.
edit
(
file
=
makeFileUpload
(
'import.file.with.dot.in.filename.ods'
))
doc
.
edit
(
file
=
self
.
makeFileUpload
(
'import.file.with.dot.in.filename.ods'
))
doc
.
publish
()
self
.
tic
()
...
...
@@ -671,12 +680,8 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
'attachment; filename="import.file.with.dot.in.filename.pdf"'
,
response
.
getHeader
(
'content-disposition'
))
response_body
=
response
.
getBody
()
conversion
=
str
(
doc
.
convert
(
'pdf'
)[
1
])
diff
=
'
\
n
'
+
'
\
n
'
.
join
(
difflib
.
unified_diff
(
response_body
.
splitlines
(),
conversion
.
splitlines
(),
fromfile
=
'first_call.pdf'
,
tofile
=
'second_call.pdf'
))
self
.
assertEqual
(
response_body
,
conversion
,
diff
)
conversion
=
doc
.
convert
(
'pdf'
)[
1
]
self
.
assertEqual
(
response_body
,
conversion
)
# test Print icon works on OOoDocument
response
=
self
.
publish
(
'%s/OOoDocument_print'
%
doc
.
getPath
())
...
...
@@ -734,13 +739,13 @@ class TestDocument(TestDocumentMixin):
def
test_csv
(
self
):
doc
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
,
file
=
makeFileUpload
(
'simple.csv'
),
file
=
self
.
makeFileUpload
(
'simple.csv'
),
)
self
.
assertEqual
(
doc
.
getContentType
(),
'text/csv'
)
doc
.
publish
()
self
.
tic
()
response
=
self
.
publish
(
'%s?format='
%
doc
.
getPath
())
self
.
assertEqual
(
response
.
getBody
(),
makeFileUpload
(
'simple.csv'
).
read
())
self
.
assertEqual
(
response
.
getBody
(),
self
.
makeFileUpload
(
'simple.csv'
).
read
())
self
.
assertEqual
(
response
.
getHeader
(
'Content-Type'
),
'text/csv; charset=utf-8'
)
self
.
assertEqual
(
response
.
getHeader
(
'Content-Disposition'
),
'attachment; filename="simple.csv"'
)
...
...
@@ -762,7 +767,7 @@ class TestDocument(TestDocumentMixin):
is not draft
"""
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
assertEqual
(
'converting'
,
document
.
getExternalProcessingState
())
...
...
@@ -827,7 +832,7 @@ class TestDocument(TestDocumentMixin):
document.
"""
filename
=
'EmbeddedImage-en-002.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
...
...
@@ -1313,7 +1318,7 @@ class TestDocument(TestDocumentMixin):
re_html_nbsp
=
re
.
compile
(
'&(nbsp|#160);'
)
def
test_PDFTextContent
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
self
.
assertEqual
(
'I use reference to look up TEST
\
n
'
,
...
...
@@ -1324,7 +1329,7 @@ class TestDocument(TestDocumentMixin):
document
.
SearchableText
())
def
test_PDFToPng
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
...
...
@@ -1336,7 +1341,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
image_data
[
1
:
4
],
b'PNG'
)
def
test_PDFToJpg
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
...
...
@@ -1347,7 +1352,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
image_data
[
6
:
10
],
b'JFIF'
)
def
test_PDFToGif
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
...
...
@@ -1358,7 +1363,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
image_data
[
0
:
4
],
b'GIF8'
)
def
test_PDFToTiff
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
...
...
@@ -1370,7 +1375,7 @@ class TestDocument(TestDocumentMixin):
def
test_PDF_content_information
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
content_information
=
document
.
getContentInformation
()
...
...
@@ -1382,7 +1387,7 @@ class TestDocument(TestDocumentMixin):
def
test_PDF_content_information_extra_metadata
(
self
):
# Extra metadata, such as those stored by pdftk update_info are also
# available in document.getContentInformation()
upload_file
=
makeFileUpload
(
'metadata.pdf'
,
as_name
=
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'metadata.pdf'
,
as_name
=
'REF-en-001.pdf'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
'PDF'
,
document
.
getPortalType
())
...
...
@@ -1393,7 +1398,7 @@ class TestDocument(TestDocumentMixin):
# contribute file which will be merged to current document in synchronous mode
# and check content_type recalculated
upload_file
=
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
,
as_name
=
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
,
as_name
=
'REF-en-001.pdf'
)
contributed_document
=
self
.
portal
.
Base_contribute
(
file
=
upload_file
,
\
synchronous_metadata_discovery
=
True
)
self
.
tic
()
...
...
@@ -1407,7 +1412,7 @@ class TestDocument(TestDocumentMixin):
document
.
getContentInformation
()[
'Pages'
])
# upload with another file and check content_type recalculated
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
.
setFile
(
upload_file
)
self
.
tic
()
content_information
=
document
.
getContentInformation
()
...
...
@@ -1425,7 +1430,7 @@ class TestDocument(TestDocumentMixin):
# IndirectObject instance which is not picklable
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
file
=
makeFileUpload
(
'apple_metadata.pdf'
))
file
=
self
.
makeFileUpload
(
'apple_metadata.pdf'
))
# content_information is picklable
content_information
=
document
.
getContentInformation
()
from
pickle
import
dumps
...
...
@@ -1438,7 +1443,7 @@ class TestDocument(TestDocumentMixin):
""" Test that pypdf2 handle wrong formatted PDF """
pdf
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
file
=
makeFileUpload
(
'FEUILLE BLANCHE.pdf'
),
file
=
self
.
makeFileUpload
(
'FEUILLE BLANCHE.pdf'
),
title
=
'Bad PDF'
)
self
.
tic
()
pdf
.
share
()
...
...
@@ -1448,7 +1453,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertNotEqual
(
result
,
None
)
def
test_PDF_content_content_type
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
)
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
)
# Here we use edit instead of setFile,
# because only edit method set filename as filename.
...
...
@@ -1457,17 +1462,17 @@ class TestDocument(TestDocumentMixin):
def
test_PDF_watermark
(
self
):
original_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'REF-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
))
# This watermark.pdf document is a pdf with a transparent background. Such
# document can be created using GIMP
watermark_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'watermark.pdf'
))
file
=
self
.
makeFileUpload
(
'watermark.pdf'
))
watermarked_data
=
original_document
.
getWatermarkedData
(
watermark_data
=
watermark_document
.
getData
(),
repeat_watermark
=
False
)
# this looks like a pdf
self
.
assertTrue
(
watermarked_data
.
startswith
(
'%PDF-1.3'
))
self
.
assertTrue
(
watermarked_data
.
startswith
(
b
'%PDF-1.3'
))
# and ERP5 can make a PDF Document out of it
watermarked_document
=
self
.
portal
.
document_module
.
newContent
(
...
...
@@ -1480,14 +1485,14 @@ class TestDocument(TestDocumentMixin):
def
test_PDF_watermark_repeat
(
self
):
# watermark a pdf, repeating the watermark
original_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
))
watermark_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'watermark.pdf'
))
file
=
self
.
makeFileUpload
(
'watermark.pdf'
))
watermarked_data
=
original_document
.
getWatermarkedData
(
watermark_data
=
watermark_document
.
getData
(),
repeat_watermark
=
True
)
self
.
assertTrue
(
watermarked_data
.
startswith
(
'%PDF-1.3'
))
self
.
assertTrue
(
watermarked_data
.
startswith
(
b
'%PDF-1.3'
))
watermarked_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
data
=
watermarked_data
)
...
...
@@ -1498,15 +1503,15 @@ class TestDocument(TestDocumentMixin):
def
test_PDF_watermark_start_page
(
self
):
# watermark a pdf, starting on the second page
original_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
))
watermark_document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'watermark.pdf'
))
file
=
self
.
makeFileUpload
(
'watermark.pdf'
))
watermarked_data
=
original_document
.
getWatermarkedData
(
watermark_data
=
watermark_document
.
getData
(),
repeat_watermark
=
False
,
watermark_start_page
=
1
)
# This is 0 based.
self
.
assertTrue
(
watermarked_data
.
startswith
(
'%PDF-1.3'
))
self
.
assertTrue
(
watermarked_data
.
startswith
(
b
'%PDF-1.3'
))
watermarked_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
data
=
watermarked_data
)
...
...
@@ -1515,7 +1520,7 @@ class TestDocument(TestDocumentMixin):
watermarked_document
.
getData
())
def
test_checkVisibleTextInPresentationToImageConversion
(
self
):
odp
=
makeFileUpload
(
"TEST-en-003.odp"
)
odp
=
self
.
makeFileUpload
(
"TEST-en-003.odp"
)
presentation
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
"Presentation"
,
data
=
odp
,
...
...
@@ -1535,7 +1540,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertIn
(
"ERP5 DMS page 1"
,
txt
)
def
test_Document_getStandardFilename
(
self
):
upload_file
=
makeFileUpload
(
'metadata.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'metadata.pdf'
)
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
)
document
.
edit
(
file
=
upload_file
)
self
.
assertEqual
(
document
.
getStandardFilename
(),
'metadata.pdf'
)
...
...
@@ -1547,7 +1552,7 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
document
.
getStandardFilename
(
format
=
'png'
),
'metadata-001-en.png'
)
# check when format contains multiple '.'
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
document
.
edit
(
file
=
upload_file
)
self
.
assertEqual
(
document
.
getStandardFilename
(),
'TEST-en-003.odp'
)
...
...
@@ -1555,18 +1560,18 @@ class TestDocument(TestDocumentMixin):
def
test_CMYKImageTextContent
(
self
):
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'cmyk_sample.jpg'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'Image'
,
document
.
getPortalType
())
self
.
assertEqual
(
'ERP5 is a free software.'
,
document
.
asText
())
def
test_MonochromeImageResize
(
self
):
upload_file
=
makeFileUpload
(
'monochrome_sample.tiff'
)
upload_file
=
self
.
makeFileUpload
(
'monochrome_sample.tiff'
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
assertEqual
(
'Image'
,
document
.
getPortalType
())
resized_image
=
document
.
convert
(
format
=
'png'
,
display
=
'small'
)[
1
]
identify_output
=
Popen
([
'identify'
,
'-verbose'
,
'-'
],
stdin
=
PIPE
,
stdout
=
PIPE
).
communicate
(
resized_image
)[
0
]
self
.
assertNotIn
(
'1-bit'
,
identify_output
)
self
.
assertNotIn
(
b
'1-bit'
,
identify_output
)
self
.
assertEqual
(
'ERP5 is a free software.'
,
document
.
asText
())
def
test_Base_showFoundText
(
self
):
...
...
@@ -1574,7 +1579,7 @@ class TestDocument(TestDocumentMixin):
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Drawing'
)
self
.
assertEqual
(
'empty'
,
document
.
getExternalProcessingState
())
upload_file
=
makeFileUpload
(
'TEST-en-002.odt'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.odt'
)
document
.
edit
(
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
'converted'
,
document
.
getExternalProcessingState
())
...
...
@@ -1589,7 +1594,7 @@ class TestDocument(TestDocumentMixin):
document
.
Base_showFoundText
())
# upload again good content
upload_file
=
makeFileUpload
(
'TEST-en-002.odt'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.odt'
)
document
.
edit
(
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
'converted'
,
document
.
getExternalProcessingState
())
...
...
@@ -1600,18 +1605,18 @@ class TestDocument(TestDocumentMixin):
Check that encoding remains.
"""
web_page_portal_type
=
'Web Page'
string_to_test
=
'éààéôù'
string_to_test
=
u
'éààéôù'
web_page
=
self
.
portal
.
getDefaultModule
(
web_page_portal_type
)
\
.
newContent
(
portal_type
=
web_page_portal_type
)
html_content
=
'<p>%s</p>'
%
string_to_test
html_content
=
u
'<p>%s</p>'
%
string_to_test
web_page
.
edit
(
text_content
=
html_content
)
_
,
pdf_data
=
web_page
.
convert
(
'pdf'
)
text_content
=
self
.
portal
.
portal_transforms
.
\
convertToData
(
'text/plain'
,
str
(
pdf_data
),
bytes
(
pdf_data
),
object
=
web_page
,
context
=
web_page
,
filename
=
'test.pdf'
)
self
.
assertIn
(
string_to_test
,
text_content
)
self
.
assertIn
(
string_to_test
,
text_content
.
decode
(
'utf-8'
)
)
def
test_HTML_to_ODT_conversion_keep_related_image_list
(
self
):
"""This test create a Web Page and an Image.
...
...
@@ -1633,7 +1638,7 @@ class TestDocument(TestDocumentMixin):
.
newContent
(
portal_type
=
image_portal_type
)
# edit content and publish it
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'cmyk_sample.jpg'
)
image
.
edit
(
reference
=
image_reference
,
version
=
'001'
,
language
=
'en'
,
...
...
@@ -1669,7 +1674,7 @@ class TestDocument(TestDocumentMixin):
# Let's continue with Presentation Document as embbeded image
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
image_reference
=
'IMAGE-odp'
document
.
edit
(
file
=
upload_file
,
reference
=
image_reference
)
document
.
publish
()
...
...
@@ -1740,7 +1745,7 @@ class TestDocument(TestDocumentMixin):
module
=
self
.
portal
.
getDefaultModule
(
web_page_portal_type
)
web_page
=
module
.
newContent
(
portal_type
=
web_page_portal_type
)
html_content
=
"""<html>
html_content
=
u
"""<html>
<head>
<meta http-equiv="refresh" content="5;url=http://example.com/"/>
<meta http-equiv="Set-Cookie" content=""/>
...
...
@@ -1766,9 +1771,7 @@ class TestDocument(TestDocumentMixin):
</body>
</html>
"""
if
six
.
PY2
:
html_content
=
html_content
.
decode
(
'utf-8'
).
encode
(
'iso-8859-1'
)
html_content
=
html_content
.
encode
(
'iso-8859-1'
)
# content encoded into another codec
# than utf-8 comes from necessarily an external file
# (Ingestion, or FileField), not from user interface
...
...
@@ -1777,12 +1780,8 @@ class TestDocument(TestDocumentMixin):
# as it is done in reality
# Mimic the behaviour of a FileUpload from WebPage_view
file_like
=
StringIO
()
file_like
.
write
(
html_content
)
setattr
(
file_like
,
'filename'
,
'something.htm'
)
if
six
.
PY3
:
from
io
import
BytesIO
file_like
=
BytesIO
(
file_like
.
getvalue
().
encode
())
file_like
=
io
.
BytesIO
(
html_content
)
file_like
.
filename
=
'something.htm'
web_page
.
edit
(
file
=
file_like
)
# run conversion to base format
self
.
tic
()
...
...
@@ -1889,7 +1888,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
self
.
assertNotIn
(
'#FFAA44'
,
safe_html
)
filename
=
'broken_html.html'
file_object
=
makeFileUpload
(
filename
)
file_object
=
self
.
makeFileUpload
(
filename
)
web_page
.
edit
(
file
=
file_object
)
assert
web_page
.
convert
(
'html'
)[
1
]
...
...
@@ -1949,7 +1948,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
document_module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
document
=
document_module
.
newContent
(
portal_type
=
portal_type
)
upload_file
=
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'Forty-Two.Pages-en-001.pdf'
)
document
.
edit
(
file
=
upload_file
)
pages_number
=
int
(
document
.
getContentInformation
()[
'Pages'
])
self
.
tic
()
...
...
@@ -2053,16 +2052,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
"""
web_page_portal_type
=
'Web Page'
module
=
self
.
portal
.
getDefaultModule
(
web_page_portal_type
)
upload_file
=
makeFileUpload
(
'TEST-text-iso8859-1.txt'
)
web_page
=
module
.
newContent
(
portal_type
=
web_page_portal_type
,
upload_file
=
self
.
makeFileUpload
(
'TEST-text-iso8859-1.txt'
)
web_page
=
module
.
newContent
(
portal_type
=
web_page_portal_type
,
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
web_page
.
getContentType
(),
'text/plain'
)
text_content
=
web_page
.
getTextContent
()
my_utf_eight_token
=
'ùééàçèîà'
text_content
=
text_content
.
replace
(
'
\
n
'
,
'
\
n
%s
\
n
'
%
my_utf_eight_token
)
self
.
assertIn
(
'éèàùôâïî'
,
text_content
)
self
.
assertIn
(
'éèàùôâïî'
,
web_page
.
asStrippedHTML
())
self
.
assertIn
(
'éèàùôâïî'
,
web_page
.
asEntireHTML
())
added_utf_eight_token
=
'ùééàçèîà'
text_content
=
text_content
.
replace
(
'
\
n
'
,
'
\
n
%s
\
n
'
%
added_utf_eight_token
)
web_page
.
edit
(
text_content
=
text_content
)
self
.
assertIn
(
my_utf_eight_token
,
web_page
.
asStrippedHTML
())
self
.
assertTrue
(
isinstance
(
web_page
.
asEntireHTML
().
decode
(
'utf-8'
),
unicode
))
self
.
assertIn
(
'éèàùôâïî'
,
web_page
.
asStrippedHTML
())
self
.
assertIn
(
'éèàùôâïî'
,
web_page
.
asEntireHTML
())
self
.
assertIn
(
added_utf_eight_token
,
web_page
.
asStrippedHTML
())
self
.
assertIn
(
added_utf_eight_token
,
web_page
.
asEntireHTML
())
def
test_PDFDocument_asTextConversion
(
self
):
"""Test a PDF document with embedded images
...
...
@@ -2070,24 +2077,24 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
"""
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
file
=
makeFileUpload
(
'TEST.Embedded.Image.pdf'
))
file
=
self
.
makeFileUpload
(
'TEST.Embedded.Image.pdf'
))
self
.
assertEqual
(
document
.
asText
(),
'ERP5 is a free software.'
)
def
test_broken_pdf_asText
(
self
):
class
StringIOWithFilename
(
String
IO
):
class
BytesIOWithFilename
(
io
.
Bytes
IO
):
filename
=
'broken.pdf'
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
file
=
StringIOWithFilename
(
'broken'
))
file
=
BytesIOWithFilename
(
b
'broken'
))
self
.
assertEqual
(
document
.
asText
(),
''
)
self
.
tic
()
# no activity failure
def
test_password_protected_pdf_asText
(
self
):
pdf_reader
=
PyPDF2
.
PdfFileReader
(
makeFileUpload
(
'TEST.Embedded.Image.pdf'
))
pdf_reader
=
PyPDF2
.
PdfFileReader
(
self
.
makeFileUpload
(
'TEST.Embedded.Image.pdf'
))
pdf_writer
=
PyPDF2
.
PdfFileWriter
()
pdf_writer
.
addPage
(
pdf_reader
.
getPage
(
0
))
pdf_writer
.
encrypt
(
'secret'
)
encrypted_pdf_stream
=
String
IO
()
encrypted_pdf_stream
=
io
.
Bytes
IO
()
pdf_writer
.
write
(
encrypted_pdf_stream
)
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
...
...
@@ -2109,7 +2116,7 @@ return 1
def
_test_document_conversion_to_base_format_no_original_format_access
(
self
,
portal_type
,
filename
):
module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
upload_file
=
makeFileUpload
(
filename
)
upload_file
=
self
.
makeFileUpload
(
filename
)
document
=
module
.
newContent
(
portal_type
=
portal_type
,
file
=
upload_file
)
...
...
@@ -2161,7 +2168,7 @@ return 1
self
.
commit
()
# Create document with good content
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
document
.
edit
(
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
'converted'
,
document
.
getExternalProcessingState
())
...
...
@@ -2169,12 +2176,12 @@ return 1
for
credential
in
[
'ERP5TypeTestCase:'
,
'zope_user:'
]:
response
=
self
.
publish
(
'%s/%s'
%
(
document
.
getPath
(),
object_url
),
basic
=
credential
)
self
.
assertIn
(
'200 OK'
,
response
.
getOutput
())
self
.
assertIn
(
b
'200 OK'
,
response
.
getOutput
())
# OOod produced HTML navigation, test it
self
.
assertIn
(
'First page'
,
response
.
getBody
())
self
.
assertIn
(
'Back'
,
response
.
getBody
())
self
.
assertIn
(
'Continue'
,
response
.
getBody
())
self
.
assertIn
(
'Last page'
,
response
.
getBody
())
self
.
assertIn
(
b
'First page'
,
response
.
getBody
())
self
.
assertIn
(
b
'Back'
,
response
.
getBody
())
self
.
assertIn
(
b
'Continue'
,
response
.
getBody
())
self
.
assertIn
(
b
'Last page'
,
response
.
getBody
())
def
test_getTargetFormatItemList
(
self
):
"""
...
...
@@ -2186,7 +2193,7 @@ return 1
portal_type
=
'PDF'
module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
upload_file
=
makeFileUpload
(
'TEST.Large.Document.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'TEST.Large.Document.pdf'
)
pdf
=
module
.
newContent
(
portal_type
=
portal_type
,
file
=
upload_file
)
self
.
assertIn
(
'html'
,
pdf
.
getTargetFormatList
())
...
...
@@ -2207,7 +2214,7 @@ return 1
self
.
assertSameSet
([],
presentation
.
getTargetFormatList
())
# test uploading some data
upload_file
=
makeFileUpload
(
'Foo_001.odg'
)
upload_file
=
self
.
makeFileUpload
(
'Foo_001.odg'
)
presentation
.
edit
(
file
=
upload_file
)
self
.
tic
()
self
.
assertIn
(
'odg'
,
presentation
.
getTargetFormatList
())
...
...
@@ -2235,7 +2242,7 @@ return 1
# images from same instance accessed by reference and wrong conversion arguments (dispay NOT display)
# code should be more resilient
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'cmyk_sample.jpg'
)
image
=
self
.
portal
.
image_module
.
newContent
(
portal_type
=
'Image'
,
reference
=
'Embedded-XXX'
,
version
=
'001'
,
...
...
@@ -2278,15 +2285,15 @@ return 1
"""
# Create OOo document
ooo_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
ooo_document
.
edit
(
file
=
upload_file
)
pdf_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
)
upload_file
=
makeFileUpload
(
'TEST-en-002.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.pdf'
)
pdf_document
.
edit
(
file
=
upload_file
)
image_document
=
self
.
portal
.
image_module
.
newContent
(
portal_type
=
'Image'
)
upload_file
=
makeFileUpload
(
'TEST-en-002.png'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.png'
)
image_document
.
edit
(
file
=
upload_file
)
web_page_document
=
self
.
portal
.
web_page_module
.
newContent
(
portal_type
=
"Web Page"
)
...
...
@@ -2370,19 +2377,19 @@ return 1
"""
def
getURL
(
uri
,
**
kw
):
# __ac=RVJQNVR5cGVUZXN0Q2FzZTo%3D is encoded ERP5TypeTestCase with empty password
url
=
'%s?%s
&__ac=%s'
%
(
uri
,
urlencode
(
kw
),
'RVJQNVR5cGVUZXN0Q2FzZTo%3D'
)
url
=
'%s?%s
'
%
(
uri
,
urlencode
(
dict
(
kw
,
__ac
=
'RVJQNVR5cGVUZXN0Q2FzZTo%3D'
))
)
return
urlopen
(
url
)
ooo_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
ooo_document
.
edit
(
file
=
upload_file
)
pdf_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
)
upload_file
=
makeFileUpload
(
'TEST-en-002.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.pdf'
)
pdf_document
.
edit
(
file
=
upload_file
)
image_document
=
self
.
portal
.
image_module
.
newContent
(
portal_type
=
'Image'
)
upload_file
=
makeFileUpload
(
'TEST-en-002.png'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.png'
)
image_document
.
edit
(
file
=
upload_file
)
web_page_document
=
self
.
portal
.
web_page_module
.
newContent
(
portal_type
=
"Web Page"
)
...
...
@@ -2391,25 +2398,25 @@ return 1
web_page_document
.
setTextContentSubstitutionMappingMethodId
(
'WebPage_getStandardSubstitutionMappingDict'
)
self
.
tic
()
response
=
getURL
(
image_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
In
(
'Content-Type: image/png
\
r
\
n
'
,
response
.
info
().
headers
)
self
.
assert
In
(
'Content-Length: %s
\
r
\
n
'
%
getFileSize
(
'TEST-en-002.png'
),
response
.
info
().
headers
)
response
=
getURL
(
image_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Type'
),
'image/png'
)
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Length'
),
str
(
getFileSize
(
'TEST-en-002.png'
))
)
response
=
getURL
(
ooo_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
In
(
'Content-Type: application/vnd.oasis.opendocument.presentation
\
r
\
n
'
,
response
.
info
().
headers
)
self
.
assert
In
(
'Content-Disposition: attachment; filename="TEST-en-003.odp"
\
r
\
n
'
,
response
.
info
().
headers
)
self
.
assert
In
(
'Content-Length: %s
\
r
\
n
'
%
getFileSize
(
'TEST-en-003.odp'
),
response
.
info
().
headers
)
response
=
getURL
(
ooo_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Type'
),
'application/vnd.oasis.opendocument.presentation'
)
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Disposition'
),
'attachment; filename="TEST-en-003.odp"'
)
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Length'
),
str
(
getFileSize
(
'TEST-en-003.odp'
))
)
response
=
getURL
(
pdf_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
In
(
'Content-Type: application/pdf
\
r
\
n
'
,
response
.
info
().
headers
)
self
.
assert
In
(
'Content-Disposition: attachment; filename="TEST-en-002.pdf"
\
r
\
n
'
,
response
.
info
().
headers
)
response
=
getURL
(
pdf_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Type'
),
'application/pdf'
)
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Disposition'
),
'attachment; filename="TEST-en-002.pdf"'
)
response
=
getURL
(
pdf_document
.
absolute_url
(),
**
{
'format'
:
'pdf'
})
self
.
assert
In
(
'Content-Type: application/pdf
\
r
\
n
'
,
response
.
info
().
headers
)
self
.
assert
In
(
'Content-Disposition: attachment; filename="TEST-en-002.pdf"
\
r
\
n
'
,
response
.
info
().
headers
)
response
=
getURL
(
pdf_document
.
absolute_url
(),
**
{
'format'
:
'pdf'
})
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Type'
),
'application/pdf'
)
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Disposition'
),
'attachment; filename="TEST-en-002.pdf"'
)
response
=
getURL
(
web_page_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
In
(
'Content-Type: text/html; charset=utf-8
\
r
\
n
'
,
response
.
info
().
headers
)
response
=
getURL
(
web_page_document
.
absolute_url
(),
**
{
'format'
:
''
})
self
.
assert
Equal
(
response
.
info
().
get
(
'Content-Type'
),
'text/html; charset=utf-8'
)
def
test_checkConversionFormatPermission
(
self
):
"""
...
...
@@ -2417,7 +2424,7 @@ return 1
"""
portal_type
=
'PDF'
module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
upload_file
=
makeFileUpload
(
'TEST.Large.Document.pdf'
)
upload_file
=
self
.
makeFileUpload
(
'TEST.Large.Document.pdf'
)
pdf
=
module
.
newContent
(
portal_type
=
portal_type
,
file
=
upload_file
)
# if PDF size is larger than A4 format system should deny conversion
...
...
@@ -2426,7 +2433,7 @@ return 1
# raster -> svg image should deny conversion if image width or height > 128 px
portal_type
=
'Image'
module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
upload_file
=
makeFileUpload
(
'TEST-en-002.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.jpg'
)
image
=
module
.
newContent
(
portal_type
=
portal_type
,
file
=
upload_file
)
self
.
assertRaises
(
Unauthorized
,
image
.
convert
,
format
=
'svg'
)
...
...
@@ -2436,7 +2443,7 @@ return 1
return a default (i.e. indicating a conversion failures)
"""
doc
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Presentation'
)
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
)
doc
.
edit
(
file
=
upload_file
)
doc
.
publish
()
self
.
tic
()
...
...
@@ -2564,7 +2571,7 @@ return 1
Test various cases of contributing to an existing document
"""
# contribute a document, then make it not editable and check we can not contribute to it
upload_file
=
makeFileUpload
(
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
self
.
tic
()
...
...
@@ -2589,12 +2596,12 @@ return 1
"""
# contribute a document, then make it not editable and check we can not contribute to it
kw
=
dict
(
synchronous_metadata_discovery
=
True
)
upload_file
=
makeFileUpload
(
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
self
.
tic
()
upload_file
=
makeFileUpload
(
'TEST-en-003.odp'
,
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-003.odp'
,
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
self
.
tic
()
...
...
@@ -2628,7 +2635,7 @@ return 1
def
test_base_convertable_uses_pdata_for_base_data
(
self
):
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
,
file
=
makeFileUpload
(
'import_big_spreadsheet.ods'
))
file
=
self
.
makeFileUpload
(
'import_big_spreadsheet.ods'
))
self
.
tic
()
# for large documents base_data is stored as Pdata
self
.
assertIsInstance
(
document
.
base_data
,
Pdata
)
...
...
@@ -2638,7 +2645,7 @@ return 1
# for small documents, it's bytes directly
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Text'
,
file
=
makeFileUpload
(
'TEST-en-002.odt'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002.odt'
))
self
.
tic
()
self
.
assertIsInstance
(
document
.
base_data
,
bytes
)
self
.
assertIsInstance
(
document
.
getBaseData
(),
bytes
)
...
...
@@ -2650,7 +2657,7 @@ return 1
When cloning a document base_data must not be computed once again.
"""
# create a document
upload_file
=
makeFileUpload
(
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
self
.
tic
()
...
...
@@ -2668,7 +2675,7 @@ return 1
# Update document with another content by using setData:
# base_data must be recomputed
document
.
edit
(
data
=
makeFileUpload
(
'TEST-en-002.odt'
).
read
())
document
.
edit
(
data
=
self
.
makeFileUpload
(
'TEST-en-002.odt'
).
read
())
self
.
tic
()
self
.
assertTrue
(
document
.
hasBaseData
())
self
.
assertNotEqual
(
previous_base_data
,
document
.
getBaseData
(),
...
...
@@ -2680,7 +2687,7 @@ return 1
# Update document with another content by using setFile:
# base_data must be recomputed
document
.
edit
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
))
document
.
edit
(
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
))
self
.
tic
()
self
.
assertTrue
(
document
.
hasBaseData
())
self
.
assertNotEqual
(
previous_base_data
,
document
.
getBaseData
(),
...
...
@@ -2701,7 +2708,7 @@ return 1
back to empty state
"""
# create a document
upload_file
=
makeFileUpload
(
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
self
.
tic
()
...
...
@@ -2849,7 +2856,7 @@ return 1
""" Test "visible" instances of a doc are auto archived when a new
instance is made "visible" except when they have a future effective date.
"""
upload_file
=
makeFileUpload
(
'TEST-en-002.doc'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
)
document_002
=
self
.
portal
.
Base_contribute
(
**
kw
)
document_002
.
publish
()
...
...
@@ -2908,7 +2915,7 @@ return 1
self
.
tic
()
def
testFileWithNotDefinedMimeType
(
self
):
upload_file
=
makeFileUpload
(
'TEST-001-en.dummy'
)
upload_file
=
self
.
makeFileUpload
(
'TEST-001-en.dummy'
)
kw
=
dict
(
file
=
upload_file
,
synchronous_metadata_discovery
=
True
,
portal_type
=
'File'
)
document
=
self
.
portal
.
Base_contribute
(
**
kw
)
...
...
@@ -2925,7 +2932,7 @@ return 1
Checks Base_getRelatedDocumentList works correctly with both
related (follow_up) Documents and with sub-object Embedded Files
"""
uploaded_file
=
makeFileUpload
(
'TEST-001-en.dummy'
)
uploaded_file
=
self
.
makeFileUpload
(
'TEST-001-en.dummy'
)
document_value
=
self
.
portal
.
Base_contribute
(
file
=
uploaded_file
,
synchronous_metadata_discovery
=
True
,
...
...
@@ -2976,7 +2983,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Make sure that uploader can preview document after submitted.
"""
filename
=
'REF-en-001.odt'
upload_file
=
makeFileUpload
(
filename
)
upload_file
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
upload_file
)
self
.
tic
()
...
...
@@ -2999,9 +3006,8 @@ class TestDocumentWithSecurity(TestDocumentMixin):
text_document
=
document_module
.
newContent
(
portal_type
=
portal_type
,
reference
=
'Foo_001'
,
title
=
'Foo_OO1'
)
f
=
makeFileUpload
(
'Foo_001.odt'
)
f
=
self
.
makeFileUpload
(
'Foo_001.odt'
)
text_document
.
edit
(
file
=
f
)
f
.
close
()
self
.
tic
()
# the document should be automatically converted to html
...
...
@@ -3071,14 +3077,14 @@ class TestDocumentWithSecurity(TestDocumentMixin):
def
test_mergeRevision
(
self
):
document1
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
))
self
.
tic
()
self
.
assertEqual
(
(
document1
.
getReference
(),
document1
.
getLanguage
(),
document1
.
getVersion
()),
(
'TEST'
,
'en'
,
'002'
))
self
.
assertNotIn
(
'This document is modified'
,
document1
.
asText
())
document2
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002-modified.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002-modified.doc'
))
self
.
tic
()
self
.
assertIn
(
'This document is modified'
,
document2
.
asText
())
self
.
assertEqual
(
...
...
@@ -3097,7 +3103,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
with
self
.
assertRaisesRegex
(
Unauthorized
,
"You are not allowed to update the existing document"
):
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
))
self
.
portal
.
portal_contributions
.
newContent
(
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
))
# this also works with another user which can not see the document
another_user_id
=
self
.
id
()
...
...
@@ -3107,7 +3113,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
with
self
.
assertRaisesRegex
(
Unauthorized
,
"You are not allowed to update the existing document"
):
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
))
self
.
portal
.
portal_contributions
.
newContent
(
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
))
def
test_mergeRevision_with_node_reference_local_reference_filename_regular_expression
(
self
):
# this filename regular expression comes from configurator
...
...
@@ -3116,14 +3122,14 @@ class TestDocumentWithSecurity(TestDocumentMixin):
)
self
.
tic
()
document1
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
self
.
tic
()
self
.
assertEqual
(
(
document1
.
getReference
(),
document1
.
getLanguage
(),
document1
.
getVersion
()),
(
'P-PROJ-TEST'
,
'en'
,
'002'
))
self
.
assertNotIn
(
'This document is modified'
,
document1
.
asText
())
document2
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002-modified.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002-modified.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
self
.
tic
()
self
.
assertIn
(
'This document is modified'
,
document2
.
asText
())
self
.
assertEqual
(
...
...
@@ -3143,7 +3149,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Unauthorized
,
"You are not allowed to update the existing document"
):
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
# this also works with another user which can not see the document
another_user_id
=
self
.
id
()
...
...
@@ -3154,7 +3160,7 @@ class TestDocumentWithSecurity(TestDocumentMixin):
Unauthorized
,
"You are not allowed to update the existing document"
):
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
file
=
self
.
makeFileUpload
(
'TEST-en-002.doc'
,
as_name
=
'P-PROJ-TEST-002-en.doc'
))
class
TestDocumentPerformance
(
TestDocumentMixin
):
...
...
@@ -3164,7 +3170,7 @@ class TestDocumentPerformance(TestDocumentMixin):
Test large OOoDocument to image conversion
"""
ooo_document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Spreadsheet'
)
upload_file
=
makeFileUpload
(
'import_big_spreadsheet.ods'
)
upload_file
=
self
.
makeFileUpload
(
'import_big_spreadsheet.ods'
)
ooo_document
.
edit
(
file
=
upload_file
)
self
.
tic
()
before
=
time
.
time
()
...
...
@@ -3183,7 +3189,7 @@ class TestDocumentPerformance(TestDocumentMixin):
req_time
)
class
DocumentConsistencyTestCase
(
ERP5Type
TestCase
):
class
DocumentConsistencyTestCase
(
DocumentUpload
TestCase
):
portal_type
=
NotImplemented
content_type
=
NotImplemented
filename
=
NotImplemented
...
...
@@ -3193,7 +3199,7 @@ class DocumentConsistencyTestCase(ERP5TypeTestCase):
def
afterSetUp
(
self
):
self
.
document
=
self
.
_getDocumentModule
().
newContent
(
portal_type
=
self
.
portal_type
)
self
.
file_upload
=
makeFileUpload
(
self
.
filename
)
self
.
file_upload
=
self
.
makeFileUpload
(
self
.
filename
)
with
open
(
makeFilePath
(
self
.
filename
),
'rb'
)
as
f
:
self
.
file_data
=
f
.
read
()
self
.
file_size
=
len
(
self
.
file_data
)
...
...
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testOOoConversionCache.py
View file @
5afebc71
...
...
@@ -31,7 +31,7 @@
import
unittest
from
DateTime
import
DateTime
from
erp5.component.test.testDms
import
TestDocumentMixin
,
makeFileUpload
from
erp5.component.test.testDms
import
TestDocumentMixin
try
:
import
magic
...
...
@@ -59,7 +59,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
def
test_image_conversion
(
self
):
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
format_
=
'png'
...
...
@@ -96,7 +96,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Test Conversion Cache mechanism
"""
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
document_url
=
document
.
getRelativeUrl
()
...
...
@@ -129,7 +129,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
def
test_02_VolatileCacheConversionOfTempObject
(
self
):
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
,
temp_object
=
1
)
document
.
uploadFile
()
document
.
processFile
()
...
...
@@ -163,8 +163,8 @@ class TestDocumentConversionCache(TestDocumentMixin):
def
test_03_CacheConversionOfTempObjectIsNotMixed
(
self
):
filename1
=
'TEST-en-002.doc'
filename2
=
'TEST-en-002.odt'
file1
=
makeFileUpload
(
filename1
)
file2
=
makeFileUpload
(
filename2
)
file1
=
self
.
makeFileUpload
(
filename1
)
file2
=
self
.
makeFileUpload
(
filename2
)
document1
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file1
,
temp_object
=
1
)
document1
.
uploadFile
()
document1
.
processFile
()
...
...
@@ -187,7 +187,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self
.
portal
.
portal_caches
.
clearAllCache
()
self
.
tic
()
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
document_url
=
document
.
getRelativeUrl
()
...
...
@@ -223,7 +223,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Test Conversion Cache return expected value with checksum
"""
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
document_url
=
document
.
getRelativeUrl
()
...
...
@@ -252,7 +252,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
Check that md5 checksum is well updated when upload a file
"""
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
self
.
tic
()
document_url
=
document
.
getRelativeUrl
()
...
...
@@ -260,7 +260,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
md5sum
=
document
.
getContentMd5
()
self
.
assertTrue
(
md5sum
)
filename2
=
'TEST-en-002.odt'
file2
=
makeFileUpload
(
filename2
)
file2
=
self
.
makeFileUpload
(
filename2
)
document
.
edit
(
file
=
file2
)
self
.
assertNotEqual
(
md5sum
,
document
.
getContentMd5
())
self
.
tic
()
...
...
@@ -275,7 +275,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self
.
portal
.
portal_caches
.
clearAllCache
()
self
.
tic
()
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document_id
=
'an id with spaces'
portal_type
=
'Text'
module
=
self
.
portal
.
getDefaultModule
(
portal_type
)
...
...
@@ -314,7 +314,7 @@ class TestDocumentConversionCache(TestDocumentMixin):
self
.
assertEqual
(
len
(
portal_type_list
),
len
([
pt
for
pt
in
portal_type_list
if
pt
in
data_mapping
]))
for
portal_type
in
portal_type_list
:
module
=
self
.
portal
.
getDefaultModule
(
portal_type
=
portal_type
)
upload_file
=
makeFileUpload
(
data_mapping
[
portal_type
])
upload_file
=
self
.
makeFileUpload
(
data_mapping
[
portal_type
])
document
=
module
.
newContent
(
portal_type
=
portal_type
)
document
.
edit
(
file
=
upload_file
)
self
.
tic
()
...
...
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testOOoConversionServerRetry.py
View file @
5afebc71
...
...
@@ -25,12 +25,11 @@
#
##############################################################################
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.test.testDms
import
makeFileUpload
from
erp5.component.test.testDms
import
DocumentUploadTestCase
from
Products.ERP5Form.PreferenceTool
import
Priority
class
TestOOoConversionServerRetry
(
ERP5Type
TestCase
):
class
TestOOoConversionServerRetry
(
DocumentUpload
TestCase
):
def
getBusinessTemplateList
(
self
):
business_template_list
=
[
'erp5_core_proxy_field_legacy'
,
'erp5_jquery'
,
...
...
@@ -80,7 +79,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
self
.
tic
()
filename
=
'monochrome_sample.tiff'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'Text'
)
document
.
edit
(
file
=
file_
)
message
=
document
.
Document_tryToConvertToBaseFormat
()
...
...
@@ -95,7 +94,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
system_pref
.
setPreferredDocumentConversionServerUrlList
([
'https://broken.url'
])
self
.
tic
()
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
message
=
document
.
Document_tryToConvertToBaseFormat
()
...
...
@@ -110,7 +109,7 @@ class TestOOoConversionServerRetry(ERP5TypeTestCase):
system_pref
.
setPreferredOoodocServerTimeout
(
1
)
self
.
tic
()
filename
=
'TEST-en-002.doc'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
message
=
document
.
Document_tryToConvertToBaseFormat
()
...
...
bt5/erp5_dms_conversion_catalog/TestTemplateItem/portal_components/test.erp5.testDmsWithPreConversion.py
View file @
5afebc71
...
...
@@ -28,7 +28,7 @@
##############################################################################
import
unittest
from
erp5.component.test.testDms
import
TestDocument
,
makeFileUpload
from
erp5.component.test.testDms
import
TestDocument
class
TestDocumentWithPreConversion
(
TestDocument
):
"""
...
...
@@ -40,7 +40,7 @@ class TestDocumentWithPreConversion(TestDocument):
def
test_preConvertedReferencedImageInWebPageContent
(
self
):
# create an image
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'cmyk_sample.jpg'
)
image
=
self
.
portal
.
image_module
.
newContent
(
portal_type
=
'Image'
,
reference
=
'Embedded-XXX'
,
version
=
'001'
,
...
...
@@ -75,7 +75,7 @@ class TestDocumentWithPreConversion(TestDocument):
language
=
'en'
)
# draft image is not convertible
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
upload_file
=
self
.
makeFileUpload
(
'cmyk_sample.jpg'
)
image
.
edit
(
file
=
upload_file
)
self
.
tic
()
self
.
assertEqual
(
False
,
image
.
Base_isConvertible
())
...
...
bt5/erp5_km/TestTemplateItem/portal_components/test.erp5.testKM.py
View file @
5afebc71
...
...
@@ -31,7 +31,7 @@ import unittest
from
unittest
import
expectedFailure
from
AccessControl.SecurityManagement
import
newSecurityManager
from
Products.ERP5Type.Base
import
TempBase
from
erp5.component.test.testDms
import
makeFileUpload
,
TestDocumentMixin
from
erp5.component.test.testDms
import
TestDocumentMixin
def
_getGadgetInstanceUrlFromKnowledgePad
(
knowledge_pad
,
gadget
):
""" Get Knowledge Box's relative URL specialising a gadget in a Knowledge Pad."""
...
...
@@ -39,6 +39,7 @@ def _getGadgetInstanceUrlFromKnowledgePad(knowledge_pad, gadget):
portal_type
=
'Knowledge Box'
,
specialise_uid
=
gadget
.
getUid
())[
0
].
getObject
().
getRelativeUrl
()
class
TestKMMixIn
(
TestDocumentMixin
):
"""
Mix in class for Knowledge Management system.
...
...
@@ -1008,38 +1009,38 @@ class TestKMSearch(TestKMMixIn):
# create docs to be referenced:
# (1) TEST, 002, en
filename
=
'TEST-en-002.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# (2) TEST, 002, fr
as_name
=
'TEST-fr-002.odt'
file_
=
makeFileUpload
(
filename
,
as_name
)
file_
=
self
.
makeFileUpload
(
filename
,
as_name
)
document2
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# (3) TEST, 003, en
as_name
=
'TEST-en-003.odt'
file_
=
makeFileUpload
(
filename
,
as_name
)
file_
=
self
.
makeFileUpload
(
filename
,
as_name
)
document3
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# create docs to contain references in text_content:
# REF, 002, en; "I use reference to look up TEST"
filename
=
'REF-en-002.odt'
file_
=
makeFileUpload
(
filename
)
file_
=
self
.
makeFileUpload
(
filename
)
document5
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
file_
)
# REFLANG, 001, en: "I use reference and language to look up TEST-fr"
#filename = 'REFLANG-en-001.odt'
#file = makeFileUpload(filename)
#file =
self.
makeFileUpload(filename)
#document6 = self.portal.portal_contributions.newContent(file=file)
# REFVER, 001, en: "I use reference and version to look up TEST-002"
#filename = 'REFVER-en-001.odt'
#file = makeFileUpload(filename)
#file =
self.
makeFileUpload(filename)
#document7 = self.portal.portal_contributions.newContent(file=file)
# REFVERLANG, 001, en: "I use reference, version and language to look up TEST-002-en"
#filename = 'REFVERLANG-en-001.odt'
#file = makeFileUpload(filename)
#file =
self.
makeFileUpload(filename)
#document8 = self.portal.portal_contributions.newContent(file=file)
self
.
tic
()
...
...
bt5/erp5_pdf_merge/TestTemplateItem/portal_components/test.erp5.testERP5PDFMerge.py
View file @
5afebc71
...
...
@@ -26,11 +26,11 @@
##############################################################################
import
warnings
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.test.testDms
import
makeFileUpload
from
erp5.component.test.testDms
import
DocumentUploadTestCase
from
Products.ERP5Type
import
Utils
class
TestERP5PDFMerge
(
ERP5TypeTestCase
):
class
TestERP5PDFMerge
(
DocumentUploadTestCase
):
def
test_showwarning_issue
(
self
):
"""
...
...
@@ -39,7 +39,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
"""
self
.
assertEqual
(
Utils
.
_showwarning
,
warnings
.
showwarning
)
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'REF-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
))
merged_pdf_data
=
self
.
portal
.
ERP5Site_mergePDFList
(
[
document
.
getData
(),
document
.
getData
()])
self
.
portal
.
document_module
.
newContent
(
...
...
@@ -50,7 +50,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
def
test_erp5_merge_pdf
(
self
):
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'REF-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
))
merged_pdf_data
=
self
.
portal
.
ERP5Site_mergePDFList
(
[
document
.
getData
(),
document
.
getData
()])
merged_document
=
self
.
portal
.
document_module
.
newContent
(
...
...
@@ -60,7 +60,7 @@ class TestERP5PDFMerge(ERP5TypeTestCase):
def
test_erp5_merge_pdf_start_on_recto
(
self
):
document
=
self
.
portal
.
portal_contributions
.
newContent
(
file
=
makeFileUpload
(
'REF-en-001.pdf'
))
file
=
self
.
makeFileUpload
(
'REF-en-001.pdf'
))
merged_pdf_data
=
self
.
portal
.
ERP5Site_mergePDFList
(
[
document
.
getData
(),
document
.
getData
()],
start_on_recto
=
True
)
merged_document
=
self
.
portal
.
document_module
.
newContent
(
...
...
bt5/erp5_run_my_doc/TestTemplateItem/portal_components/test.erp5.testRunMyDoc.py
View file @
5afebc71
...
...
@@ -26,12 +26,12 @@
#
##############################################################################
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.test.testDms
import
makeFileUpload
from
erp5.component.test.testDms
import
DocumentUploadTestCase
from
time
import
time
import
base64
class
TestRunMyDoc
(
ERP5TypeTestCase
):
class
TestRunMyDoc
(
DocumentUploadTestCase
):
"""
Basic Test for internal implementation of RunMyDocs
"""
...
...
@@ -96,7 +96,7 @@ class TestRunMyDoc(ERP5TypeTestCase):
Test Screeshot upload script used by Zelenium to
update screenshots of the documents.
"""
image_upload
=
makeFileUpload
(
'TEST-en-002.png'
)
image_upload
=
self
.
makeFileUpload
(
'TEST-en-002.png'
)
self
.
assertNotEqual
(
None
,
image_upload
)
# Create a web page, and check if the content is not overwriten
...
...
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