Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cloudooo
Commits
0262a86d
Commit
0262a86d
authored
Jun 03, 2011
by
Priscila Manhaes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor to new methods from testcase
parent
396f5721
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
357 additions
and
350 deletions
+357
-350
cloudooo/handler/ooo/tests/testOooServer.py
cloudooo/handler/ooo/tests/testOooServer.py
+357
-350
No files found.
cloudooo/handler/ooo/tests/testOooServer.py
View file @
0262a86d
...
@@ -26,9 +26,11 @@
...
@@ -26,9 +26,11 @@
#
#
##############################################################################
##############################################################################
from
os.path
import
join
from
os.path
import
join
,
exists
import
datetime
from
os
import
remove
from
base64
import
encodestring
from
base64
import
encodestring
,
decodestring
from
types
import
DictType
from
zipfile
import
ZipFile
,
is_zipfile
from
cloudooo.tests.cloudoooTestCase
import
TestCase
,
make_suite
from
cloudooo.tests.cloudoooTestCase
import
TestCase
,
make_suite
...
@@ -43,7 +45,7 @@ class TestServer(TestCase):
...
@@ -43,7 +45,7 @@ class TestServer(TestCase):
[
'doc'
,
'Microsoft Word 97/2000/XP'
],
[
'doc'
,
'Microsoft Word 97/2000/XP'
],
[
'docx'
,
'Microsoft Word 2007 XML'
],
[
'docx'
,
'Microsoft Word 2007 XML'
],
[
'docx'
,
'Office Open XML Text'
],
[
'docx'
,
'Office Open XML Text'
],
[
'htm
l
'
,
'HTML Document (OpenOffice.org Writer)'
],
[
'htm'
,
'HTML Document (OpenOffice.org Writer)'
],
[
'html'
,
'HTML Document (Opeself.text_expected_listnOffice.org Writer)'
],
[
'html'
,
'HTML Document (Opeself.text_expected_listnOffice.org Writer)'
],
[
'html'
,
'XHTML'
],
[
'odt'
,
'ODF Text Document'
],
[
'html'
,
'XHTML'
],
[
'odt'
,
'ODF Text Document'
],
[
'ott'
,
'ODF Text Document Template'
],
[
'ott'
,
'ODF Text Document Template'
],
...
@@ -58,7 +60,7 @@ class TestServer(TestCase):
...
@@ -58,7 +60,7 @@ class TestServer(TestCase):
[
'emf'
,
'EMF - Enhanced Metafile'
],
[
'emf'
,
'EMF - Enhanced Metafile'
],
[
'eps'
,
'EPS - Encapsulated PostScript'
],
[
'eps'
,
'EPS - Encapsulated PostScript'
],
[
'gif'
,
'GIF - Graphics Interchange Format'
],
[
'gif'
,
'GIF - Graphics Interchange Format'
],
[
'htm
l
'
,
'HTML Document (OpenOffice.org Impress)'
],
[
'htm'
,
'HTML Document (OpenOffice.org Impress)'
],
[
'html'
,
'HTML Document (OpenOffice.org Impress)'
],
[
'html'
,
'HTML Document (OpenOffice.org Impress)'
],
[
'html'
,
'XHTML'
],
[
'jfif'
,
'JPEG - Joint Photographic Experts Group'
],
[
'html'
,
'XHTML'
],
[
'jfif'
,
'JPEG - Joint Photographic Experts Group'
],
[
'jif'
,
'JPEG - Joint Photographic Experts Group'
],
[
'jif'
,
'JPEG - Joint Photographic Experts Group'
],
...
@@ -91,144 +93,144 @@ class TestServer(TestCase):
...
@@ -91,144 +93,144 @@ class TestServer(TestCase):
self
.
text_expected_list
.
sort
()
self
.
text_expected_list
.
sort
()
self
.
presentation_expected_list
.
sort
()
self
.
presentation_expected_list
.
sort
()
#
def testGetAllowedTextExtensionListByType(self):
def
testGetAllowedTextExtensionListByType
(
self
):
#
"""Call getAllowedExtensionList and verify if the returns is a list with
"""Call getAllowedExtensionList and verify if the returns is a list with
#
extension and ui_name. The request is by document type as text"""
extension and ui_name. The request is by document type as text"""
#
text_request = {'document_type': "text"}
text_request
=
{
'document_type'
:
"text"
}
#
text_allowed_list = self.proxy.getAllowedExtensionList(text_request)
text_allowed_list
=
self
.
proxy
.
getAllowedExtensionList
(
text_request
)
#
text_allowed_list.sort()
text_allowed_list
.
sort
()
#
for arg in text_allowed_list:
for
arg
in
text_allowed_list
:
#
self.assertTrue(arg in self.text_expected_list,
self
.
assertTrue
(
arg
in
self
.
text_expected_list
,
#
"%s not in %s" % (arg, self.text_expected_list))
"%s not in %s"
%
(
arg
,
self
.
text_expected_list
))
#
def testGetAllowedPresentationExtensionListByType(self):
def
testGetAllowedPresentationExtensionListByType
(
self
):
#
"""Call getAllowedExtensionList and verify if the returns is a list with
"""Call getAllowedExtensionList and verify if the returns is a list with
#
extension and ui_name. The request is by document type as presentation"""
extension and ui_name. The request is by document type as presentation"""
#
request_dict = {'document_type': "presentation"}
request_dict
=
{
'document_type'
:
"presentation"
}
#
presentation_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
presentation_allowed_list
=
self
.
proxy
.
getAllowedExtensionList
(
request_dict
)
#
presentation_allowed_list.sort()
presentation_allowed_list
.
sort
()
#
for arg in presentation_allowed_list:
for
arg
in
presentation_allowed_list
:
#
self.assertTrue(arg in self.presentation_expected_list,
self
.
assertTrue
(
arg
in
self
.
presentation_expected_list
,
#
"%s not in %s" % (arg, self.presentation_expected_list))
"%s not in %s"
%
(
arg
,
self
.
presentation_expected_list
))
#
def testGetAllowedExtensionListByExtension(self):
def
testGetAllowedExtensionListByExtension
(
self
):
#
"""Call getAllowedExtensionList and verify if the returns is a list with
"""Call getAllowedExtensionList and verify if the returns is a list with
#
extension and ui_name. The request is by extension"""
extension and ui_name. The request is by extension"""
#
doc_allowed_list = self.proxy.getAllowedExtensionList({'extension': "doc"})
doc_allowed_list
=
self
.
proxy
.
getAllowedExtensionList
({
'extension'
:
"doc"
})
#
doc_allowed_list.sort()
doc_allowed_list
.
sort
()
#
for arg in doc_allowed_list:
for
arg
in
doc_allowed_list
:
#
self.assertTrue(arg in self.text_expected_list,
self
.
assertTrue
(
arg
in
self
.
text_expected_list
,
#
"%s not in %s" % (arg, self.text_expected_list))
"%s not in %s"
%
(
arg
,
self
.
text_expected_list
))
#
def testGetAllowedExtensionListByMimetype(self):
def
testGetAllowedExtensionListByMimetype
(
self
):
#
"""Call getAllowedExtensionList and verify if the returns is a list with
"""Call getAllowedExtensionList and verify if the returns is a list with
#
extension and ui_name. The request is by mimetype"""
extension and ui_name. The request is by mimetype"""
#
request_dict = {"mimetype": "application/msword"}
request_dict
=
{
"mimetype"
:
"application/msword"
}
#
msword_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
msword_allowed_list
=
self
.
proxy
.
getAllowedExtensionList
(
request_dict
)
#
msword_allowed_list.sort()
msword_allowed_list
.
sort
()
#
for arg in msword_allowed_list:
for
arg
in
msword_allowed_list
:
#
self.assertTrue(arg in self.text_expected_list,
self
.
assertTrue
(
arg
in
self
.
text_expected_list
,
#
"%s not in %s" % (arg, self.text_expected_list))
"%s not in %s"
%
(
arg
,
self
.
text_expected_list
))
#
def ConversionScenarioList(self):
def
ConversionScenarioList
(
self
):
#
return [
return
[
#
# Test Convert Doc -> Odt
# Test Convert Doc -> Odt
#
(join('data', 'test.doc'), "doc", "odt", "application/vnd.oasis."+
(
join
(
'data'
,
'test.doc'
),
"doc"
,
"odt"
,
"application/vnd.oasis."
+
#
"opendocument.text"),
"opendocument.text"
),
#
# Test export png to svg
# Test export png to svg
#
(join('data', 'test.png'), "png", "svg", "image/svg+xml"),
(
join
(
'data'
,
'test.png'
),
"png"
,
"svg"
,
"image/svg+xml"
),
#
# Test export docx to odt
# Test export docx to odt
#
(join('data', 'test.docx'), "docx", "odt", "application/vnd.oasis."+
(
join
(
'data'
,
'test.docx'
),
"docx"
,
"odt"
,
"application/vnd.oasis."
+
#
"opendocument.text"),
"opendocument.text"
),
#
# Test export python to pdf
# Test export python to pdf
#
(__file__, "py", "pdf", "application/pdf"),
(
__file__
,
"py"
,
"pdf"
,
"application/pdf"
),
#
# Test if send a zipfile returns a document correctly
# Test if send a zipfile returns a document correctly
#
(join('data', 'test.zip'), "zip", "txt", "application/zip", True),
(
join
(
'data'
,
'test.zip'
),
"zip"
,
"txt"
,
"application/zip"
,
True
),
#
# Convert compressed html to txt
# Convert compressed html to txt
#
(join('data', 'test.zip'), "zip", "txt", "text/plain"),
(
join
(
'data'
,
'test.zip'
),
"zip"
,
"txt"
,
"text/plain"
),
#
# Test export pptx to odp
# Test export pptx to odp
#
(join('data', 'test.pptx'), "pptx", "odp", "application/vnd.oasis."+
(
join
(
'data'
,
'test.pptx'
),
"pptx"
,
"odp"
,
"application/vnd.oasis."
+
#
"opendocument.presentation"),
"opendocument.presentation"
),
#
]
]
#
def testConvert(self):
def
testConvert
(
self
):
#
"""Convert OOofiles"""
"""Convert OOofiles"""
#
self.runConversionList(self.ConversionScenarioList())
self
.
runConversionList
(
self
.
ConversionScenarioList
())
#
def FaultConversionScenarioList(self):
def
FaultConversionScenarioList
(
self
):
#
return [
return
[
#
# Test to verify if server fail when a empty string is sent
# Test to verify if server fail when a empty string is sent
#
('', '', ''),
(
''
,
''
,
''
),
#
# Try convert one document for a invalid format
# Try convert one document for a invalid format
#
(open(join('data', 'test.doc')).read(), 'doc', 'xyz'),
(
open
(
join
(
'data'
,
'test.doc'
)).
read
(),
'doc'
,
'xyz'
),
#
# Try convert one document to format not possible
# Try convert one document to format not possible
#
(open(join('data', 'test.odp')).read(), 'odp', 'doc'),
(
open
(
join
(
'data'
,
'test.odp'
)).
read
(),
'odp'
,
'doc'
),
#
]
]
#
def testFaultConversion(self):
def
testFaultConversion
(
self
):
#
"""Convert Invalid OOofiles"""
"""Convert Invalid OOofiles"""
#
self.runFaultConversionList(self.FaultConversionScenarioList())
self
.
runFaultConversionList
(
self
.
FaultConversionScenarioList
())
#
def GetMetadataScenarioList(self):
def
GetMetadataScenarioList
(
self
):
#
return [
return
[
#
# Test method getFileMetadataItemList. Without data converted
# Test method getFileMetadataItemList. Without data converted
#
(join('data', 'testMetadata.odt'), "odt", dict(Data='', Title='clo'+
(
join
(
'data'
,
'testMetadata.odt'
),
"odt"
,
dict
(
Data
=
''
,
Title
=
'clo'
+
#
'udooo Test', Subject='Subject Test', Description='cloudooo Comments',
'udooo Test'
,
Subject
=
'Subject Test'
,
Description
=
'cloudooo Comments'
,
#
Type='Text', MIMEType='application/vnd.oasis.opendocument.text',
Type
=
'Text'
,
MIMEType
=
'application/vnd.oasis.opendocument.text'
,
#
ModifyDate='2/8/2010 9:57:3', Keywords='Keywords Test')),
ModifyDate
=
'2/8/2010 9:57:3'
,
Keywords
=
'Keywords Test'
)),
#
# Test method getFileMetadataItemList. With data converted
# Test method getFileMetadataItemList. With data converted
#
(join('data', 'testMetadata.odt'), "odt", dict(Title='cloudooo Test',
(
join
(
'data'
,
'testMetadata.odt'
),
"odt"
,
dict
(
Title
=
'cloudooo Test'
,
#
Subject='Subject Test', Description='cloudooo Comments',
Subject
=
'Subject Test'
,
Description
=
'cloudooo Comments'
,
#
Type='Text', MIMEType='application/vnd.oasis.opendocument.text',
Type
=
'Text'
,
MIMEType
=
'application/vnd.oasis.opendocument.text'
,
#
ModifyDate='2/8/2010 9:57:3', Keywords='Keywords Test'),
ModifyDate
=
'2/8/2010 9:57:3'
,
Keywords
=
'Keywords Test'
),
#
True),
True
),
#
]
]
#
def testGetMetadata(self):
def
testGetMetadata
(
self
):
#
"""test if OOo metadata are extracted correctly"""
"""test if OOo metadata are extracted correctly"""
#
self.runGetMetadataList(self.GetMetadataScenarioList())
self
.
runGetMetadataList
(
self
.
GetMetadataScenarioList
())
#
def FaultGetMetadataScenarioList(self):
def
FaultGetMetadataScenarioList
(
self
):
#
return [
return
[
#
# Test to verify if server fail when a empty string is sent
# Test to verify if server fail when a empty string is sent
#
('', ''),
(
''
,
''
),
#
]
]
#
def testFaultGetMetadata(self):
def
testFaultGetMetadata
(
self
):
#
"""getMetadata from invalid OOofiles"""
"""getMetadata from invalid OOofiles"""
#
self.runFaultGetMetadataList(self.FaultGetMetadataScenarioList())
self
.
runFaultGetMetadataList
(
self
.
FaultGetMetadataScenarioList
())
#
def UpdateMetadataScenarioList(self):
def
UpdateMetadataScenarioList
(
self
):
#
return [
return
[
#
# Test server using method updateFileMetadata
# Test server using method updateFileMetadata
#
(join('data', 'testMetadata.odt'), "odt", dict(Title='testSetMetadata')),
(
join
(
'data'
,
'testMetadata.odt'
),
"odt"
,
dict
(
Title
=
'testSetMetadata'
)),
#
# Test server using method updateFileMetadata with unsual metadata
# Test server using method updateFileMetadata with unsual metadata
#
(join('data', 'testMetadata.odt'), "odt", dict(Reference='testSet'+
(
join
(
'data'
,
'testMetadata.odt'
),
"odt"
,
dict
(
Reference
=
'testSet'
+
#
'Metadata')),
'Metadata'
)),
#
# Test document that already has metadata. Check if the metadata is
# Test document that already has metadata. Check if the metadata is
#
# not deleted, but updated
# not deleted, but updated
#
(join('data', 'testMetadata.odt'), "odt", dict(Title='cloudooo Title')),
(
join
(
'data'
,
'testMetadata.odt'
),
"odt"
,
dict
(
Title
=
'cloudooo Title'
)),
#
]
]
#
def testUpdateMetadata(self):
def
testUpdateMetadata
(
self
):
#
"""test if OOo metadata are insert correctly"""
"""test if OOo metadata are insert correctly"""
#
self.runUpdateMetadataList(self.UpdateMetadataScenarioList())
self
.
runUpdateMetadataList
(
self
.
UpdateMetadataScenarioList
())
#
def testupdateFileMetadataUpdateSomeMetadata(self):
def
testupdateFileMetadataUpdateSomeMetadata
(
self
):
#
"""Test server using method updateFileMetadata when the same metadata is
"""Test server using method updateFileMetadata when the same metadata is
#
updated"""
updated"""
#
odf_data = self.proxy.updateFileMetadata(encodestring(
odf_data
=
self
.
proxy
.
updateFileMetadata
(
encodestring
(
#
open(join('data', 'testMetadata.odt')).read()),
open
(
join
(
'data'
,
'testMetadata.odt'
)).
read
()),
#
'odt',
'odt'
,
#
dict(Reference="testSetMetadata", Something="ABC"))
dict
(
Reference
=
"testSetMetadata"
,
Something
=
"ABC"
))
#
new_odf_data = self.proxy.updateFileMetadata(odf_data,
new_odf_data
=
self
.
proxy
.
updateFileMetadata
(
odf_data
,
#
'odt',
'odt'
,
#
dict(Reference="new value", Something="ABC"))
dict
(
Reference
=
"new value"
,
Something
=
"ABC"
))
#
self.assertEquals(self._getFileType(new_odf_data),
self
.
assertEquals
(
self
.
_getFileType
(
new_odf_data
),
#
'application/vnd.oasis.opendocument.text')
'application/vnd.oasis.opendocument.text'
)
#
metadata_dict = self.proxy.getFileMetadataItemList(new_odf_data, 'odt')
metadata_dict
=
self
.
proxy
.
getFileMetadataItemList
(
new_odf_data
,
'odt'
)
#
self.assertEquals(metadata_dict.get("Reference"), "new value")
self
.
assertEquals
(
metadata_dict
.
get
(
"Reference"
),
"new value"
)
#
self.assertEquals(metadata_dict.get("Something"), "ABC")
self
.
assertEquals
(
metadata_dict
.
get
(
"Something"
),
"ABC"
)
def
ConvertScenarioList
(
self
):
def
ConvertScenarioList
(
self
):
return
[
return
[
...
@@ -246,213 +248,218 @@ class TestServer(TestCase):
...
@@ -246,213 +248,218 @@ class TestServer(TestCase):
"""Test run_convert method"""
"""Test run_convert method"""
self
.
runConvertScenarioList
(
self
.
ConvertScenarioList
())
self
.
runConvertScenarioList
(
self
.
ConvertScenarioList
())
# def testRunGenerateMethod(self):
def
GenerateScenarioList
(
self
):
# """Test run_generate method"""
return
[
# data = open(join('data', 'test.odt'), 'r').read()
# Test run_generate method with odt to pdf document
# generate_result = self.proxy.run_generate('test.odt',
(
'test.odt'
,
open
(
join
(
'data'
,
'test.odt'
)).
read
(),
None
,
# encodestring(data),
'application/vnd.oasis.opendocument.text'
,
'pdf'
,
200
,
''
,
# None, 'pdf',
'application/pdf'
),
# 'application/vnd.oasis.opendocument.text')
# XXX disable this test because LibreOffice 3.3 can open such a
# response_code, response_dict, response_message = generate_result
# broken document
# self.assertEquals(response_code, 200)
# Test run_generate method with invalid document
# self.assertEquals(type(response_dict), DictType)
(
'test.odt'
,
open
(
join
(
'data'
,
'test.odt'
)).
read
()[:
100
],
None
,
# self.assertNotEquals(response_dict['data'], '')
'application/vnd.oasis.opendocument.text'
,
'pdf'
,
402
,
''
,
None
),
# self.assertEquals(response_dict['mime'], 'application/pdf')
]
# def testRunGenerateMethodConvertOdsToHTML(self):
def
testRunGenerateMethod
(
self
):
# """Test run_generate method. This test is to validate a bug convertions to
"""Test run_generate method with ooo documents"""
# html"""
self
.
runGenerateScenarioList
(
self
.
GenerateScenarioList
())
# data = open(join('data', 'test.ods'), 'r').read()
# generate_result = self.proxy.run_generate('test.ods',
def
testRunGenerateMethodConvertOdsToHTML
(
self
):
# encodestring(data),
"""Test run_generate method. This test is to validate a bug convertions to
# None, 'html',
html"""
# "application/vnd.oasis.opendocument.spreadsheet")
generate_result
=
self
.
proxy
.
run_generate
(
'test.ods'
,
# response_code, response_dict, response_message = generate_result
encodestring
(
# self.assertEquals(response_code, 200)
open
(
join
(
'data'
,
'test.ods'
)).
read
()),
# self.assertEquals(type(response_dict), DictType)
None
,
'html'
,
# self.assertNotEquals(response_dict['data'], '')
"application/vnd.oasis.opendocument.spreadsheet"
)
# self.assertEquals(response_dict['mime'], 'application/zip')
response_code
,
response_dict
,
response_message
=
generate_result
# output_url = join(self.tmp_url, "zip.zip")
self
.
assertEquals
(
response_code
,
200
)
# open(output_url, 'w').write(decodestring(response_dict['data']))
self
.
assertEquals
(
type
(
response_dict
),
DictType
)
# self.assertTrue(is_zipfile(output_url))
self
.
assertNotEquals
(
response_dict
[
'data'
],
''
)
# filename_list = [file.filename for file in ZipFile(output_url).filelist]
self
.
assertEquals
(
response_dict
[
'mime'
],
'application/zip'
)
# for filename in filename_list:
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
# if filename.endswith("impr.html"):
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
# break
self
.
assertTrue
(
is_zipfile
(
output_url
))
# else:
filename_list
=
[
file
.
filename
for
file
in
ZipFile
(
output_url
).
filelist
]
# self.fail("Not exists one file with 'impr.html' format")
for
filename
in
filename_list
:
# if exists(output_url):
if
filename
.
endswith
(
"impr.html"
):
# remove(output_url)
break
else
:
# def testPNGFileToConvertOdpToHTML(self):
self
.
fail
(
"Not exists one file with 'impr.html' format"
)
# """Test run_generate method. This test if returns good png files"""
if
exists
(
output_url
):
# data = open(join('data', 'test_png.odp'), 'r').read()
remove
(
output_url
)
# generate_result = self.proxy.run_generate('test_png.odp',
# encodestring(data),
def
testPNGFileToConvertOdpToHTML
(
self
):
# None, 'html',
"""Test run_generate method. This test if returns good png files"""
# 'application/vnd.oasis.opendocument.presentation')
generate_result
=
self
.
proxy
.
run_generate
(
'test_png.odp'
,
# response_code, response_dict, response_message = generate_result
encodestring
(
# self.assertEquals(response_code, 200)
open
(
join
(
'data'
,
'test_png.odp'
)).
read
()),
# self.assertEquals(type(response_dict), DictType)
None
,
'html'
,
# self.assertNotEquals(response_dict['data'], '')
'application/vnd.oasis.opendocument.presentation'
)
# self.assertEquals(response_dict['mime'], 'application/zip')
response_code
,
response_dict
,
response_message
=
generate_result
# output_url = join(self.tmp_url, "zip.zip")
self
.
assertEquals
(
response_code
,
200
)
# open(output_url, 'w').write(decodestring(response_dict['data']))
self
.
assertEquals
(
type
(
response_dict
),
DictType
)
# self.assertTrue(is_zipfile(output_url))
self
.
assertNotEquals
(
response_dict
[
'data'
],
''
)
# zipfile = ZipFile(output_url)
self
.
assertEquals
(
response_dict
[
'mime'
],
'application/zip'
)
# try:
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
# png_path = join(self.tmp_url, "img0.png")
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
# zipfile.extractall(self.tmp_url)
self
.
assertTrue
(
is_zipfile
(
output_url
))
# content_type = self._getFileType(png_path)
zipfile
=
ZipFile
(
output_url
)
# self.assertEquals(content_type, 'image/png')
try
:
# m = magic.Magic()
png_path
=
join
(
self
.
tmp_url
,
"img0.png"
)
# self.assertTrue("8-bit/color RGB" in m.from_file(png_path))
zipfile
.
extractall
(
self
.
tmp_url
)
# finally:
content_type
=
self
.
_getFileType
(
png_path
)
# zipfile.close()
self
.
assertEquals
(
content_type
,
'image/png'
)
# if exists(output_url):
m
=
magic
.
Magic
()
# remove(output_url)
self
.
assertTrue
(
"8-bit/color RGB"
in
m
.
from_file
(
png_path
))
finally
:
# def testRunGenerateMethodConvertOdpToHTML(self):
zipfile
.
close
()
# """Test run_generate method. This test is to validate a bug convertions to
if
exists
(
output_url
):
# html"""
remove
(
output_url
)
# data = open(join('data', 'test.odp'), 'r').read()
# generate_result = self.proxy.run_generate('test.odp',
def
testRunGenerateMethodConvertOdpToHTML
(
self
):
# encodestring(data),
"""Test run_generate method. This test is to validate a bug convertions to
# None, 'html',
html"""
# 'application/vnd.oasis.opendocument.presentation')
generate_result
=
self
.
proxy
.
run_generate
(
'test.odp'
,
# response_code, response_dict, response_message = generate_result
encodestring
(
# self.assertEquals(response_code, 200)
open
(
join
(
'data'
,
'test.odp'
)).
read
()),
# self.assertEquals(type(response_dict), DictType)
None
,
'html'
,
# self.assertNotEquals(response_dict['data'], '')
'application/vnd.oasis.opendocument.presentation'
)
# self.assertEquals(response_dict['mime'], 'application/zip')
response_code
,
response_dict
,
response_message
=
generate_result
# output_url = join(self.tmp_url, "zip.zip")
self
.
assertEquals
(
response_code
,
200
)
# open(output_url, 'w').write(decodestring(response_dict['data']))
self
.
assertEquals
(
type
(
response_dict
),
DictType
)
# self.assertTrue(is_zipfile(output_url))
self
.
assertNotEquals
(
response_dict
[
'data'
],
''
)
# filename_list = [file.filename for file in ZipFile(output_url).filelist]
self
.
assertEquals
(
response_dict
[
'mime'
],
'application/zip'
)
# for filename in filename_list:
output_url
=
join
(
self
.
tmp_url
,
"zip.zip"
)
# if filename.endswith("impr.html"):
open
(
output_url
,
'w'
).
write
(
decodestring
(
response_dict
[
'data'
]))
# break
self
.
assertTrue
(
is_zipfile
(
output_url
))
# else:
filename_list
=
[
file
.
filename
for
file
in
ZipFile
(
output_url
).
filelist
]
# self.fail("Not exists one file with 'impr.html' format")
for
filename
in
filename_list
:
if
filename
.
endswith
(
"impr.html"
):
# # XXX disable this test because LibreOffice 3.3 can open such a broken
break
# # document.
else
:
# def _testRunGenerateMethodFailResponse(self):
self
.
fail
(
"Not exists one file with 'impr.html' format"
)
# """Test run_generate method with invalid document"""
if
exists
(
output_url
):
# data = open(join('data', 'test.odt'), 'r').read()[:100]
remove
(
output_url
)
# generate_result = self.proxy.run_generate('test.odt',
# encodestring(data),
def
testRunSetMetadata
(
self
):
# None, 'pdf', 'application/vnd.oasis.opendocument.text')
"""Test run_setmetadata method, updating the same metadata"""
# response_code, response_dict, response_message = generate_result
setmetadata_result
=
self
.
proxy
.
run_setmetadata
(
'testMetadata.odt'
,
# self.assertEquals(response_code, 402)
encodestring
(
# self.assertEquals(type(response_dict), DictType)
open
(
join
(
'data'
,
'testMetadata.odt'
)).
read
()),
# self.assertEquals(response_dict, {})
{
"Title"
:
"testSetMetadata"
,
"Description"
:
"Music"
})
# self.assertTrue(response_message.startswith('Traceback'))
response_code
,
response_dict
,
response_message
=
setmetadata_result
self
.
assertEquals
(
response_code
,
200
)
# def testRunSetMetadata(self):
new_data
=
response_dict
[
'data'
]
# """Test run_setmetadata method"""
self
.
assertNotEquals
(
new_data
,
''
)
# data = open(join('data', 'testMetadata.odt'), 'r').read()
getmetadata_result
=
self
.
proxy
.
run_getmetadata
(
'testMetadata.odt'
,
# setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
new_data
)
# encodestring(data),
response_code
,
response_dict
,
response_message
=
getmetadata_result
# {"Title": "testSetMetadata", "Description": "Music"})
self
.
assertEquals
(
response_code
,
200
)
# response_code, response_dict, response_message = setmetadata_result
self
.
assertEquals
(
response_dict
[
'meta'
][
'MIMEType'
],
# self.assertEquals(response_code, 200)
'application/vnd.oasis.opendocument.text'
)
# self.assertNotEquals(response_dict['data'], '')
self
.
assertEquals
(
response_dict
[
'meta'
][
'Description'
],
"Music"
)
# getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt',
setmetadata_result
=
self
.
proxy
.
run_setmetadata
(
'testMetadata.odt'
,
# response_dict['data'])
new_data
,
# response_code, response_dict, response_message = getmetadata_result
{
"Title"
:
"Namie's working record"
,
# self.assertEquals(response_code, 200)
"Description"
:
"Music"
})
# self.assertEquals(response_dict['meta']['MIMEType'],
response_code
,
response_dict
,
response_message
=
setmetadata_result
# 'application/vnd.oasis.opendocument.text')
getmetadata_result
=
self
.
proxy
.
run_getmetadata
(
'testMetadata.odt'
,
# self.assertEquals(response_dict['meta']['Description'], "Music")
response_dict
[
'data'
])
# setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
response_code
,
response_dict
,
response_message
=
getmetadata_result
# encodestring(data),
self
.
assertEquals
(
response_code
,
200
)
# {"Title": "Namie's working record",
self
.
assertEquals
(
response_dict
[
'meta'
][
'title'
],
# "Description": "Music"})
"Namie's working record"
)
# response_code, response_dict, response_message = setmetadata_result
# getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt',
def
testRunSetMetadataFailResponse
(
self
):
# response_dict['data'])
"""Test run_setmetadata method with invalid document"""
# response_code, response_dict, response_message = getmetadata_result
setmetadata_result
=
self
.
proxy
.
run_setmetadata
(
'testMetadata.odt'
,
# self.assertEquals(response_code, 200)
encodestring
(
# self.assertEquals(response_dict['meta']['title'],
open
(
join
(
'data'
,
'testMetadata.odt'
)).
read
()[:
100
]),
# "Namie's working record")
{
"Title"
:
"testSetMetadata"
,
"Description"
:
"Music"
})
response_code
,
response_dict
,
response_message
=
setmetadata_result
# def testRunSetMetadataFailResponse(self):
self
.
assertEquals
(
response_code
,
402
)
# """Test run_setmetadata method with invalid document"""
self
.
assertEquals
(
response_dict
,
{})
# data = open(join('data', 'testMetadata.odt'), 'r').read()[:100]
self
.
assertTrue
(
response_message
.
startswith
(
'Traceback'
))
# setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
# encodestring(data),
def
testGetAllowedTargetItemList
(
self
):
# {"Title": "testSetMetadata", "Description": "Music"})
"""Test if filter name returns correctly with ERP5 API"""
# response_code, response_dict, response_message = setmetadata_result
mimetype
=
'application/vnd.oasis.opendocument.text'
# self.assertEquals(response_code, 402)
response_code
,
response_dict
,
response_message
=
\
# self.assertEquals(response_dict, {})
self
.
proxy
.
getAllowedTargetItemList
(
mimetype
)
# self.assertTrue(response_message.startswith('Traceback'))
self
.
assertEquals
(
response_code
,
200
)
self
.
assertEquals
(
len
(
response_dict
[
'response_data'
]),
17
)
# def testGetAllowedTargetItemList(self):
self
.
assertTrue
([
'html'
,
'HTML Document (OpenOffice.org Writer)'
]
in
response_dict
[
'response_data'
])
# """Test if filter name returns correctly with ERP5 API"""
self
.
assertFalse
([
'html'
,
'HTML Document'
]
in
response_dict
[
'response_data'
])
# mimetype = 'application/vnd.oasis.opendocument.text'
# response_code, response_dict, response_message = \
def
testGetTableItemListFromOdt
(
self
):
# self.proxy.getAllowedTargetItemList(mimetype)
"""Test if manager can get the table item list from odt file"""
# self.assertEquals(response_code, 200)
table_list
=
[[
'Developers'
,
''
],
# self.assertEquals(len(response_dict['response_data']), 17)
[
'Prices'
,
'Table 1: Prices table from Mon Restaurant'
],
# self.assertTrue(['html', 'HTML Document (OpenOffice.org Writer)'] in response_dict['response_data'])
[
'SoccerTeams'
,
'Tabela 2: Soccer Teams'
]]
# self.assertFalse(['html', 'HTML Document'] in response_dict['response_data'])
granulated_table
=
self
.
proxy
.
getTableItemList
(
encodestring
(
open
(
"data/granulate_table_test.odt"
).
read
()),
# def testGetTableItemList(self):
"odt"
)
# """Test if manager can get the table item list"""
self
.
assertEquals
(
table_list
,
granulated_table
)
# table_list = [['Developers', ''],
# ['Prices', 'Table 1: Prices table from Mon Restaurant'],
def
testGetTableItemListFromDoc
(
self
):
# ['SoccerTeams', 'Tabela 2: Soccer Teams']]
"""Test if manager can get the table item list from doc file"""
# data = encodestring(open("data/granulate_table_test.odt").read())
table_list
=
[[
'Table1'
,
''
],
# granulated_table = self.proxy.getTableItemList(data, "odt")
[
'Table2'
,
'Table 1: Prices table from Mon Restaurant'
],
# self.assertEquals(table_list, granulated_table)
[
'Table3'
,
'Tabela 2: Soccer Teams'
]]
# #.doc
granulated_table
=
self
.
proxy
.
getTableItemList
(
# table_list = [['Table1', ''],
encodestring
(
open
(
"data/granulate_table_test.doc"
).
read
()),
# ['Table2', 'Table 1: Prices table from Mon Restaurant'],
"doc"
)
# ['Table3', 'Tabela 2: Soccer Teams']]
self
.
assertEquals
(
table_list
,
granulated_table
)
# data = encodestring(open("data/granulate_table_test.doc").read())
# granulated_table = self.proxy.getTableItemList(data, "doc")
def
testGetTableFromOdt
(
self
):
# self.assertEquals(table_list, granulated_table)
"""Test if manager can get a item of some granulated table from odt file"""
data
=
encodestring
(
open
(
"./data/granulate_table_test.odt"
).
read
())
# def testGetTable(self):
granulated_table
=
self
.
proxy
.
getTableItemList
(
data
,
"odt"
)
# """Test if manager can get a item of some granulated table"""
table_item
=
decodestring
(
self
.
proxy
.
getTable
(
data
,
granulated_table
[
1
][
0
],
# data = encodestring(open("./data/granulate_table_test.odt").read())
"odt"
))
# granulated_table = self.proxy.getTableItemList(data, "odt")
content_xml_str
=
ZipFile
(
StringIO
(
table_item
)).
read
(
'content.xml'
)
# table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0],
content_xml
=
etree
.
fromstring
(
content_xml_str
)
# "odt"))
table_list
=
content_xml
.
xpath
(
'//table:table'
,
# content_xml_str = ZipFile(StringIO(table_item)).read('content.xml')
namespaces
=
content_xml
.
nsmap
)
# content_xml = etree.fromstring(content_xml_str)
self
.
assertEquals
(
1
,
len
(
table_list
))
# table_list = content_xml.xpath('//table:table',
table
=
table_list
[
0
]
# namespaces=content_xml.nsmap)
name_key
=
'{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
# self.assertEquals(1, len(table_list))
self
.
assertEquals
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
# table = table_list[0]
# name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
def
testGetTableFromDoc
(
self
):
# self.assertEquals(granulated_table[1][0], table.attrib[name_key])
"""Test if manager can get a item of some granulated table from doc file"""
# #.doc
data
=
encodestring
(
open
(
"./data/granulate_table_test.doc"
).
read
())
# data = encodestring(open("./data/granulate_table_test.doc").read())
granulated_table
=
self
.
proxy
.
getTableItemList
(
data
,
"doc"
)
# granulated_table = self.proxy.getTableItemList(data, "doc")
self
.
proxy
.
getTable
(
data
,
granulated_table
[
1
][
0
],
"doc"
)
# self.proxy.getTable(data, granulated_table[1][0], "doc")
table_item
=
decodestring
(
self
.
proxy
.
getTable
(
data
,
granulated_table
[
1
][
0
],
# table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0],
"doc"
))
# "doc"))
content_xml_str
=
ZipFile
(
StringIO
(
table_item
)).
read
(
'content.xml'
)
# content_xml_str = ZipFile(StringIO(table_item)).read('content.xml')
content_xml
=
etree
.
fromstring
(
content_xml_str
)
# content_xml = etree.fromstring(content_xml_str)
table_list
=
content_xml
.
xpath
(
'//table:table'
,
# table_list = content_xml.xpath('//table:table',
namespaces
=
content_xml
.
nsmap
)
# namespaces=content_xml.nsmap)
self
.
assertEquals
(
1
,
len
(
table_list
))
# self.assertEquals(1, len(table_list))
table
=
table_list
[
0
]
# table = table_list[0]
name_key
=
'{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
# name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self
.
assertEquals
(
granulated_table
[
1
][
0
],
table
.
attrib
[
name_key
])
# self.assertEquals(granulated_table[1][0], table.attrib[name_key])
def
testGetColumnItemListFromOdt
(
self
):
# def testGetColumnItemList(self):
"""Test if manager can get the list of column item from odt file"""
# """Test if manager can get the list of column item"""
columns
=
self
.
proxy
.
getColumnItemList
(
# data = encodestring(open("./data/granulate_table_test.odt").read())
encodestring
(
open
(
"./data/granulate_table_test.odt"
).
read
()),
# columns = self.proxy.getColumnItemList(data, "SoccerTeams", "odt")
"SoccerTeams"
,
# self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
"odt"
)
# #.doc
self
.
assertEquals
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
# data = encodestring(open("./data/granulate_table_test.doc").read())
# #in the doc format the tables lose their names
def
testGetColumnItemListFromDoc
(
self
):
# columns = self.proxy.getColumnItemList(data, "Table3", "doc")
"""Test if manager can get the list of column item from doc file"""
# self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
#in the doc format the tables lose their names
columns
=
self
.
proxy
.
getColumnItemList
(
encodestring
(
open
(
"./data/granulate_table_test.doc"
).
read
()),
"Table3"
,
"doc"
)
self
.
assertEquals
([[
0
,
'Name'
],
[
1
,
'Country'
]],
columns
)
# def testGetLineItemList(self):
# def testGetLineItemList(self):
# """Test if manager can get the list of lines items"""
# """Test if manager can get the list of lines items"""
...
...
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