Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
cloudooo
Commits
b2bf7ce9
Commit
b2bf7ce9
authored
Apr 11, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: trivial code modernisation
using 2to3 -f asserts -f except and a few manual changes
parent
a09d87af
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
287 additions
and
287 deletions
+287
-287
cloudooo/bin/cloudooo_tester.py
cloudooo/bin/cloudooo_tester.py
+8
-8
cloudooo/handler/ffmpeg/tests/testFfmpegHandler.py
cloudooo/handler/ffmpeg/tests/testFfmpegHandler.py
+5
-5
cloudooo/handler/ffmpeg/tests/testFfmpegInterface.py
cloudooo/handler/ffmpeg/tests/testFfmpegInterface.py
+3
-3
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
+4
-4
cloudooo/handler/ooo/granulator.py
cloudooo/handler/ooo/granulator.py
+1
-1
cloudooo/handler/ooo/tests/testOooAllFormatERP5Compatibility.py
...oo/handler/ooo/tests/testOooAllFormatERP5Compatibility.py
+1
-1
cloudooo/handler/ooo/tests/testOooApplication.py
cloudooo/handler/ooo/tests/testOooApplication.py
+7
-7
cloudooo/handler/ooo/tests/testOooFileSystemDocument.py
cloudooo/handler/ooo/tests/testOooFileSystemDocument.py
+18
-18
cloudooo/handler/ooo/tests/testOooFilter.py
cloudooo/handler/ooo/tests/testOooFilter.py
+4
-4
cloudooo/handler/ooo/tests/testOooGranulator.py
cloudooo/handler/ooo/tests/testOooGranulator.py
+21
-21
cloudooo/handler/ooo/tests/testOooHandler.py
cloudooo/handler/ooo/tests/testOooHandler.py
+40
-40
cloudooo/handler/ooo/tests/testOooLegacyInterface.py
cloudooo/handler/ooo/tests/testOooLegacyInterface.py
+4
-4
cloudooo/handler/ooo/tests/testOooMimemapper.py
cloudooo/handler/ooo/tests/testOooMimemapper.py
+23
-23
cloudooo/handler/ooo/tests/testOooMonitorInit.py
cloudooo/handler/ooo/tests/testOooMonitorInit.py
+5
-5
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
+4
-4
cloudooo/handler/ooo/tests/testOooMonitorRequest.py
cloudooo/handler/ooo/tests/testOooMonitorRequest.py
+3
-3
cloudooo/handler/ooo/tests/testOooMonitorTimeout.py
cloudooo/handler/ooo/tests/testOooMonitorTimeout.py
+5
-5
cloudooo/handler/ooo/tests/testOooOdfDocument.py
cloudooo/handler/ooo/tests/testOooOdfDocument.py
+2
-2
cloudooo/handler/ooo/tests/testOooOpenOffice.py
cloudooo/handler/ooo/tests/testOooOpenOffice.py
+7
-7
cloudooo/handler/ooo/tests/testOooServer.py
cloudooo/handler/ooo/tests/testOooServer.py
+56
-56
cloudooo/handler/ooo/tests/testOooUnoConverter.py
cloudooo/handler/ooo/tests/testOooUnoConverter.py
+3
-3
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
+13
-13
cloudooo/handler/ooo/tests/testOooUtil.py
cloudooo/handler/ooo/tests/testOooUtil.py
+4
-4
cloudooo/handler/ooo/util.py
cloudooo/handler/ooo/util.py
+5
-5
cloudooo/handler/pdf/tests/testPdfHandler.py
cloudooo/handler/pdf/tests/testPdfHandler.py
+8
-8
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
+3
-3
cloudooo/handler/x2t/tests/testX2tHandler.py
cloudooo/handler/x2t/tests/testX2tHandler.py
+6
-6
cloudooo/manager.py
cloudooo/manager.py
+5
-5
cloudooo/tests/backportUnittest.py
cloudooo/tests/backportUnittest.py
+7
-7
cloudooo/tests/cloudoooTestCase.py
cloudooo/tests/cloudoooTestCase.py
+11
-11
cloudooo/tests/runTestSuite.py
cloudooo/tests/runTestSuite.py
+1
-1
No files found.
cloudooo/bin/cloudooo_tester.py
View file @
b2bf7ce9
...
...
@@ -21,30 +21,30 @@ class CloudoooTestCase(unittest.TestCase):
data
=
encodestring
(
DOCUMENT_STRING
)
proxy
=
ServerProxy
(
self
.
proxy_address
,
allow_none
=
True
)
res
=
proxy
.
run_generate
(
"t.text"
,
data
,
None
,
'pdf'
,
'text/plain'
)
self
.
assertEqual
s
(
res
[
1
][
'mime'
],
"application/pdf"
)
self
.
assertEqual
s
(
res
[
0
],
200
)
self
.
assertEqual
(
res
[
1
][
'mime'
],
"application/pdf"
)
self
.
assertEqual
(
res
[
0
],
200
)
def
test_set_metadata
(
self
):
data
=
encodestring
(
DOCUMENT_STRING
)
proxy
=
ServerProxy
(
self
.
proxy_address
,
allow_none
=
True
)
odt_data
=
proxy
.
convertFile
(
data
,
'txt'
,
'odt'
)
metadata_dict
=
proxy
.
getFileMetadataItemList
(
odt_data
,
'odt'
)
self
.
assertEqual
s
(
metadata_dict
[
"MIMEType"
],
self
.
assertEqual
(
metadata_dict
[
"MIMEType"
],
'application/vnd.oasis.opendocument.text'
)
res
=
proxy
.
run_setmetadata
(
"t.odt"
,
odt_data
,
{
"Title"
:
"test"
})
self
.
assertEqual
s
(
res
[
0
],
200
)
self
.
assertEqual
(
res
[
0
],
200
)
response_code
,
response_dict
,
response_message
=
\
proxy
.
run_convert
(
"t.odt"
,
res
[
1
][
'data'
])
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
response_dict
[
'meta'
][
'Title'
],
"test"
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
response_dict
[
'meta'
][
'Title'
],
"test"
)
def
main
():
global
PORT
,
HOSTNAME
try
:
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
""
,
opt_list
,
_
=
getopt
(
sys
.
argv
[
1
:],
""
,
[
"port="
,
"hostname="
])
except
GetoptError
,
e
:
except
GetoptError
as
e
:
print
>>
sys
.
stderr
,
"%s
\
n
Use --port and --hostname"
%
e
sys
.
exit
(
2
)
...
...
cloudooo/handler/ffmpeg/tests/testFfmpegHandler.py
View file @
b2bf7ce9
...
...
@@ -45,12 +45,12 @@ class TestHandler(HandlerTestCase):
"""Test coversion of video to another format"""
output_data
=
self
.
input
.
convert
(
"mpeg"
)
file_format
=
self
.
file_detector
.
from_buffer
(
output_data
)
self
.
assertEqual
s
(
file_format
,
'video/mpeg'
)
self
.
assertEqual
(
file_format
,
'video/mpeg'
)
def
testgetMetadata
(
self
):
"""Test if metadata is extracted from"""
output_metadata
=
self
.
input
.
getMetadata
()
self
.
assertEqual
s
(
output_metadata
,
{
'Encoder'
:
'Lavf52.64.2'
})
self
.
assertEqual
(
output_metadata
,
{
'Encoder'
:
'Lavf52.64.2'
})
def
testsetMetadata
(
self
):
""" Test if metadata are inserted correclty """
...
...
@@ -58,8 +58,8 @@ class TestHandler(HandlerTestCase):
output
=
self
.
input
.
setMetadata
(
metadata_dict
)
handler
=
Handler
(
self
.
tmp_url
,
output
,
"ogv"
,
**
self
.
kw
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
[
"Title"
],
"Set Metadata Test"
)
self
.
assertEqual
s
(
metadata
[
"Creator"
],
"cloudooo"
)
self
.
assertEqual
(
metadata
[
"Title"
],
"Set Metadata Test"
)
self
.
assertEqual
(
metadata
[
"Creator"
],
"cloudooo"
)
def
testConvertAudio
(
self
):
"""Test coversion of audio to another format"""
...
...
@@ -68,6 +68,6 @@ class TestHandler(HandlerTestCase):
output_data
=
self
.
input
.
convert
(
"wav"
)
file_format
=
self
.
file_detector
.
from_buffer
(
output_data
)
# XXX this might expect 'audio/vnd.wave' but magic only got 'audio/x-wav'
self
.
assertEqual
s
(
file_format
,
'audio/x-wav'
)
self
.
assertEqual
(
file_format
,
'audio/x-wav'
)
cloudooo/handler/ffmpeg/tests/testFfmpegInterface.py
View file @
b2bf7ce9
...
...
@@ -39,10 +39,10 @@ class TestInterface(unittest.TestCase):
def
testIHandler
(
self
):
"""Test if Handlers implements IHandler"""
self
.
assertTrue
(
IHandler
.
implementedBy
(
Handler
))
self
.
assertEqual
s
(
IHandler
.
get
(
'convert'
).
required
,
(
'destination_format'
,))
self
.
assertEqual
s
(
IHandler
.
get
(
'getMetadata'
).
required
,
self
.
assertEqual
(
IHandler
.
get
(
'convert'
).
required
,
(
'destination_format'
,))
self
.
assertEqual
(
IHandler
.
get
(
'getMetadata'
).
required
,
(
'converted_data'
,))
self
.
assertEqual
s
(
IHandler
.
get
(
'setMetadata'
).
required
,
self
.
assertEqual
(
IHandler
.
get
(
'setMetadata'
).
required
,
(
'metadata_dict'
,))
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
View file @
b2bf7ce9
...
...
@@ -46,16 +46,16 @@ class TestHandler(HandlerTestCase):
jpg_file
=
handler
.
convert
(
"jpg"
)
mime
=
magic
.
Magic
(
mime
=
True
)
jpg_mimetype
=
mime
.
from_buffer
(
jpg_file
)
self
.
assertEqual
s
(
"image/jpeg"
,
jpg_mimetype
)
self
.
assertEqual
(
"image/jpeg"
,
jpg_mimetype
)
def
testgetMetadataFromImage
(
self
):
"""Test if metadata is extracted from image correctly"""
png_file
=
open
(
"data/test.png"
).
read
()
handler
=
Handler
(
self
.
tmp_url
,
png_file
,
"png"
,
**
self
.
kw
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
"Compression"
),
"Zip"
)
self
.
assertEqual
s
(
metadata
.
get
(
"Colorspace"
),
"sRGB"
)
self
.
assertEqual
s
(
metadata
.
get
(
"Alpha color"
),
"grey74"
)
self
.
assertEqual
(
metadata
.
get
(
"Compression"
),
"Zip"
)
self
.
assertEqual
(
metadata
.
get
(
"Colorspace"
),
"sRGB"
)
self
.
assertEqual
(
metadata
.
get
(
"Alpha color"
),
"grey74"
)
def
testsetMetadata
(
self
):
""" Test if metadata are inserted correclty """
...
...
cloudooo/handler/ooo/granulator.py
View file @
b2bf7ce9
...
...
@@ -126,7 +126,7 @@ class OOGranulator(object):
odf_document
.
close
()
odf_document_as_string
.
seek
(
0
)
return
odf_document_as_string
.
read
()
except
Exception
,
e
:
except
Exception
as
e
:
logger
.
error
(
e
)
return
None
...
...
cloudooo/handler/ooo/tests/testOooAllFormatERP5Compatibility.py
View file @
b2bf7ce9
...
...
@@ -70,7 +70,7 @@ class TestAllFormatsERP5Compatibility(TestCase):
file_type
=
self
.
_getFileType
(
data_output
)
if
file_type
.
endswith
(
": empty"
):
fault_list
.
append
((
source_format
,
extension
,
file_type
))
except
Fault
,
err
:
except
Fault
as
err
:
fault_list
.
append
((
source_format
,
extension
,
err
.
faultString
))
if
fault_list
:
template_message
=
'input_format: %r
\
n
output_format: %r
\
n
traceback:
\
n
%s'
...
...
cloudooo/handler/ooo/tests/testOooApplication.py
View file @
b2bf7ce9
...
...
@@ -41,23 +41,23 @@ class TestApplication(unittest.TestCase):
def
testLoadSettings
(
self
):
"""Test if settings are defined correctly"""
self
.
assertEqual
s
(
self
.
application
.
hostname
,
'localhost'
)
self
.
assertEqual
s
(
self
.
application
.
port
,
9999
)
self
.
assertEqual
s
(
self
.
application
.
path_run_dir
,
'/tmp/'
)
self
.
assertEqual
(
self
.
application
.
hostname
,
'localhost'
)
self
.
assertEqual
(
self
.
application
.
port
,
9999
)
self
.
assertEqual
(
self
.
application
.
path_run_dir
,
'/tmp/'
)
def
testStartTimeout
(
self
):
"""Test if the attribute timeout is defined correctly"""
self
.
assertEqual
s
(
self
.
application
.
timeout
,
20
)
self
.
assertEqual
(
self
.
application
.
timeout
,
20
)
application
=
Application
()
application
.
loadSettings
(
'localhost'
,
9999
,
'/'
,
start_timeout
=
25
)
self
.
assertEqual
s
(
application
.
timeout
,
25
)
self
.
assertEqual
(
application
.
timeout
,
25
)
def
testgetAddress
(
self
):
"""Test if getAddress() returns tuple with address correctly """
self
.
assertEqual
s
(
self
.
application
.
getAddress
(),
(
'localhost'
,
9999
))
self
.
assertEqual
(
self
.
application
.
getAddress
(),
(
'localhost'
,
9999
))
def
testPid
(
self
):
"""As the application do not have the pid() should return None"""
self
.
assertEqual
s
(
self
.
application
.
pid
(),
None
)
self
.
assertEqual
(
self
.
application
.
pid
(),
None
)
cloudooo/handler/ooo/tests/testOooFileSystemDocument.py
View file @
b2bf7ce9
...
...
@@ -60,19 +60,19 @@ class TestFileSystemDocument(unittest.TestCase):
document_filename
)
open
(
document_test_url
,
'wb'
).
write
(
decodestring
(
"Test Document"
))
self
.
fsdocument
.
reload
(
document_test_url
)
self
.
assertEqual
s
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertNotEqual
s
(
self
.
fsdocument
.
original_data
,
self
.
assertEqual
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertNotEqual
(
self
.
fsdocument
.
original_data
,
self
.
fsdocument
.
getContent
())
old_document_url
=
self
.
fsdocument
.
getUrl
()
self
.
fsdocument
.
restoreOriginal
()
self
.
assertEqual
s
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertNotEqual
s
(
old_document_url
,
self
.
fsdocument
.
getUrl
())
self
.
assertEqual
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertNotEqual
(
old_document_url
,
self
.
fsdocument
.
getUrl
())
self
.
assertTrue
(
path
.
exists
(
self
.
fsdocument
.
getUrl
()))
self
.
assertEqual
s
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
self
.
assertEqual
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
def
testgetContent
(
self
):
"""Test if returns the data correctly"""
self
.
assertEqual
s
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
self
.
assertEqual
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
def
testgetUrl
(
self
):
"""Check if the url is correct"""
...
...
@@ -83,9 +83,9 @@ class TestFileSystemDocument(unittest.TestCase):
"""Test if the document is created correctly"""
url
=
self
.
fsdocument
.
getUrl
()
tmp_document
=
open
(
url
,
'r'
).
read
()
self
.
assertEqual
s
(
self
.
data
,
tmp_document
)
self
.
assertEqual
(
self
.
data
,
tmp_document
)
self
.
fsdocument
.
trash
()
self
.
assertEqual
s
(
path
.
exists
(
url
),
False
)
self
.
assertEqual
(
path
.
exists
(
url
),
False
)
def
testReload
(
self
):
"""Change url and check if occurs correctly"""
...
...
@@ -96,10 +96,10 @@ class TestFileSystemDocument(unittest.TestCase):
open
(
document_test_url
,
'wb'
).
write
(
self
.
data
)
self
.
fsdocument
.
reload
(
document_test_url
)
url
=
self
.
fsdocument
.
getUrl
()
self
.
assertEqual
s
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertEqual
s
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
self
.
assertEqual
(
path
.
exists
(
old_document_url
),
False
)
self
.
assertEqual
(
self
.
fsdocument
.
getContent
(),
self
.
data
)
self
.
fsdocument
.
trash
()
self
.
assertEqual
s
(
path
.
exists
(
url
),
False
)
self
.
assertEqual
(
path
.
exists
(
url
),
False
)
def
testZipDocumentList
(
self
):
"""Tests if the zip file is returned correctly"""
...
...
@@ -107,14 +107,14 @@ class TestFileSystemDocument(unittest.TestCase):
zip_file
=
self
.
fsdocument
.
getContent
(
True
)
mime
=
magic
.
Magic
(
mime
=
True
)
mimetype
=
mime
.
from_buffer
(
zip_file
)
self
.
assertEqual
s
(
mimetype
,
'application/zip'
)
self
.
assertEqual
(
mimetype
,
'application/zip'
)
ziptest
=
ZipFile
(
StringIO
(
zip_file
),
'r'
)
self
.
assertEqual
s
(
len
(
ziptest
.
filelist
),
2
)
self
.
assertEqual
(
len
(
ziptest
.
filelist
),
2
)
for
file
in
ziptest
.
filelist
:
if
file
.
filename
.
endswith
(
"document2"
):
self
.
assertEqual
s
(
file
.
file_size
,
4
)
self
.
assertEqual
(
file
.
file_size
,
4
)
else
:
self
.
assertEqual
s
(
file
.
file_size
,
9
)
self
.
assertEqual
(
file
.
file_size
,
9
)
def
testSendZipFile
(
self
):
"""Tests if the htm is extrated from zipfile"""
...
...
@@ -123,11 +123,11 @@ class TestFileSystemDocument(unittest.TestCase):
zipdocument
=
FileSystemDocument
(
self
.
tmp_url
,
data
,
'zip'
)
mime
=
magic
.
Magic
(
mime
=
True
)
mimetype
=
mime
.
from_buffer
(
zipdocument
.
getContent
(
True
))
self
.
assertEqual
s
(
mimetype
,
"application/zip"
)
self
.
assertEqual
(
mimetype
,
"application/zip"
)
mimetype
=
mime
.
from_buffer
(
zipdocument
.
getContent
())
self
.
assertEqual
s
(
mimetype
,
"text/html"
)
self
.
assertEqual
(
mimetype
,
"text/html"
)
zipfile
=
ZipFile
(
StringIO
(
zipdocument
.
getContent
(
True
)))
self
.
assertEqual
s
(
sorted
(
zipfile
.
namelist
()),
self
.
assertEqual
(
sorted
(
zipfile
.
namelist
()),
sorted
([
'logo.gif'
,
'test.htm'
]))
cloudooo/handler/ooo/tests/testOooFilter.py
View file @
b2bf7ce9
...
...
@@ -48,10 +48,10 @@ class TestFilter(unittest.TestCase):
def
testFilter
(
self
):
"""Tests filter gets"""
self
.
assertEqual
s
(
self
.
filter
.
getExtension
(),
'pdf'
)
self
.
assertEqual
s
(
self
.
filter
.
getName
(),
'writer_pdf_Export'
)
self
.
assertEqual
s
(
self
.
filter
.
getMimetype
(),
'application/pdf'
)
self
.
assertEqual
s
(
self
.
filter
.
getSortIndex
(),
1000
)
self
.
assertEqual
(
self
.
filter
.
getExtension
(),
'pdf'
)
self
.
assertEqual
(
self
.
filter
.
getName
(),
'writer_pdf_Export'
)
self
.
assertEqual
(
self
.
filter
.
getMimetype
(),
'application/pdf'
)
self
.
assertEqual
(
self
.
filter
.
getSortIndex
(),
1000
)
self
.
assertTrue
(
self
.
filter
.
isPreferred
())
cloudooo/handler/ooo/tests/testOooGranulator.py
View file @
b2bf7ce9
...
...
@@ -61,7 +61,7 @@ class TestOOGranulator(HandlerTestCase):
table_list
=
[(
'Developers'
,
''
),
(
'Prices'
,
'Table 1: Prices table from Mon Restaurant'
),
(
'SoccerTeams'
,
'Tabela 2: Soccer Teams'
)]
self
.
assertEqual
s
(
table_list
,
oogranulator
.
getTableItemList
())
self
.
assertEqual
(
table_list
,
oogranulator
.
getTableItemList
())
def
testGetTable
(
self
):
"""Test if getTable() returns on odf file with the right table"""
...
...
@@ -72,23 +72,23 @@ class TestOOGranulator(HandlerTestCase):
content_xml
=
etree
.
fromstring
(
content_xml_str
)
table_list
=
content_xml
.
xpath
(
'//table:table'
,
namespaces
=
content_xml
.
nsmap
)
self
.
assertEqual
s
(
1
,
len
(
table_list
))
self
.
assertEqual
(
1
,
len
(
table_list
))
table
=
table_list
[
0
]
name_key
=
'{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self
.
assertEqual
s
(
'Developers'
,
table
.
attrib
[
name_key
])
self
.
assertEqual
(
'Developers'
,
table
.
attrib
[
name_key
])
def
testGetTableItemWithoutSuccess
(
self
):
"""Test if getTable() returns None for an non existent table name"""
data
=
open
(
'./data/granulate_table_test.odt'
).
read
()
oogranulator
=
OOGranulator
(
data
,
'odt'
)
table_data
=
oogranulator
.
getTable
(
'NonExistentTable'
)
self
.
assertEqual
s
(
table_data
,
None
)
self
.
assertEqual
(
table_data
,
None
)
def
testGetColumnItemList
(
self
):
"""Test if getColumnItemList() returns the right table columns list"""
data
=
open
(
'./data/granulate_table_test.odt'
).
read
()
oogranulator
=
OOGranulator
(
data
,
'odt'
)
self
.
assertEqual
s
([[
0
,
'Name'
],
[
1
,
'Country'
]],
self
.
assertEqual
([[
0
,
'Name'
],
[
1
,
'Country'
]],
oogranulator
.
getColumnItemList
(
'SoccerTeams'
))
def
testGetLineItemList
(
self
):
...
...
@@ -98,20 +98,20 @@ class TestOOGranulator(HandlerTestCase):
matrix
=
[[
'Name'
,
'Phone'
,
'Email'
],
[
'Hugo'
,
'+55 (22) 8888-8888'
,
'hugomaia@tiolive.com'
],
[
'Rafael'
,
'+55 (22) 9999-9999'
,
'rafael@tiolive.com'
]]
self
.
assertEqual
s
(
matrix
,
oogranulator
.
getTableMatrix
(
'Developers'
))
self
.
assertEqual
(
matrix
,
oogranulator
.
getTableMatrix
(
'Developers'
))
matrix
=
[[
'Product'
,
'Price'
],
[
'Pizza'
,
'R$ 25,00'
],
[
'Petit Gateau'
,
'R$ 10,00'
],
[
'Feijoada'
,
'R$ 30,00'
]]
self
.
assertEqual
s
(
matrix
,
oogranulator
.
getTableMatrix
(
'Prices'
))
self
.
assertEqual
(
matrix
,
oogranulator
.
getTableMatrix
(
'Prices'
))
self
.
assertEqual
s
(
None
,
oogranulator
.
getTableMatrix
(
'Non existent'
))
self
.
assertEqual
(
None
,
oogranulator
.
getTableMatrix
(
'Non existent'
))
def
testGetImageItemList
(
self
):
"""Test if getImageItemList() returns the right images list"""
image_list
=
self
.
oogranulator
.
getImageItemList
()
self
.
assertEqual
s
([(
'10000000000000C80000009C38276C51.jpg'
,
''
),
self
.
assertEqual
([(
'10000000000000C80000009C38276C51.jpg'
,
''
),
(
'10000201000000C80000004E7B947D46.png'
,
'TioLive Logo'
),
(
'10000201000000C80000004E7B947D46.png'
,
''
),
# XXX The svg image are stored into odf as svm
...
...
@@ -126,12 +126,12 @@ class TestOOGranulator(HandlerTestCase):
image_id
=
'10000000000000C80000009C38276C51.jpg'
original_image
=
zip
.
read
(
'Pictures/%s'
%
image_id
)
geted_image
=
self
.
oogranulator
.
getImage
(
image_id
)
self
.
assertEqual
s
(
original_image
,
geted_image
)
self
.
assertEqual
(
original_image
,
geted_image
)
def
testGetImageWithoutSuccess
(
self
):
"""Test if getImage() returns an empty string for not existent id"""
obtained_image
=
self
.
oogranulator
.
getImage
(
'anything.png'
)
self
.
assertEqual
s
(
''
,
obtained_image
)
self
.
assertEqual
(
''
,
obtained_image
)
def
testGetParagraphItemList
(
self
):
"""Test if getParagraphItemList() returns the right paragraphs list, with
...
...
@@ -140,31 +140,31 @@ class TestOOGranulator(HandlerTestCase):
data
=
open
(
'./data/granulate_test.odt'
).
read
()
oogranulator
=
OOGranulator
(
data
,
'odt'
)
paragraph_list
=
oogranulator
.
getParagraphItemList
()
self
.
assertEqual
s
((
0
,
'P3'
),
paragraph_list
[
0
])
self
.
assertEqual
s
((
1
,
'P1'
),
paragraph_list
[
1
])
self
.
assertEqual
s
((
2
,
'P12'
),
paragraph_list
[
2
])
self
.
assertEqual
s
((
8
,
'P13'
),
paragraph_list
[
8
])
self
.
assertEqual
s
((
19
,
'Standard'
),
paragraph_list
[
19
])
self
.
assertEqual
((
0
,
'P3'
),
paragraph_list
[
0
])
self
.
assertEqual
((
1
,
'P1'
),
paragraph_list
[
1
])
self
.
assertEqual
((
2
,
'P12'
),
paragraph_list
[
2
])
self
.
assertEqual
((
8
,
'P13'
),
paragraph_list
[
8
])
self
.
assertEqual
((
19
,
'Standard'
),
paragraph_list
[
19
])
def
testGetParagraphItemSuccessfully
(
self
):
"""Test if getParagraphItem() returns the right paragraph"""
self
.
assertEqual
s
((
'Some images without title'
,
'P13'
),
self
.
assertEqual
((
'Some images without title'
,
'P13'
),
self
.
oogranulator
.
getParagraph
(
8
))
big_paragraph
=
self
.
oogranulator
.
getParagraph
(
5
)
self
.
assertEqual
s
(
'P8'
,
big_paragraph
[
1
])
self
.
assertEqual
(
'P8'
,
big_paragraph
[
1
])
self
.
assertTrue
(
big_paragraph
[
0
].
startswith
(
u'A prática cotidiana prova'
))
self
.
assertTrue
(
big_paragraph
[
0
].
endswith
(
u'corresponde às necessidades.'
))
def
testGetParagraphItemWithoutSuccess
(
self
):
"""Test if getParagraphItem() returns None for not existent id"""
self
.
assertEqual
s
(
None
,
self
.
oogranulator
.
getParagraph
(
200
))
self
.
assertEqual
(
None
,
self
.
oogranulator
.
getParagraph
(
200
))
def
testGetChapterItemList
(
self
):
"""Test if getChapterItemList() returns the right chapters list"""
data
=
open
(
'./data/granulate_chapters_test.odt'
).
read
()
oogranulator
=
OOGranulator
(
data
,
'odt'
)
self
.
assertEqual
s
([(
0
,
'Title 0'
),
(
1
,
'Title 1'
),
(
2
,
'Title 2'
),
self
.
assertEqual
([(
0
,
'Title 0'
),
(
1
,
'Title 1'
),
(
2
,
'Title 2'
),
(
3
,
'Title 3'
),
(
4
,
'Title 4'
),
(
5
,
'Title 5'
),
(
6
,
'Title 6'
),
(
7
,
'Title 7'
),
(
8
,
'Title 8'
),
(
9
,
'Title 9'
),
(
10
,
'Title 10'
)],
...
...
@@ -174,5 +174,5 @@ class TestOOGranulator(HandlerTestCase):
"""Test if getChapterItem() returns the right chapter"""
data
=
open
(
"./data/granulate_chapters_test.odt"
).
read
()
oogranulator
=
OOGranulator
(
data
,
'odt'
)
self
.
assertEqual
s
([
'Title 1'
,
1
],
oogranulator
.
getChapterItem
(
1
))
self
.
assertEqual
([
'Title 1'
,
1
],
oogranulator
.
getChapterItem
(
1
))
cloudooo/handler/ooo/tests/testOooHandler.py
View file @
b2bf7ce9
...
...
@@ -57,7 +57,7 @@ class TestHandler(HandlerTestCase):
"""Check if the document was created correctly"""
mime
=
magic
.
Magic
(
mime
=
True
)
mimetype
=
mime
.
from_buffer
(
document
)
self
.
assertEqual
s
(
mimetype
,
expected_mimetype
)
self
.
assertEqual
(
mimetype
,
expected_mimetype
)
def
tearDown
(
self
):
"""Cleanup temp files
...
...
@@ -94,11 +94,11 @@ class TestHandler(HandlerTestCase):
decodestring
(
data
),
'odt'
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
'MIMEType'
),
self
.
assertEqual
(
metadata
.
get
(
'MIMEType'
),
'application/vnd.oasis.opendocument.text'
)
handler
.
document
.
restoreOriginal
()
metadata
=
handler
.
getMetadata
(
True
)
self
.
assertNotEqual
s
(
metadata
.
get
(
'Data'
),
''
)
self
.
assertNotEqual
(
metadata
.
get
(
'Data'
),
''
)
def
testSetMetadata
(
self
):
"""Test setMetadata"""
...
...
@@ -111,7 +111,7 @@ class TestHandler(HandlerTestCase):
new_data
,
'odt'
)
metadata
=
new_handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
'Title'
),
"cloudooo Test -"
)
self
.
assertEqual
(
metadata
.
get
(
'Title'
),
"cloudooo Test -"
)
handler
=
Handler
(
self
.
tmp_url
,
decodestring
(
data
),
'odt'
)
...
...
@@ -120,7 +120,7 @@ class TestHandler(HandlerTestCase):
new_data
,
'odt'
)
metadata
=
new_handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
'Title'
),
"Namie's working record"
)
self
.
assertEqual
(
metadata
.
get
(
'Title'
),
"Namie's working record"
)
def
testConvertWithOpenOfficeStopped
(
self
):
"""Test convert with openoffice stopped"""
...
...
@@ -141,8 +141,8 @@ class TestHandler(HandlerTestCase):
decodestring
(
data
),
'odt'
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
'Title'
),
'title'
)
self
.
assertEqual
s
(
metadata
.
get
(
'MIMEType'
),
self
.
assertEqual
(
metadata
.
get
(
'Title'
),
'title'
)
self
.
assertEqual
(
metadata
.
get
(
'MIMEType'
),
'application/vnd.oasis.opendocument.text'
)
def
testSetMetadataWithOpenOfficeStopped
(
self
):
...
...
@@ -157,7 +157,7 @@ class TestHandler(HandlerTestCase):
new_data
,
'doc'
)
metadata
=
new_handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
.
get
(
'Title'
),
"cloudooo Test -"
)
self
.
assertEqual
(
metadata
.
get
(
'Title'
),
"cloudooo Test -"
)
def
testRefreshOdt
(
self
):
"""Test refresh argument"""
...
...
@@ -205,13 +205,13 @@ class TestHandler(HandlerTestCase):
(
'image/png'
,
'PNG - Portable Network Graphic'
),
(
'text/html'
,
'HTML Document (Writer)'
),
(
'text/plain'
,
'Text - Choose Encoding'
)]
self
.
assertEqual
s
(
get
(
"text/plain;ignored=param"
),
text_plain_output_list
)
self
.
assertEqual
s
(
get
(
"text/plain;charset=UTF-8;ignored=param"
),
text_plain_output_list
)
self
.
assertEqual
s
(
get
(
"text/plain;charset=US-ASCII;ignored=param"
),
text_plain_output_list
)
self
.
assertEqual
(
get
(
"text/plain;ignored=param"
),
text_plain_output_list
)
self
.
assertEqual
(
get
(
"text/plain;charset=UTF-8;ignored=param"
),
text_plain_output_list
)
self
.
assertEqual
(
get
(
"text/plain;charset=US-ASCII;ignored=param"
),
text_plain_output_list
)
def
testGetAllowedConversionFormatList_ApplicationMsword
(
self
):
"""Test allowed conversion format for application/msword"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/msword;ignored=param"
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -227,7 +227,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationPdf
(
self
):
"""Test allowed conversion format for application/pdf"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/pdf;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -243,7 +243,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_TextRtf
(
self
):
"""Test allowed conversion format for text/rtf"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"text/rtf;ignored=param"
)),
[])
...
...
@@ -253,7 +253,7 @@ class TestHandler(HandlerTestCase):
"application/vnd.oasis.opendocument.text;ignored=param"
,
"application/vnd.oasis.opendocument.text-flat-xml;ignored=param"
,
):
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
content_type
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -270,7 +270,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOpenxmlformatsOfficedocumentWordprocessingmlDocument
(
self
):
"""Test allowed conversion format for application/vnd.openxmlformats-officedocument.wordprocessingml.document"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document;ignored=param"
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -286,7 +286,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageJpeg
(
self
):
"""Test allowed conversion format for image/jpeg"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/jpeg;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -302,7 +302,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImagePng
(
self
):
"""Test allowed conversion format for image/png"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/png;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -318,7 +318,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_TextHtml
(
self
):
"""Test allowed conversion format for text/html"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"text/html;ignored=param"
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -347,7 +347,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationPostscript
(
self
):
"""Test allowed conversion format for application/postscript"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/postscript;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -363,7 +363,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOasisOpendocumentGraphics
(
self
):
"""Test allowed conversion format for application/vnd.oasis.opendocument.graphics"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.oasis.opendocument.graphics;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -379,7 +379,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageGif
(
self
):
"""Test allowed conversion format for image/gif"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/gif;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -395,7 +395,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageSvgXml
(
self
):
"""Test allowed conversion format for image/svg+xml"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/svg+xml;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -411,7 +411,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageTiff
(
self
):
"""Test allowed conversion format for image/tiff"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/tiff;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -427,7 +427,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageXCmuRaster
(
self
):
"""Test allowed conversion format for image/x-cmu-raster"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-cmu-raster;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -443,7 +443,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageBmp
(
self
):
"""Test allowed conversion format for image/x-ms-bmp"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-ms-bmp;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -459,7 +459,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageXPortableBitmap
(
self
):
"""Test allowed conversion format for image/x-portable-bitmap"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-portable-bitmap;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -475,7 +475,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageXPortableGraymap
(
self
):
"""Test allowed conversion format for image/x-portable-graymap"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-portable-graymap;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -491,7 +491,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageXPortablePixmap
(
self
):
"""Test allowed conversion format for image/x-portable-pixmap"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-portable-pixmap;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -507,7 +507,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ImageXXpixmap
(
self
):
"""Test allowed conversion format for image/x-xpixmap"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"image/x-xpixmap;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -523,7 +523,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndMsExcel
(
self
):
"""Test allowed conversion format for application/vnd.ms-excel"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.ms-excel;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/vnd.ms-excel'
,
'Microsoft Excel 97-2003'
),
...
...
@@ -538,13 +538,13 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndMsExcelSheetMacroenabled12
(
self
):
"""Test allowed conversion format for application/vnd.ms-excel.sheet.macroEnabled.12"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.ms-excel.sheet.macroEnabled.12;ignored=param"
)),
[])
def
testGetAllowedConversionFormatList_ApplicationVndOasisOpendocumentSpreadsheet
(
self
):
"""Test allowed conversion format for application/vnd.oasis.opendocument.spreadsheet"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.oasis.opendocument.spreadsheet;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/vnd.ms-excel'
,
'Microsoft Excel 97-2003'
),
...
...
@@ -559,7 +559,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOpenXmlFormatsOfficedocumentSpreadsheetmlSheet
(
self
):
"""Test allowed conversion format for application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/vnd.ms-excel'
,
'Microsoft Excel 97-2003'
),
...
...
@@ -574,7 +574,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndSunXmlWriter
(
self
):
"""Test allowed conversion format for application/vnd.sun.xml.writer"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.sun.xml.writer;ignored=param"
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -590,7 +590,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_TextCsv
(
self
):
"""Test allowed conversion format for text/csv"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"text/csv;ignored=param"
)),
[
(
'application/msword'
,
'Microsoft Word 97-2003'
),
(
'application/pdf'
,
'PDF - Portable Document Format'
),
...
...
@@ -619,7 +619,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOasisOpendocumentPresentation
(
self
):
"""Test allowed conversion format for application/vnd.oasis.opendocument.presentation"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.oasis.opendocument.presentation;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -642,7 +642,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOpenxmlformatsOfficedocumentPresentationmlPresentation
(
self
):
"""Test allowed conversion format for application/vnd.openxmlformats-officedocument.presentationml.presentation"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.openxmlformats-officedocument.presentationml.presentation;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -665,7 +665,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndOpenxmlformatsOfficedocumentPresentationmlSlideshow
(
self
):
"""Test allowed conversion format for application/vnd.openxmlformats-officedocument.presentationml.slideshow"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.openxmlformats-officedocument.presentationml.slideshow;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
@@ -688,7 +688,7 @@ class TestHandler(HandlerTestCase):
def
testGetAllowedConversionFormatList_ApplicationVndMsPowerpoint
(
self
):
"""Test allowed conversion format for application/vnd.ms-powerpoint"""
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
(
Handler
.
getAllowedConversionFormatList
(
"application/vnd.ms-powerpoint;ignored=param"
)),
[
(
'application/pdf'
,
'PDF - Portable Document Format'
),
(
'application/postscript'
,
'EPS - Encapsulated PostScript'
),
...
...
cloudooo/handler/ooo/tests/testOooLegacyInterface.py
View file @
b2bf7ce9
...
...
@@ -47,8 +47,8 @@ class TestLegacyInterface(TestCase):
None
,
'text/html'
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'text/html'
)
self
.
assertEqual
s
(
self
.
_getFileType
(
response_dict
[
'data'
]),
self
.
assertEqual
(
response_dict
[
'mime'
],
'text/html'
)
self
.
assertEqual
(
self
.
_getFileType
(
response_dict
[
'data'
]),
'text/html'
)
def
testHtmlToOdt
(
self
):
...
...
@@ -61,7 +61,7 @@ class TestLegacyInterface(TestCase):
None
,
'odt'
,
'text/html'
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/vnd.oasis.opendocument.text'
)
self
.
assertEqual
s
(
self
.
_getFileType
(
response_dict
[
'data'
]),
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/vnd.oasis.opendocument.text'
)
self
.
assertEqual
(
self
.
_getFileType
(
response_dict
[
'data'
]),
'application/vnd.oasis.opendocument.text'
)
cloudooo/handler/ooo/tests/testOooMimemapper.py
View file @
b2bf7ce9
...
...
@@ -161,50 +161,50 @@ class TestMimeMapper(HandlerTestCase):
def
testGetFilterWhenExtensionNotExist
(
self
):
"""Test the case that the user passes extension which does not exist."""
empty_list
=
self
.
mimemapper
.
getFilterList
(
'xxx'
)
self
.
assertEqual
s
(
empty_list
,
[])
self
.
assertEqual
(
empty_list
,
[])
def
testIfThereIsDuplicateData
(
self
):
"""Test if there is duplicate data."""
# XXX It can not exists multiple keys inside a dictionary
extension_list
=
self
.
mimemapper
.
_doc_type_list_by_extension
.
keys
()
self
.
assertEqual
s
(
len
(
extension_list
),
len
(
set
(
extension_list
)))
self
.
assertEqual
(
len
(
extension_list
),
len
(
set
(
extension_list
)))
for
type_list
in
self
.
mimemapper
.
_doc_type_list_by_extension
.
values
():
self
.
assertEqual
s
(
len
(
type_list
),
len
(
set
(
type_list
)))
self
.
assertEqual
(
len
(
type_list
),
len
(
set
(
type_list
)))
document_type_list
=
self
.
mimemapper
.
_document_type_dict
.
keys
()
self
.
assertEqual
s
(
len
(
document_type_list
),
len
(
set
(
document_type_list
)))
self
.
assertEqual
(
len
(
document_type_list
),
len
(
set
(
document_type_list
)))
document_service_list
=
self
.
mimemapper
.
_document_type_dict
.
values
()
self
.
assertEqual
s
(
len
(
document_service_list
),
len
(
set
(
document_service_list
)))
self
.
assertEqual
(
len
(
document_service_list
),
len
(
set
(
document_service_list
)))
document_service_list
=
self
.
mimemapper
.
_extension_list_by_type
.
keys
()
self
.
assertEqual
s
(
len
(
document_service_list
),
len
(
set
(
document_service_list
)))
self
.
assertEqual
(
len
(
document_service_list
),
len
(
set
(
document_service_list
)))
extension_list
=
self
.
mimemapper
.
_extension_list_by_type
.
values
()
for
extension
in
extension_list
:
self
.
assertEqual
s
(
len
(
extension
),
len
(
set
(
extension
)),
self
.
assertEqual
(
len
(
extension
),
len
(
set
(
extension
)),
"extension_list_by_type has duplicate data"
)
def
testGetFilterByExt
(
self
):
"""Test if passing the extension the filter returns corretcly."""
pdf_filter_list
=
self
.
mimemapper
.
getFilterList
(
'pdf'
)
self
.
assertEqual
s
(
len
(
pdf_filter_list
),
5
)
self
.
assertEqual
(
len
(
pdf_filter_list
),
5
)
xls_filter_list
=
self
.
mimemapper
.
getFilterList
(
'xls'
)
self
.
assertEqual
s
(
len
(
xls_filter_list
),
1
)
self
.
assertEqual
(
len
(
xls_filter_list
),
1
)
doc_filter_list
=
self
.
mimemapper
.
getFilterList
(
'doc'
)
self
.
assertEqual
s
(
len
(
doc_filter_list
),
1
)
self
.
assertEqual
(
len
(
doc_filter_list
),
1
)
def
testGetDocumentTypeDict
(
self
):
"""Test if dictonary document type returns type correctly."""
document_type_dict
=
self
.
mimemapper
.
_document_type_dict
type
=
document_type_dict
.
get
(
"text"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.text.TextDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.text.TextDocument'
)
type
=
document_type_dict
.
get
(
"chart"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.chart2.ChartDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.chart2.ChartDocument'
)
type
=
document_type_dict
.
get
(
"drawing"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.drawing.DrawingDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.drawing.DrawingDocument'
)
type
=
document_type_dict
.
get
(
"presentation"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.presentation.PresentationDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.presentation.PresentationDocument'
)
type
=
document_type_dict
.
get
(
"spreadsheet"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.sheet.SpreadsheetDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.sheet.SpreadsheetDocument'
)
type
=
document_type_dict
.
get
(
"web"
)
self
.
assertEqual
s
(
type
,
'com.sun.star.text.WebDocument'
)
self
.
assertEqual
(
type
,
'com.sun.star.text.WebDocument'
)
def
testGetAllowedExtensionListByExtension
(
self
):
"""Test if function getAllowedExtensionList returns correctly a list with
...
...
@@ -243,7 +243,7 @@ class TestMimeMapper(HandlerTestCase):
got_list
.
sort
()
global_expected_list
=
list
(
global_expected_tuple
)
global_expected_list
.
sort
()
self
.
assertEqual
s
(
got_list
,
global_expected_list
)
self
.
assertEqual
(
got_list
,
global_expected_list
)
def
testGetAllAllowedExtensionListForDrawing
(
self
):
"""Passing document_type equal to 'drawing', the return must be equal
...
...
@@ -262,7 +262,7 @@ class TestMimeMapper(HandlerTestCase):
got_tuple
.
sort
()
web_expected_list
=
list
(
web_expected_tuple
)
web_expected_list
.
sort
()
self
.
assertEqual
s
(
got_tuple
,
web_expected_list
)
self
.
assertEqual
(
got_tuple
,
web_expected_list
)
def
testGetAllAllowedExtensionListForPresentation
(
self
):
"""Passing document_type equal to 'presentation', the return must be equal
...
...
@@ -290,21 +290,21 @@ class TestMimeMapper(HandlerTestCase):
got_list
.
sort
()
chart_expected_list
=
list
(
chart_expected_tuple
)
chart_expected_list
.
sort
()
self
.
assertEqual
s
(
got_list
,
chart_expected_list
)
self
.
assertEqual
(
got_list
,
chart_expected_list
)
def
testGetFilterName
(
self
):
"""Test if passing extension and document_type, the filter is correct."""
filtername
=
self
.
mimemapper
.
getFilterName
(
"xls"
,
'com.sun.star.sheet.SpreadsheetDocument'
)
self
.
assertEqual
s
(
filtername
,
"MS Excel 97"
)
self
.
assertEqual
(
filtername
,
"MS Excel 97"
)
filtername
=
self
.
mimemapper
.
getFilterName
(
"pdf"
,
'com.sun.star.text.TextDocument'
)
self
.
assertEqual
s
(
filtername
,
"writer_pdf_Export"
)
self
.
assertEqual
(
filtername
,
"writer_pdf_Export"
)
filtername
=
self
.
mimemapper
.
getFilterName
(
'ppt'
,
'com.sun.star.presentation.PresentationDocument'
)
self
.
assertEqual
s
(
filtername
,
"MS PowerPoint 97"
)
self
.
assertEqual
(
filtername
,
"MS PowerPoint 97"
)
filtername
=
self
.
mimemapper
.
getFilterName
(
"html"
,
'com.sun.star.presentation.PresentationDocument'
)
self
.
assertEqual
s
(
filtername
,
"impress_html_Export"
)
self
.
assertEqual
(
filtername
,
"impress_html_Export"
)
cloudooo/handler/ooo/tests/testOooMonitorInit.py
View file @
b2bf7ce9
...
...
@@ -53,13 +53,13 @@ class TestMonitorInit(HandlerTestCase):
def
testMonitorInitGlobalAttributes
(
self
):
"""Test the global attributes"""
self
.
assertEqual
s
(
monitor
.
monitor_request
,
None
)
self
.
assertEqual
s
(
monitor
.
monitor_memory
,
None
)
self
.
assertEqual
(
monitor
.
monitor_request
,
None
)
self
.
assertEqual
(
monitor
.
monitor_memory
,
None
)
def
testMonitorLoadOnlyMonitorRequest
(
self
):
"""Check if the monitors are started"""
monitor
.
load
(
self
.
load_config
)
self
.
assertEqual
s
(
isinstance
(
monitor
.
monitor_request
,
self
.
assertEqual
(
isinstance
(
monitor
.
monitor_request
,
MonitorRequest
),
True
)
...
...
@@ -67,10 +67,10 @@ class TestMonitorInit(HandlerTestCase):
"""Check if the MemoryMemory is started"""
self
.
load_config
[
'enable_memory_monitor'
]
=
'true'
monitor
.
load
(
self
.
load_config
)
self
.
assertEqual
s
(
isinstance
(
monitor
.
monitor_request
,
self
.
assertEqual
(
isinstance
(
monitor
.
monitor_request
,
MonitorRequest
),
True
)
self
.
assertEqual
s
(
isinstance
(
monitor
.
monitor_memory
,
self
.
assertEqual
(
isinstance
(
monitor
.
monitor_memory
,
MonitorMemory
),
True
)
...
...
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
View file @
b2bf7ce9
...
...
@@ -74,7 +74,7 @@ class TestMonitorMemory(unittest.TestCase):
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
10
)
self
.
monitor
.
start
()
sleep
(
self
.
interval
)
self
.
assertEqual
s
(
openoffice
.
status
(),
False
)
self
.
assertEqual
(
openoffice
.
status
(),
False
)
finally
:
self
.
monitor
.
terminate
()
...
...
@@ -94,17 +94,17 @@ class TestMonitorMemory(unittest.TestCase):
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
self
.
monitor
.
create_process
()
self
.
assertTrue
(
hasattr
(
self
.
monitor
,
'process'
))
self
.
assertEqual
s
(
type
(
self
.
monitor
.
process
),
Process
)
self
.
assertEqual
(
type
(
self
.
monitor
.
process
),
Process
)
def
testGetMemoryUsage
(
self
):
"""Test memory usage"""
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
openoffice
.
stop
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
()
self
.
assertEqual
s
(
memory_usage_int
,
0
)
self
.
assertEqual
(
memory_usage_int
,
0
)
if
not
openoffice
.
status
():
openoffice
.
start
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
()
self
.
assertEqual
s
(
type
(
memory_usage_int
),
IntType
)
self
.
assertEqual
(
type
(
memory_usage_int
),
IntType
)
cloudooo/handler/ooo/tests/testOooMonitorRequest.py
View file @
b2bf7ce9
...
...
@@ -47,18 +47,18 @@ class TestMonitorRequest(HandlerTestCase):
monitor_request
.
terminate
()
sleep
(
4
)
try
:
self
.
assertEqual
s
(
monitor_request
.
is_alive
(),
False
)
self
.
assertEqual
(
monitor_request
.
is_alive
(),
False
)
finally
:
monitor_request
.
terminate
()
def
testMonitorRequest
(
self
):
"""Test if openoffice is monitored correclty"""
openoffice
.
request
=
3
self
.
assertEqual
s
(
openoffice
.
request
,
3
)
self
.
assertEqual
(
openoffice
.
request
,
3
)
monitor_request
=
MonitorRequest
(
openoffice
,
1
,
2
)
monitor_request
.
start
()
sleep
(
4
)
self
.
assertEqual
s
(
openoffice
.
request
,
0
)
self
.
assertEqual
(
openoffice
.
request
,
0
)
monitor_request
.
terminate
()
cloudooo/handler/ooo/tests/testOooMonitorTimeout.py
View file @
b2bf7ce9
...
...
@@ -52,7 +52,7 @@ class TestMonitorTimeout(unittest.TestCase):
monitor_timeout
=
self
.
_createMonitor
(
1
)
monitor_timeout
.
start
()
sleep
(
2
)
self
.
assertEqual
s
(
monitor_timeout
.
is_alive
(),
False
)
self
.
assertEqual
(
monitor_timeout
.
is_alive
(),
False
)
monitor_timeout
.
terminate
()
def
testStopOpenOffice
(
self
):
...
...
@@ -62,7 +62,7 @@ class TestMonitorTimeout(unittest.TestCase):
monitor_timeout
=
self
.
_createMonitor
(
1
)
monitor_timeout
.
start
()
sleep
(
2
)
self
.
assertEqual
s
(
openoffice
.
status
(),
False
)
self
.
assertEqual
(
openoffice
.
status
(),
False
)
openoffice
.
restart
()
self
.
assertTrue
(
openoffice
.
status
())
finally
:
...
...
@@ -76,17 +76,17 @@ class TestMonitorTimeout(unittest.TestCase):
monitor_timeout
=
self
.
_createMonitor
(
1
)
monitor_timeout
.
start
()
sleep
(
2
)
self
.
assertEqual
s
(
openoffice
.
status
(),
False
)
self
.
assertEqual
(
openoffice
.
status
(),
False
)
monitor_timeout
.
terminate
()
openoffice
.
restart
()
self
.
assertTrue
(
openoffice
.
status
())
monitor_timeout
=
self
.
_createMonitor
(
1
)
monitor_timeout
.
start
()
sleep
(
2
)
self
.
assertEqual
s
(
openoffice
.
status
(),
False
)
self
.
assertEqual
(
openoffice
.
status
(),
False
)
monitor_timeout
.
terminate
()
sleep
(
1
)
self
.
assertEqual
s
(
monitor_timeout
.
is_alive
(),
False
)
self
.
assertEqual
(
monitor_timeout
.
is_alive
(),
False
)
finally
:
monitor_timeout
.
terminate
()
openoffice
.
release
()
...
...
cloudooo/handler/ooo/tests/testOooOdfDocument.py
View file @
b2bf7ce9
...
...
@@ -52,12 +52,12 @@ class TestOdfDocument(HandlerTestCase):
def
testGetExistentFile
(
self
):
"""Test if the getFile method returns the requested file"""
requested_file
=
self
.
oodocument
.
getFile
(
'content.xml'
)
self
.
assertEqual
s
(
requested_file
,
self
.
oodocument
.
getContentXml
())
self
.
assertEqual
(
requested_file
,
self
.
oodocument
.
getContentXml
())
def
testGetNotPresentFile
(
self
):
"""Test if the getFile method returns None for not present file request"""
requested_file
=
self
.
oodocument
.
getFile
(
'not_present.xml'
)
self
.
assertEqual
s
(
requested_file
,
''
)
self
.
assertEqual
(
requested_file
,
''
)
def
testParseContent
(
self
):
"""Test if the _parsed_content attribute is the parsed content.xml"""
...
...
cloudooo/handler/ooo/tests/testOooOpenOffice.py
View file @
b2bf7ce9
...
...
@@ -56,10 +56,10 @@ class TestOpenOffice(HandlerTestCase):
def
testPid
(
self
):
"""Test pid function to validate if the return is correctly"""
self
.
assertNotEqual
s
(
self
.
openoffice
.
pid
(),
None
)
self
.
assertNotEqual
(
self
.
openoffice
.
pid
(),
None
)
self
.
openoffice
.
stop
()
self
.
assertEqual
s
(
self
.
openoffice
.
pid
(),
None
)
self
.
assertEqual
s
(
self
.
openoffice
.
status
(),
False
)
self
.
assertEqual
(
self
.
openoffice
.
pid
(),
None
)
self
.
assertEqual
(
self
.
openoffice
.
status
(),
False
)
def
testOpenOfficeStart
(
self
):
"""Test if the start method works correclty"""
...
...
@@ -69,12 +69,12 @@ class TestOpenOffice(HandlerTestCase):
"""Test if the stop method works correctly"""
self
.
openoffice
.
stop
()
waitStopDaemon
(
self
.
openoffice
)
self
.
assertEqual
s
(
self
.
openoffice
.
status
(),
False
)
self
.
assertEqual
(
self
.
openoffice
.
status
(),
False
)
def
testOpenOfficeRequest
(
self
):
"""Test if the requisition amount is increasing right"""
self
.
openoffice
.
acquire
()
self
.
assertEqual
s
(
self
.
openoffice
.
request
,
1
)
self
.
assertEqual
(
self
.
openoffice
.
request
,
1
)
self
.
openoffice
.
release
()
def
testOpenOfficeRestart
(
self
):
...
...
@@ -87,7 +87,7 @@ class TestOpenOffice(HandlerTestCase):
self
.
openoffice
.
acquire
()
self
.
assertTrue
(
self
.
openoffice
.
isLocked
())
self
.
openoffice
.
release
()
self
.
assertEqual
s
(
self
.
openoffice
.
isLocked
(),
False
)
self
.
assertEqual
(
self
.
openoffice
.
isLocked
(),
False
)
def
testStartTwoOpenOfficeWithTheSameAddress
(
self
):
"""Check if starting two openoffice using the same address, the second
...
...
@@ -100,7 +100,7 @@ class TestOpenOffice(HandlerTestCase):
'en'
,
self
.
environment_dict
)
second_openoffice
.
start
()
self
.
assertEqual
s
(
self
.
openoffice
.
status
(),
False
)
self
.
assertEqual
(
self
.
openoffice
.
status
(),
False
)
self
.
assertTrue
(
second_openoffice
.
status
())
second_openoffice
.
stop
()
...
...
cloudooo/handler/ooo/tests/testOooServer.py
View file @
b2bf7ce9
...
...
@@ -200,11 +200,11 @@ class TestGetMetadata(TestCase):
new_odf_data
=
self
.
proxy
.
updateFileMetadata
(
odf_data
,
'odt'
,
dict
(
Reference
=
"new value"
,
Something
=
"ABC"
))
self
.
assertEqual
s
(
self
.
_getFileType
(
new_odf_data
),
self
.
assertEqual
(
self
.
_getFileType
(
new_odf_data
),
'application/vnd.oasis.opendocument.text'
)
metadata_dict
=
self
.
proxy
.
getFileMetadataItemList
(
new_odf_data
,
'odt'
)
self
.
assertEqual
s
(
metadata_dict
.
get
(
"Reference"
),
"new value"
)
self
.
assertEqual
s
(
metadata_dict
.
get
(
"Something"
),
"ABC"
)
self
.
assertEqual
(
metadata_dict
.
get
(
"Reference"
),
"new value"
)
self
.
assertEqual
(
metadata_dict
.
get
(
"Something"
),
"ABC"
)
# XXX: This is a test for ERP5 Backward compatibility,
...
...
@@ -217,10 +217,10 @@ class TestGetMetadata(TestCase):
None
,
'pdf'
,
'application/vnd.oasis.opendocument.text'
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/pdf'
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/pdf'
)
class
TestGenerate
(
TestCase
):
...
...
@@ -235,10 +235,10 @@ class TestGenerate(TestCase):
None
,
'html'
,
"application/vnd.oasis.opendocument.spreadsheet"
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/zip'
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/zip'
)
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
self
.
assertTrue
(
is_zipfile
(
output_url
))
...
...
@@ -260,10 +260,10 @@ class TestGenerate(TestCase):
None
,
'ms.xlsx'
,
"application/vnd.oasis.opendocument.spreadsheet"
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
# XXX: This is a test for ERP5 Backward compatibility,
# and the support to this kind of tests will be dropped.
...
...
@@ -276,10 +276,10 @@ class TestGenerate(TestCase):
None
,
'html'
,
'application/vnd.oasis.opendocument.presentation'
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/zip'
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/zip'
)
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
self
.
assertTrue
(
is_zipfile
(
output_url
))
...
...
@@ -288,7 +288,7 @@ class TestGenerate(TestCase):
png_path
=
join
(
self
.
tmp_url
,
"img0.png"
)
zipfile
.
extractall
(
self
.
tmp_url
)
content_type
=
self
.
_getFileType
(
encodestring
(
open
(
png_path
).
read
()))
self
.
assertEqual
s
(
content_type
,
'image/png'
)
self
.
assertEqual
(
content_type
,
'image/png'
)
m
=
magic
.
Magic
()
self
.
assertTrue
(
"8-bit/color RGB"
in
m
.
from_file
(
png_path
))
finally
:
...
...
@@ -307,10 +307,10 @@ class TestGenerate(TestCase):
None
,
'html'
,
'application/vnd.oasis.opendocument.presentation'
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
s
(
response_dict
[
'mime'
],
'application/zip'
)
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
''
)
self
.
assertEqual
(
response_dict
[
'mime'
],
'application/zip'
)
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
self
.
assertTrue
(
is_zipfile
(
output_url
))
...
...
@@ -334,9 +334,9 @@ class TestGenerate(TestCase):
encodestring
(
data
),
None
,
'pdf'
,
'application/vnd.oasis.opendocument.text'
)
response_code
,
response_dict
,
response_message
=
generate_result
self
.
assertEqual
s
(
response_code
,
402
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertEqual
s
(
response_dict
,
{})
self
.
assertEqual
(
response_code
,
402
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
self
.
assertEqual
(
response_dict
,
{})
self
.
assertTrue
(
response_message
.
startswith
(
'Traceback'
))
...
...
@@ -348,16 +348,16 @@ class TestSetMetadata(TestCase):
open
(
join
(
'data'
,
'testMetadata.odt'
)).
read
()),
{
"Title"
:
"testSetMetadata"
,
"Description"
:
"Music"
})
response_code
,
response_dict
,
response_message
=
setmetadata_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
(
response_code
,
200
)
new_data
=
response_dict
[
'data'
]
self
.
assertNotEqual
s
(
new_data
,
''
)
self
.
assertNotEqual
(
new_data
,
''
)
getmetadata_result
=
self
.
proxy
.
run_getmetadata
(
'testMetadata.odt'
,
new_data
)
response_code
,
response_dict
,
response_message
=
getmetadata_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
response_dict
[
'meta'
][
'MIMEType'
],
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
response_dict
[
'meta'
][
'MIMEType'
],
'application/vnd.oasis.opendocument.text'
)
self
.
assertEqual
s
(
response_dict
[
'meta'
][
'Description'
],
"Music"
)
self
.
assertEqual
(
response_dict
[
'meta'
][
'Description'
],
"Music"
)
setmetadata_result
=
self
.
proxy
.
run_setmetadata
(
'testMetadata.odt'
,
new_data
,
{
"Title"
:
"Namie's working record"
,
...
...
@@ -366,8 +366,8 @@ class TestSetMetadata(TestCase):
getmetadata_result
=
self
.
proxy
.
run_getmetadata
(
'testMetadata.odt'
,
response_dict
[
'data'
])
response_code
,
response_dict
,
response_message
=
getmetadata_result
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
s
(
response_dict
[
'meta'
][
'title'
],
self
.
assertEqual
(
response_code
,
200
)
self
.
assertEqual
(
response_dict
[
'meta'
][
'title'
],
"Namie's working record"
)
def
testRunSetMetadataFailResponse
(
self
):
...
...
@@ -377,8 +377,8 @@ class TestSetMetadata(TestCase):
open
(
join
(
'data'
,
'testMetadata.odt'
)).
read
()[:
100
]),
{
"Title"
:
"testSetMetadata"
,
"Description"
:
"Music"
})
response_code
,
response_dict
,
response_message
=
setmetadata_result
self
.
assertEqual
s
(
response_code
,
402
)
self
.
assertEqual
s
(
response_dict
,
{})
self
.
assertEqual
(
response_code
,
402
)
self
.
assertEqual
(
response_dict
,
{})
self
.
assertTrue
(
response_message
.
startswith
(
'Traceback'
))
...
...
@@ -388,9 +388,9 @@ class TestGetAllowedTargetItemList(TestCase):
mimetype
=
'application/vnd.oasis.opendocument.text'
response_code
,
response_dict
,
response_message
=
\
self
.
proxy
.
getAllowedTargetItemList
(
mimetype
)
self
.
assertEqual
s
(
response_code
,
200
)
self
.
assertEqual
(
response_code
,
200
)
# XXX in this test, docy is present in the allowed target extensions
self
.
assertEqual
s
(
self
.
assertEqual
(
sorted
([(
extension
,
ui_name
)
for
(
extension
,
ui_name
)
in
response_dict
[
'response_data'
]
if
extension
not
in
(
'docy'
,)]),
...
...
@@ -406,7 +406,7 @@ class TestGetTableItemList(TestCase):
granulated_table
=
self
.
proxy
.
getTableItemList
(
encodestring
(
open
(
"data/granulate_table_test.odt"
).
read
()),
"odt"
)
self
.
assertEqual
s
(
table_list
,
granulated_table
)
self
.
assertEqual
(
table_list
,
granulated_table
)
def
testGetTableItemListFromDoc
(
self
):
"""Test if getTableItemList can get the table item list from doc file"""
...
...
@@ -416,7 +416,7 @@ class TestGetTableItemList(TestCase):
granulated_table
=
self
.
proxy
.
getTableItemList
(
encodestring
(
open
(
"data/granulate_table_test.doc"
).
read
()),
"doc"
)
self
.
assertEqual
s
(
table_list
,
granulated_table
)
self
.
assertEqual
(
table_list
,
granulated_table
)
def
testGetTableFromOdt
(
self
):
"""Test if getTableItemList can get a item of some granulated table from odt file"""
...
...
@@ -428,10 +428,10 @@ class TestGetTableItemList(TestCase):
content_xml
=
etree
.
fromstring
(
content_xml_str
)
table_list
=
content_xml
.
xpath
(
'//table:table'
,
namespaces
=
content_xml
.
nsmap
)
self
.
assertEqual
s
(
1
,
len
(
table_list
))
self
.
assertEqual
(
1
,
len
(
table_list
))
table
=
table_list
[
0
]
name_key
=
'{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self
.
assertEqual
s
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
self
.
assertEqual
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
def
testGetTableFromDoc
(
self
):
"""Test if getTableItemList can get a item of some granulated table from doc file"""
...
...
@@ -444,10 +444,10 @@ class TestGetTableItemList(TestCase):
content_xml
=
etree
.
fromstring
(
content_xml_str
)
table_list
=
content_xml
.
xpath
(
'//table:table'
,
namespaces
=
content_xml
.
nsmap
)
self
.
assertEqual
s
(
1
,
len
(
table_list
))
self
.
assertEqual
(
1
,
len
(
table_list
))
table
=
table_list
[
0
]
name_key
=
'{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self
.
assertEqual
s
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
self
.
assertEqual
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
def
testGetColumnItemListFromOdt
(
self
):
"""Test if getColumnItemList can get the list of column item from odt file"""
...
...
@@ -455,7 +455,7 @@ class TestGetTableItemList(TestCase):
encodestring
(
open
(
"./data/granulate_table_test.odt"
).
read
()),
"SoccerTeams"
,
"odt"
)
self
.
assertEqual
s
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
self
.
assertEqual
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
def
testGetColumnItemListFromDoc
(
self
):
"""Test if getColumnItemList can get the list of column item from doc file"""
...
...
@@ -464,13 +464,13 @@ class TestGetTableItemList(TestCase):
encodestring
(
open
(
"./data/granulate_table_test.doc"
).
read
()),
"Table3"
,
"doc"
)
self
.
assertEqual
s
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
self
.
assertEqual
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
def
testGetLineItemListFromOdt
(
self
):
"""Test if getLineItemList can get the list of lines items from odt file"""
data
=
encodestring
(
open
(
"./data/granulate_table_test.odt"
).
read
())
line_item_list
=
self
.
proxy
.
getLineItemList
(
data
,
"Developers"
,
"odt"
)
self
.
assertEqual
s
([[
'Name'
,
'Hugo'
],
[
'Phone'
,
'+55 (22) 8888-8888'
],
self
.
assertEqual
([[
'Name'
,
'Hugo'
],
[
'Phone'
,
'+55 (22) 8888-8888'
],
[
'Email'
,
'hugomaia@tiolive.com'
],
[
'Name'
,
'Rafael'
],
[
'Phone'
,
'+55 (22) 9999-9999'
],
[
'Email'
,
'rafael@tiolive.com'
]],
line_item_list
)
...
...
@@ -479,7 +479,7 @@ class TestGetTableItemList(TestCase):
"""Test if getLineItemList can get the list of lines items from doc file"""
data
=
encodestring
(
open
(
"./data/granulate_table_test.doc"
).
read
())
line_item_list
=
self
.
proxy
.
getLineItemList
(
data
,
"Table1"
,
"doc"
)
self
.
assertEqual
s
([[
'Name'
,
'Hugo'
],
[
'Phone'
,
'+55 (22) 8888-8888'
],
self
.
assertEqual
([[
'Name'
,
'Hugo'
],
[
'Phone'
,
'+55 (22) 8888-8888'
],
[
'Email'
,
'hugomaia@tiolive.com'
],
[
'Name'
,
'Rafael'
],
[
'Phone'
,
'+55 (22) 9999-9999'
],
[
'Email'
,
'rafael@tiolive.com'
]],
line_item_list
)
...
...
@@ -490,7 +490,7 @@ class TestImagetItemList(TestCase):
"""Test if getImageItemList can get the list of images items from odt file"""
data
=
encodestring
(
open
(
"./data/granulate_test.odt"
).
read
())
image_list
=
self
.
proxy
.
getImageItemList
(
data
,
"odt"
)
self
.
assertEqual
s
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
self
.
assertEqual
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
[
'10000201000000C80000004E85B3F70C71E07CE8.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004E85B3F70C71E07CE8.png'
,
''
],
[
'2000004F0000423300001370ADF6545B2997B448.svm'
,
'Python Logo'
],
...
...
@@ -501,7 +501,7 @@ class TestImagetItemList(TestCase):
"""Test if getImageItemList can get the list of images items from doc file"""
data
=
encodestring
(
open
(
"./data/granulate_test.doc"
).
read
())
image_list
=
self
.
proxy
.
getImageItemList
(
data
,
"doc"
)
self
.
assertEqual
s
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
self
.
assertEqual
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
[
'10000201000000C80000004E85B3F70C71E07CE8.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004E85B3F70C71E07CE8.png'
,
''
],
[
'2000031600004233000013702113A0E70B910778.wmf'
,
'Python Logo'
],
...
...
@@ -515,7 +515,7 @@ class TestImagetItemList(TestCase):
image_id
=
'10000201000000C80000004E7B947D46.png'
original_image
=
zip
.
read
(
'Pictures/%s'
%
image_id
)
geted_image
=
decodestring
(
self
.
proxy
.
getImage
(
data
,
image_id
,
"odt"
))
self
.
assertEqual
s
(
original_image
,
geted_image
)
self
.
assertEqual
(
original_image
,
geted_image
)
def
testGetImageFromDoc
(
self
):
"""Test if getImage can get a image from doc file after zip"""
...
...
@@ -527,7 +527,7 @@ class TestImagetItemList(TestCase):
image_id
=
'10000000000000C80000009CBF079A6E41EE290C.jpg'
original_image
=
zip
.
read
(
'Pictures/%s'
%
image_id
)
geted_image
=
decodestring
(
self
.
proxy
.
getImage
(
data
,
image_id
,
"doc"
))
self
.
assertEqual
s
(
original_image
,
geted_image
)
self
.
assertEqual
(
original_image
,
geted_image
)
class
TestParagraphItemList
(
TestCase
):
...
...
@@ -535,7 +535,7 @@ class TestParagraphItemList(TestCase):
"""Test if getParagraphItemList can get paragraphs correctly from document"""
data
=
encodestring
(
open
(
"./data/granulate_test.odt"
).
read
())
paragraph_list
=
self
.
proxy
.
getParagraphItemList
(
data
,
"odt"
)
self
.
assertEqual
s
([[
0
,
'P3'
],
[
1
,
'P1'
],
[
2
,
'P12'
],
[
3
,
'P6'
],
[
4
,
'P7'
],
self
.
assertEqual
([[
0
,
'P3'
],
[
1
,
'P1'
],
[
2
,
'P12'
],
[
3
,
'P6'
],
[
4
,
'P7'
],
[
5
,
'P8'
],
[
6
,
'P6'
],
[
7
,
'P6'
],
[
8
,
'P13'
],
[
9
,
'P9'
],
[
10
,
'P9'
],
[
11
,
'P9'
],
[
12
,
'P4'
],
[
13
,
'P10'
],
[
14
,
'P5'
],
[
15
,
'P5'
],
[
16
,
'P14'
],
[
17
,
'P11'
],
[
18
,
'P11'
],
...
...
@@ -547,7 +547,7 @@ class TestParagraphItemList(TestCase):
"""Test if getParagraph can get a paragraph"""
data
=
encodestring
(
open
(
"./data/granulate_test.odt"
).
read
())
paragraph
=
self
.
proxy
.
getParagraph
(
data
,
1
,
"odt"
)
self
.
assertEqual
s
([
''
,
'P1'
],
paragraph
)
self
.
assertEqual
([
''
,
'P1'
],
paragraph
)
class
TestChapterItemList
(
TestCase
):
...
...
@@ -555,7 +555,7 @@ class TestChapterItemList(TestCase):
"""Test if getChapterItemList can get the chapters list correctly from document"""
data
=
encodestring
(
open
(
"./data/granulate_chapters_test.odt"
).
read
())
chapter_list
=
self
.
proxy
.
getChapterItemList
(
data
,
"odt"
)
self
.
assertEqual
s
([[
0
,
'Title 0'
],
[
1
,
'Title 1'
],
[
2
,
'Title 2'
],
self
.
assertEqual
([[
0
,
'Title 0'
],
[
1
,
'Title 1'
],
[
2
,
'Title 2'
],
[
3
,
'Title 3'
],
[
4
,
'Title 4'
],
[
5
,
'Title 5'
],
[
6
,
'Title 6'
],
[
7
,
'Title 7'
],
[
8
,
'Title 8'
],
[
9
,
'Title 9'
],
[
10
,
'Title 10'
]]
,
chapter_list
)
...
...
@@ -564,7 +564,7 @@ class TestChapterItemList(TestCase):
"""Test if getChapterItem can get a chapter"""
data
=
encodestring
(
open
(
"./data/granulate_chapters_test.odt"
).
read
())
chapter
=
self
.
proxy
.
getChapterItem
(
1
,
data
,
"odt"
)
self
.
assertEqual
s
([
'Title 1'
,
1
],
chapter
)
self
.
assertEqual
([
'Title 1'
,
1
],
chapter
)
class
TestCSVEncoding
(
TestCase
):
...
...
cloudooo/handler/ooo/tests/testOooUnoConverter.py
View file @
b2bf7ce9
...
...
@@ -80,12 +80,12 @@ class TestUnoConverter(HandlerTestCase):
stdout
,
stderr
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
).
communicate
()
self
.
assertEqual
s
(
stderr
,
''
)
self
.
assertEqual
(
stderr
,
''
)
output_url
=
stdout
.
replace
(
'
\
n
'
,
''
)
self
.
assertTrue
(
exists
(
output_url
),
stdout
)
mime
=
magic
.
Magic
(
mime
=
True
)
self
.
assertEqual
s
(
mime
.
from_file
(
output_url
),
'application/msword'
)
self
.
assertEqual
(
mime
.
from_file
(
output_url
),
'application/msword'
)
self
.
document
.
trash
()
self
.
assertEqual
s
(
exists
(
output_url
),
False
)
self
.
assertEqual
(
exists
(
output_url
),
False
)
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
View file @
b2bf7ce9
...
...
@@ -68,15 +68,15 @@ class TestUnoMimeMapper(HandlerTestCase):
stdout
,
stderr
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
).
communicate
()
self
.
assertEqual
s
(
stderr
,
''
)
self
.
assertEqual
(
stderr
,
''
)
filter_dict
,
type_dict
=
json
.
loads
(
stdout
)
self
.
assertTrue
(
'filter_dict'
in
locals
())
self
.
assertTrue
(
'type_dict'
in
locals
())
self
.
assertNotEqual
s
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
s
(
type_dict
.
get
(
'writer8'
).
get
(
'Name'
),
'writer8'
)
self
.
assertNotEqual
s
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
s
(
type_dict
.
get
(
'writer8'
).
get
(
'PreferredFilter'
),
'writer8'
)
self
.
assertEqual
s
(
stderr
,
''
)
self
.
assertNotEqual
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
(
type_dict
.
get
(
'writer8'
).
get
(
'Name'
),
'writer8'
)
self
.
assertNotEqual
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
(
type_dict
.
get
(
'writer8'
).
get
(
'PreferredFilter'
),
'writer8'
)
self
.
assertEqual
(
stderr
,
''
)
def
testCallUnoMimemapperOnlyHostNameAndPort
(
self
):
""" Test call unomimemapper without uno_path and office_binary_path"""
...
...
@@ -89,15 +89,15 @@ class TestUnoMimeMapper(HandlerTestCase):
stdout
,
stderr
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
).
communicate
()
self
.
assertEqual
s
(
stderr
,
''
)
self
.
assertEqual
(
stderr
,
''
)
filter_dict
,
type_dict
=
json
.
loads
(
stdout
)
self
.
assertTrue
(
'filter_dict'
in
locals
())
self
.
assertTrue
(
'type_dict'
in
locals
())
self
.
assertNotEqual
s
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
s
(
type_dict
.
get
(
'writer8'
).
get
(
'Name'
),
'writer8'
)
self
.
assertNotEqual
s
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
s
(
type_dict
.
get
(
'writer8'
).
get
(
'PreferredFilter'
),
'writer8'
)
self
.
assertEqual
s
(
stderr
,
''
)
self
.
assertNotEqual
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
(
type_dict
.
get
(
'writer8'
).
get
(
'Name'
),
'writer8'
)
self
.
assertNotEqual
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEqual
(
type_dict
.
get
(
'writer8'
).
get
(
'PreferredFilter'
),
'writer8'
)
self
.
assertEqual
(
stderr
,
''
)
def
testWithoutOpenOffice
(
self
):
"""Test when the openoffice is stopped"""
...
...
@@ -118,7 +118,7 @@ class TestUnoMimeMapper(HandlerTestCase):
stdout
,
stderr
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
).
communicate
()
self
.
assertEqual
s
(
stdout
,
''
)
self
.
assertEqual
(
stdout
,
''
)
self
.
assertTrue
(
stderr
.
endswith
(
error_msg
),
stderr
)
openoffice
.
start
()
...
...
cloudooo/handler/ooo/tests/testOooUtil.py
View file @
b2bf7ce9
...
...
@@ -48,10 +48,10 @@ class TestUtil(unittest.TestCase):
def
testLoadMimetypelist
(
self
):
"""Test if the file with mimetypes is loaded correctly"""
self
.
assertEqual
s
(
mimetypes
.
types_map
.
get
(
".ogv"
),
None
)
self
.
assertEqual
s
(
mimetypes
.
types_map
.
get
(
".3gp"
),
None
)
self
.
assertEqual
(
mimetypes
.
types_map
.
get
(
".ogv"
),
None
)
self
.
assertEqual
(
mimetypes
.
types_map
.
get
(
".3gp"
),
None
)
util
.
loadMimetypeList
()
self
.
assertEqual
s
(
mimetypes
.
types_map
.
get
(
".ogv"
),
"video/ogg"
)
self
.
assertEqual
s
(
mimetypes
.
types_map
.
get
(
".3gp"
),
"video/3gpp"
)
self
.
assertEqual
(
mimetypes
.
types_map
.
get
(
".ogv"
),
"video/ogg"
)
self
.
assertEqual
(
mimetypes
.
types_map
.
get
(
".3gp"
),
"video/3gpp"
)
cloudooo/handler/ooo/util.py
View file @
b2bf7ce9
...
...
@@ -40,7 +40,7 @@ def removeDirectory(path):
"""Remove directory"""
try
:
rmtree
(
path
)
except
OSError
,
msg
:
except
OSError
as
msg
:
logger
.
error
(
msg
)
...
...
@@ -50,8 +50,8 @@ def socketStatus(hostname, port):
socket
().
bind
((
hostname
,
port
),)
# False if the is free
return
False
except
error
,
(
num
,
err
)
:
if
num
==
EADDRINUSE
:
except
error
as
err
:
if
err
.
errno
==
EADDRINUSE
:
# True if the isn't free
return
True
...
...
@@ -79,5 +79,5 @@ def waitStopDaemon(daemon, attempts=5):
def
remove_file
(
filepath
):
try
:
remove
(
filepath
)
except
OSError
,
msg
:
print
msg
.
strerror
except
OSError
as
msg
:
print
(
msg
.
strerror
)
cloudooo/handler/pdf/tests/testPdfHandler.py
View file @
b2bf7ce9
...
...
@@ -51,9 +51,9 @@ class TestHandler(HandlerTestCase):
pdf_document
=
open
(
"data/test.pdf"
).
read
()
handler
=
Handler
(
self
.
tmp_url
,
pdf_document
,
"pdf"
,
**
self
.
kw
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
type
(
metadata
),
DictType
)
self
.
assertNotEqual
s
(
metadata
,
{})
self
.
assertEqual
s
(
metadata
[
"title"
],
'Free Cloud Alliance Presentation'
)
self
.
assertEqual
(
type
(
metadata
),
DictType
)
self
.
assertNotEqual
(
metadata
,
{})
self
.
assertEqual
(
metadata
[
"title"
],
'Free Cloud Alliance Presentation'
)
def
testsetMetadata
(
self
):
"""Test if the metadata is inserted correctly"""
...
...
@@ -63,8 +63,8 @@ class TestHandler(HandlerTestCase):
new_document
=
handler
.
setMetadata
(
metadata_dict
)
handler
=
Handler
(
self
.
tmp_url
,
new_document
,
"pdf"
,
**
self
.
kw
)
metadata
=
handler
.
getMetadata
()
self
.
assertEqual
s
(
metadata
[
"title"
],
'Set Metadata Test'
)
self
.
assertEqual
s
(
metadata
[
'creator'
],
'gabriel
\
'
@'
)
self
.
assertEqual
(
metadata
[
"title"
],
'Set Metadata Test'
)
self
.
assertEqual
(
metadata
[
'creator'
],
'gabriel
\
'
@'
)
def
testGetAllowedConversionFormatList
(
self
):
"""Test all combination of mimetype
...
...
@@ -73,10 +73,10 @@ class TestHandler(HandlerTestCase):
"""
get
=
Handler
.
getAllowedConversionFormatList
# Handled mimetypes
self
.
assertEqual
s
(
get
(
"application/pdf;ignored=param"
),
self
.
assertEqual
(
get
(
"application/pdf;ignored=param"
),
[(
"text/plain"
,
"Plain Text"
)])
# Unhandled mimetypes
self
.
assertEqual
s
(
get
(
"text/plain;ignored=param"
),
[])
self
.
assertEqual
s
(
get
(
"text/plain;charset=UTF-8;ignored=param"
),
[])
self
.
assertEqual
(
get
(
"text/plain;ignored=param"
),
[])
self
.
assertEqual
(
get
(
"text/plain;charset=UTF-8;ignored=param"
),
[])
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
View file @
b2bf7ce9
...
...
@@ -45,7 +45,7 @@ class TestHandler(HandlerTestCase):
pdf_file
=
handler
.
convert
(
"pdf"
,
**
conversion_kw
)
mime
=
magic
.
Magic
(
mime
=
True
)
pdf_mimetype
=
mime
.
from_buffer
(
pdf_file
)
self
.
assertEqual
s
(
"application/pdf"
,
pdf_mimetype
)
self
.
assertEqual
(
"application/pdf"
,
pdf_mimetype
)
def
testConvertHtmlWithPngDataUrlToPdf
(
self
):
"""Test conversion of html with png data url to pdf"""
...
...
@@ -86,9 +86,9 @@ class TestHandler(HandlerTestCase):
"""
get
=
Handler
.
getAllowedConversionFormatList
# Handled mimetypes
self
.
assertEqual
s
(
get
(
"text/html;ignored=param"
),
self
.
assertEqual
(
get
(
"text/html;ignored=param"
),
[(
"application/pdf"
,
"PDF - Portable Document Format"
)])
# Unhandled mimetypes
self
.
assertEqual
s
(
get
(
"application/pdf;ignored=param"
),
[])
self
.
assertEqual
(
get
(
"application/pdf;ignored=param"
),
[])
cloudooo/handler/x2t/tests/testX2tHandler.py
View file @
b2bf7ce9
...
...
@@ -89,7 +89,7 @@ class TestHandler(HandlerTestCase):
def
testgetMetadata
(
self
):
"""Test getMetadata from yformats"""
handler
=
Handler
(
self
.
tmp_url
,
""
,
"xlsy"
,
**
self
.
kw
)
self
.
assertEqual
s
(
handler
.
getMetadata
(),
{
self
.
assertEqual
(
handler
.
getMetadata
(),
{
u'CreationDate'
:
u'00/00/0000 00:00:00'
,
u'ImplementationName'
:
u'com.sun.star.comp.comphelper.OPropertyBag'
,
u'MIMEType'
:
u'text/plain'
,
...
...
@@ -98,7 +98,7 @@ class TestHandler(HandlerTestCase):
u'TemplateDate'
:
u'00/00/0000 00:00:00'
,
})
handler
=
Handler
(
self
.
tmp_url
,
open
(
"data/test_with_metadata.xlsy"
).
read
(),
"xlsy"
,
**
self
.
kw
)
self
.
assertEqual
s
(
handler
.
getMetadata
(),
{
self
.
assertEqual
(
handler
.
getMetadata
(),
{
u'CreationDate'
:
u'31/01/2018 21:09:10'
,
u'Keywords'
:
[
u'
\
u0442
\
u0435
\
u0441
\
u0442
'
,
u'
\
u0441
\
u0430
\
u0431
\
u0436
\
u0435
\
u043a
\
u0442
'
],
'MIMEType'
:
'application/x-asc-spreadsheet'
,
...
...
@@ -117,7 +117,7 @@ class TestHandler(HandlerTestCase):
"Keywords"
:
"test keywords"
,
})
handler
=
Handler
(
self
.
tmp_url
,
new_mime_data
,
"xlsy"
,
**
self
.
kw
)
self
.
assertEqual
s
(
handler
.
getMetadata
(),
{
u'Keywords'
:
u'test keywords'
,
'MIMEType'
:
'application/x-asc-spreadsheet'
,
u'Title'
:
u'test title'
,
u'Subject'
:
u'test subject'
})
self
.
assertEqual
(
handler
.
getMetadata
(),
{
u'Keywords'
:
u'test keywords'
,
'MIMEType'
:
'application/x-asc-spreadsheet'
,
u'Title'
:
u'test title'
,
u'Subject'
:
u'test subject'
})
def
testGetAllowedConversionFormatList
(
self
):
"""Test all combination of mimetype
...
...
@@ -125,13 +125,13 @@ class TestHandler(HandlerTestCase):
None of the types below define any mimetype parameter to not ignore so far.
"""
get
=
Handler
.
getAllowedConversionFormatList
self
.
assertEqual
s
(
get
(
"application/x-asc-text;ignored=param"
),
self
.
assertEqual
(
get
(
"application/x-asc-text;ignored=param"
),
[(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
,
"Word 2007 Document"
),
(
'application/vnd.oasis.opendocument.text'
,
'ODF Text Document'
)])
self
.
assertEqual
s
(
get
(
"application/x-asc-spreadsheet;ignored=param"
),
self
.
assertEqual
(
get
(
"application/x-asc-spreadsheet;ignored=param"
),
[(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
,
"Excel 2007 Spreadsheet"
),
(
'application/vnd.oasis.opendocument.spreadsheet'
,
'ODF Spreadsheet Document'
)])
self
.
assertEqual
s
(
get
(
"application/x-asc-presentation;ignored=param"
),
self
.
assertEqual
(
get
(
"application/x-asc-presentation;ignored=param"
),
[(
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
,
"PowerPoint 2007 Presentation"
),
(
'application/vnd.oasis.opendocument.presentation'
,
'ODF Presentation Document'
)])
cloudooo/manager.py
View file @
b2bf7ce9
...
...
@@ -274,7 +274,7 @@ class Manager(object):
response_dict
[
'mime'
]
=
response_dict
[
'meta'
][
'MIMEType'
]
del
response_dict
[
'meta'
][
'Data'
]
return
(
200
,
response_dict
,
""
)
except
Exception
,
e
:
except
Exception
as
e
:
import
traceback
;
logger
.
error
(
traceback
.
format_exc
())
return
(
402
,
{},
e
.
args
[
0
])
...
...
@@ -291,7 +291,7 @@ class Manager(object):
try
:
response_dict
[
'data'
]
=
self
.
updateFileMetadata
(
data
,
extension
,
meta
)
return
(
200
,
response_dict
,
''
)
except
Exception
,
e
:
except
Exception
as
e
:
import
traceback
;
logger
.
error
(
traceback
.
format_exc
())
return
(
402
,
{},
e
.
args
[
0
])
...
...
@@ -311,7 +311,7 @@ class Manager(object):
# we use 'Title'"
response_dict
[
'meta'
][
'title'
]
=
response_dict
[
'meta'
][
'Title'
]
return
(
200
,
response_dict
,
''
)
except
Exception
,
e
:
except
Exception
as
e
:
import
traceback
;
logger
.
error
(
'run_getmetadata: '
+
traceback
.
format_exc
())
return
(
402
,
{},
e
.
args
[
0
])
...
...
@@ -353,7 +353,7 @@ class Manager(object):
response_dict
[
'mime'
]
=
mimetypes
.
types_map
.
get
(
'.%s'
%
extension
,
mimetypes
.
types_map
.
get
(
'.%s'
%
extension
.
split
(
'.'
)[
-
1
]))
return
(
200
,
response_dict
,
""
)
except
Exception
,
e
:
except
Exception
as
e
:
import
traceback
;
logger
.
error
(
traceback
.
format_exc
())
return
(
402
,
response_dict
,
str
(
e
))
...
...
@@ -373,7 +373,7 @@ class Manager(object):
extension_list
.
append
((
ext
.
lstrip
(
'.'
),
t
))
response_dict
[
'response_data'
]
=
extension_list
return
(
200
,
response_dict
,
''
)
except
Exception
,
e
:
except
Exception
as
e
:
logger
.
error
(
e
)
return
(
402
,
{},
e
.
args
[
0
])
...
...
cloudooo/tests/backportUnittest.py
View file @
b2bf7ce9
...
...
@@ -123,11 +123,11 @@ class TestCase(unittest.TestCase):
success
=
False
try
:
self
.
setUp
()
except
SkipTest
,
e
:
except
SkipTest
as
e
:
result
.
addSkip
(
self
,
str
(
e
))
except
SetupSiteError
,
e
:
except
SetupSiteError
as
e
:
result
.
errors
.
append
(
None
)
except
BaseException
,
e
:
except
BaseException
as
e
:
result
.
addError
(
self
,
sys
.
exc_info
())
if
isinstance
(
e
,
(
KeyboardInterrupt
,
SystemExit
)):
raise
...
...
@@ -136,13 +136,13 @@ class TestCase(unittest.TestCase):
testMethod
()
except
self
.
failureException
:
result
.
addFailure
(
self
,
sys
.
exc_info
())
except
_ExpectedFailure
,
e
:
except
_ExpectedFailure
as
e
:
result
.
addExpectedFailure
(
self
,
e
.
exc_info
)
except
_UnexpectedSuccess
:
result
.
addUnexpectedSuccess
(
self
)
except
SkipTest
,
e
:
except
SkipTest
as
e
:
result
.
addSkip
(
self
,
str
(
e
))
except
BaseException
,
e
:
except
BaseException
as
e
:
result
.
addError
(
self
,
sys
.
exc_info
())
if
isinstance
(
e
,
(
KeyboardInterrupt
,
SystemExit
)):
raise
...
...
@@ -151,7 +151,7 @@ class TestCase(unittest.TestCase):
try
:
self
.
tearDown
()
except
BaseException
,
e
:
except
BaseException
as
e
:
result
.
addError
(
self
,
sys
.
exc_info
())
if
isinstance
(
e
,
(
KeyboardInterrupt
,
SystemExit
)):
raise
...
...
cloudooo/tests/cloudoooTestCase.py
View file @
b2bf7ce9
...
...
@@ -81,11 +81,11 @@ class TestCase(backportUnittest.TestCase):
zip
)
file_type
=
self
.
_getFileType
(
output_data
)
if
destination_mimetype
!=
None
:
self
.
assertEqual
s
(
file_type
,
destination_mimetype
)
self
.
assertEqual
(
file_type
,
destination_mimetype
)
else
:
if
file_type
.
endswith
(
": empty"
):
fault_list
.
append
((
source_format
,
destination_format
,
file_type
))
except
Fault
,
err
:
except
Fault
as
err
:
fault_list
.
append
((
source_format
,
destination_format
,
err
.
faultString
))
if
fault_list
:
template_message
=
'input_format: %r
\
n
output_format: %r
\
n
traceback:
\
n
%s'
...
...
@@ -106,7 +106,7 @@ class TestCase(backportUnittest.TestCase):
source_format
,
base_document
)
for
key
,
value
in
expected_metadata
.
iteritems
():
self
.
assertEqual
s
(
metadata_dict
[
key
],
value
)
self
.
assertEqual
(
metadata_dict
[
key
],
value
)
def
_testFaultGetMetadata
(
self
,
data
,
source_format
):
""" Generic test for fail converting"""
...
...
@@ -123,7 +123,7 @@ class TestCase(backportUnittest.TestCase):
source_format
,
False
)
for
key
,
value
in
metadata_dict
.
iteritems
():
self
.
assertEqual
s
(
new_metadata_dict
[
key
],
value
)
self
.
assertEqual
(
new_metadata_dict
[
key
],
value
)
def
_testRunConvert
(
self
,
filename
,
data
,
expected_response_code
,
response_dict_data
,
response_dict_keys
,
...
...
@@ -131,17 +131,17 @@ class TestCase(backportUnittest.TestCase):
"""Generic test for run_convert"""
response_code
,
response_dict
,
response_message
=
\
self
.
proxy
.
run_convert
(
filename
,
encodestring
(
data
))
self
.
assertEqual
s
(
response_code
,
expected_response_code
)
self
.
assertEqual
s
(
type
(
response_dict
),
DictType
)
self
.
assertEqual
(
response_code
,
expected_response_code
)
self
.
assertEqual
(
type
(
response_dict
),
DictType
)
if
expected_response_code
==
402
:
self
.
assertEqual
s
(
response_dict
,
{})
self
.
assertEqual
(
response_dict
,
{})
self
.
assertTrue
(
response_message
.
endswith
(
expected_response_message
),
"%s != %s"
%
(
response_message
,
expected_response_message
))
else
:
self
.
assertNotEqual
s
(
response_dict
[
'data'
],
response_dict_data
)
self
.
assertEqual
s
(
sorted
(
response_dict
.
keys
()),
response_dict_keys
)
self
.
assertEqual
s
(
response_message
,
expected_response_message
)
self
.
assertEqual
s
(
response_dict
[
'meta'
][
'MIMEType'
],
response_dict_meta
)
self
.
assertNotEqual
(
response_dict
[
'data'
],
response_dict_data
)
self
.
assertEqual
(
sorted
(
response_dict
.
keys
()),
response_dict_keys
)
self
.
assertEqual
(
response_message
,
expected_response_message
)
self
.
assertEqual
(
response_dict
[
'meta'
][
'MIMEType'
],
response_dict_meta
)
def
ConversionScenarioList
(
self
):
"""
...
...
cloudooo/tests/runTestSuite.py
View file @
b2bf7ce9
...
...
@@ -53,7 +53,7 @@ class TestSuite(BaseTestSuite):
'runUnitTest'
)
args
=
tuple
(
shlex
.
split
(
runUnitTest
))
+
args
status_dict
=
self
.
spawn
(
*
args
,
**
kw
)
except
SubprocessError
,
e
:
except
SubprocessError
as
e
:
status_dict
=
e
.
status_dict
test_log
=
status_dict
[
'stderr'
]
search
=
self
.
RUN_RE
.
search
(
test_log
)
...
...
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