Commit 30c8240a authored by Priscila Manhaes's avatar Priscila Manhaes

refactor for using cloudoootestcase into convert, getMetadata, updateMetadata,...

refactor for using cloudoootestcase into convert, getMetadata, updateMetadata, fault conversions, but still missig some tests
parent 53bb0a8d
...@@ -26,628 +26,521 @@ ...@@ -26,628 +26,521 @@
# #
############################################################################## ##############################################################################
from os.path import join, exists from os.path import join
from os import remove import datetime
from xmlrpclib import ServerProxy, Fault from cloudooo.tests.cloudoooTestCase import TestCase, make_suite
from base64 import encodestring, decodestring
from cloudooo.tests.handlerTestCase import HandlerTestCase, make_suite
from zipfile import ZipFile, is_zipfile
from StringIO import StringIO
from lxml import etree
from types import DictType
import magic
DAEMON = True class TestServer(TestCase):
class TestServer(HandlerTestCase):
"""Test XmlRpc Server. Needs cloudooo server started""" """Test XmlRpc Server. Needs cloudooo server started"""
def afterSetUp(self): # def ConversionScenarioList(self):
"""Creates a connection with cloudooo server""" # return [
self.proxy = ServerProxy("http://%s:%s/RPC2" % \ # # Test Convert Doc -> Odt
(self.hostname, self.cloudooo_port), allow_none=True) # (join('data', 'test.doc'), "doc", "odt", "application/vnd.oasis."+
# "opendocument.text"),
# XXX Duplicated list of filters # # Test export png to svg
self.text_expected_list = [['doc', 'Microsoft Word 6.0'], # (join('data', 'test.png'), "png", "svg", "image/svg+xml"),
['doc', 'Microsoft Word 95'], # # Test export docx to odt
['doc', 'Microsoft Word 97/2000/XP'], # (join('data', 'test.docx'), "docx", "odt", "application/vnd.oasis."+
['docx', 'Microsoft Word 2007 XML'], # "opendocument.text"),
['docx', 'Office Open XML Text'], # # Test export python to pdf
['htm', 'HTML Document (OpenOffice.org Writer)'], # (__file__, "py", "pdf", "application/pdf"),
['html', 'HTML Document (OpenOffice.org Writer)'], # # Test if send a zipfile returns a document correctly
['html', 'XHTML'], ['odt', 'ODF Text Document'], # (join('data', 'test.zip'), "zip", "txt", "application/zip", True),
['ott', 'ODF Text Document Template'], # # Convert compressed html to txt
['pdf', 'PDF - Portable Document Format'], # (join('data', 'test.zip'), "zip", "txt", "text/plain"),
['rtf', 'Rich Text Format'], ['sdw', 'StarWriter 3.0'], # # Test export pptx to odp
['sdw', 'StarWriter 4.0'], ['sdw', 'StarWriter 5.0'], # (join('data', 'test.pptx'), "pptx", "odp", "application/vnd.oasis."+
['sxw', 'OpenOffice.org 1.0 Text Document'], # "opendocument.presentation"),
['txt', 'Text'], ['txt', 'Text Encoded'], # ]
['xhtml', 'XHTML'], ['pdb', 'AportisDoc (Palm)'],
['psw', 'Pocket Word']] # def testConvert(self):
# """Convert OOofiles"""
self.text_expected_list.sort() # self.runConversionList(self.ConversionScenarioList())
self.presentation_expected_list = [['bmp', 'BMP - Windows Bitmap'], # def FaultConversionScenarioList(self):
['emf', 'EMF - Enhanced Metafile'], # return [
['eps', 'EPS - Encapsulated PostScript'], # # Test to verify if server fail when a empty string is sent
['gif', 'GIF - Graphics Interchange Format'], # ('', '', ''),
['htm', 'HTML Document (OpenOffice.org Impress)'], # # Try convert one document for a invalid format
['html', 'HTML Document (OpenOffice.org Impress)'], # (open(join('data', 'test.doc')).read(), 'doc', 'xyz'),
['html', 'XHTML'], ['jfif', 'JPEG - Joint Photographic Experts Group'], # # Try convert one document to format not possible
['jif', 'JPEG - Joint Photographic Experts Group'], # (open(join('data', 'test.odp')).read(), 'odp', 'doc'),
['jpe', 'JPEG - Joint Photographic Experts Group'], # ]
['jpeg', 'JPEG - Joint Photographic Experts Group'],
['jpg', 'JPEG - Joint Photographic Experts Group'], # def testFaultConversion(self):
['met', 'MET - OS/2 Metafile'], ['odg', 'ODF Drawing (Impress)'], # """Convert Invalid OOofiles"""
['odp', 'ODF Presentation'], # self.runFaultConversionList(self.FaultConversionScenarioList())
['otp', 'ODF Presentation Template'],
['pbm', 'PBM - Portable Bitmap'], ['pct', 'PCT - Mac Pict'], def GetMetadataScenarioList(self):
['pdf', 'PDF - Portable Document Format'], return [
['pgm', 'PGM - Portable Graymap'], ['pict', 'PCT - Mac Pict'], # Test method getFileMetadataItemList. Without data converted
['png', 'PNG - Portable Network Graphic'], (join('data', 'testMetadata.odt'), "odt", dict(Data='', Title='clo'+
['pot', 'Microsoft PowerPoint 97/2000/XP Template'], 'udooo Test', Subject='Subject Test', Description='cloudooo Comments',
['ppm', 'PPM - Portable Pixelmap'], Type='Text', MIMEType='application/vnd.oasis.opendocument.text',
['pps', 'Microsoft PowerPoint 97/2000/XP'], ModifyDate='2/8/2010 9:57:3', Keywords='Keywords Test')),
['ppt', 'Microsoft PowerPoint 97/2000/XP'], # # Test method getFileMetadataItemList. With data converted
['ras', 'RAS - Sun Raster Image'], # (join('data', 'testMetadata.odt'), "odt", dict(Title='cloudooo Test',
['sda', 'StarDraw 5.0 (OpenOffice.org Impress)'], # Subject='Subject Test', Description='cloudooo Comments',
['sdd', 'StarDraw 3.0 (OpenOffice.org Impress)'], # Type='Text', MIMEType='application/vnd.oasis.opendocument.text',
['sdd', 'StarImpress 4.0'], ['sdd', 'StarImpress 5.0'], # ModifyDate='2/8/2010 9:57:3', Keywords='Keywords Test'),
['svg', 'SVG - Scalable Vector Graphics'], # True),
['svm', 'SVM - StarView Metafile'], ]
['sxd', 'OpenOffice.org 1.0 Drawing (OpenOffice.org Impress)'],
['sxi', 'OpenOffice.org 1.0 Presentation'], def testGetMetadata(self):
['tif', 'TIFF - Tagged Image File Format'], """test if OOo metadata are extracted correctly"""
['tiff', 'TIFF - Tagged Image File Format'], self.runGetMetadataList(self.GetMetadataScenarioList())
['wmf', 'WMF - Windows Metafile'],
['xhtml', 'XHTML'], ['xpm', 'XPM - X PixMap']] def UpdateMetadataScenarioList(self):
return [
self.presentation_expected_list.sort() # Test server using method updateFileMetadata
(join('data', 'testMetadata.odt'), "odt", dict(Title='testSetMetadata')),
def _testConvertFile(self, input_url, output_url, # Test server using method updateFileMetadata with unsual metadata
source_format, destination_format, # (join('data', 'testMetadata.odt'), "odt", dict(Reference='testSet'+
stdout_msg, zip=False): # 'Metadata')),
"""Generic test to use convertFile""" # # Test document that already has metadata. Check if the metadata is
data = encodestring(open(input_url).read()) # # not deleted, but updated
output_data = self.proxy.convertFile(data, # (join('data', 'testMetadata.odt'), "odt", dict(Title='cloudooo Title')),
source_format, ]
destination_format, zip)
open(output_url, 'w').write(decodestring(output_data)) def testUpdateMetadata(self):
content_type = self._getFileType(output_url) """test if OOo metadata are insert correctly"""
self.assertEquals(content_type, stdout_msg) self.runUpdateMetadataList(self.UpdateMetadataScenarioList())
def _getFileType(self, output_url):
mime = magic.Magic(mime=True) # def testupdateFileMetadataUpdateSomeMetadata(self):
return mime.from_file(output_url) # """Test server using method updateFileMetadata when the same metadata is
# updated"""
def testGetAllowedExtensionListByType(self): # document_output_url = join(self.tmp_url, "testSetMetadata.odt")
"""Call getAllowedExtensionList and verify if the returns is a list with # data = open(join('data', 'testMetadata.odt'), 'r').read()
extension and ui_name. The request is by document type""" # odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt',
text_request = {'document_type': "text"} # {"Reference": "testSetMetadata", "Something": "ABC"})
text_allowed_list = self.proxy.getAllowedExtensionList(text_request) # new_odf_data = self.proxy.updateFileMetadata(odf_data, 'odt',
text_allowed_list.sort() # {"Reference": "new value", "Something": "ABC"})
for arg in text_allowed_list: # open(document_output_url, 'w').write(decodestring(new_odf_data))
self.assertTrue(arg in self.text_expected_list, # content_type = self._getFileType(document_output_url)
"%s not in %s" % (arg, self.text_expected_list)) # self.assertEquals(content_type, 'application/vnd.oasis.opendocument.text')
request_dict = {'document_type': "presentation"} # metadata_dict = self.proxy.getFileMetadataItemList(new_odf_data, 'odt')
presentation_allowed_list = self.proxy.getAllowedExtensionList(request_dict) # self.assertEquals(metadata_dict.get("Reference"), "new value")
presentation_allowed_list.sort() # self.assertEquals(metadata_dict.get("Something"), "ABC")
for arg in presentation_allowed_list:
self.assertTrue(arg in self.presentation_expected_list,
"%s not in %s" % (arg, self.presentation_expected_list)) # # XXX Duplicated list of filters
# self.text_expected_list = [['doc', 'Microsoft Word 6.0'],
def testGetAllowedExtensionListByExtension(self): # ['doc', 'Microsoft Word 95'],
"""Call getAllowedExtensionList and verify if the returns is a list with # ['doc', 'Microsoft Word 97/2000/XP'],
extension and ui_name. The request is by extension""" # ['docx', 'Microsoft Word 2007 XML'],
doc_allowed_list = self.proxy.getAllowedExtensionList({'extension': "doc"}) # ['docx', 'Office Open XML Text'],
doc_allowed_list.sort() # ['htm', 'HTML Document (OpenOffice.org Writer)'],
for arg in doc_allowed_list: # ['html', 'HTML Document (OpenOffice.org Writer)'],
self.assertTrue(arg in self.text_expected_list, # ['html', 'XHTML'], ['odt', 'ODF Text Document'],
"%s not in %s" % (arg, self.text_expected_list)) # ['ott', 'ODF Text Document Template'],
# ['pdf', 'PDF - Portable Document Format'],
def testGetAllowedExtensionListByMimetype(self): # ['rtf', 'Rich Text Format'], ['sdw', 'StarWriter 3.0'],
"""Call getAllowedExtensionList and verify if the returns is a list with # ['sdw', 'StarWriter 4.0'], ['sdw', 'StarWriter 5.0'],
extension and ui_name. The request is by mimetype""" # ['sxw', 'OpenOffice.org 1.0 Text Document'],
request_dict = {"mimetype": "application/msword"} # ['txt', 'Text'], ['txt', 'Text Encoded'],
msword_allowed_list = self.proxy.getAllowedExtensionList(request_dict) # ['xhtml', 'XHTML'], ['pdb', 'AportisDoc (Palm)'],
msword_allowed_list.sort() # ['psw', 'Pocket Word']]
for arg in msword_allowed_list:
self.assertTrue(arg in self.text_expected_list, # self.text_expected_list.sort()
"%s not in %s" % (arg, self.text_expected_list))
# self.presentation_expected_list = [['bmp', 'BMP - Windows Bitmap'],
def testConvertDocToOdt(self): # ['emf', 'EMF - Enhanced Metafile'],
"""Test Convert Doc -> Odt""" # ['eps', 'EPS - Encapsulated PostScript'],
self._testConvertFile("data/test.doc", # ['gif', 'GIF - Graphics Interchange Format'],
join(self.tmp_url, "document_output.odt"), # ['htm', 'HTML Document (OpenOffice.org Impress)'],
'doc', # ['html', 'HTML Document (OpenOffice.org Impress)'],
'odt', # ['html', 'XHTML'], ['jfif', 'JPEG - Joint Photographic Experts Group'],
'application/vnd.oasis.opendocument.text') # ['jif', 'JPEG - Joint Photographic Experts Group'],
# ['jpe', 'JPEG - Joint Photographic Experts Group'],
def testgetFileMetadataItemListWithoutData(self): # ['jpeg', 'JPEG - Joint Photographic Experts Group'],
"""Test server using method getFileMetadataItemList. Without data # ['jpg', 'JPEG - Joint Photographic Experts Group'],
converted""" # ['met', 'MET - OS/2 Metafile'], ['odg', 'ODF Drawing (Impress)'],
data = open(join('data', 'testMetadata.odt'), 'r').read() # ['odp', 'ODF Presentation'],
metadata_dict = self.proxy.getFileMetadataItemList(encodestring(data), # ['otp', 'ODF Presentation Template'],
'odt') # ['pbm', 'PBM - Portable Bitmap'], ['pct', 'PCT - Mac Pict'],
self.assertEquals(metadata_dict.get("Data"), '') # ['pdf', 'PDF - Portable Document Format'],
self.assertEquals(metadata_dict.get("Title"), "cloudooo Test") # ['pgm', 'PGM - Portable Graymap'], ['pict', 'PCT - Mac Pict'],
self.assertEquals(metadata_dict.get("Subject"), "Subject Test") # ['png', 'PNG - Portable Network Graphic'],
self.assertEquals(metadata_dict.get("Description"), "cloudooo Comments") # ['pot', 'Microsoft PowerPoint 97/2000/XP Template'],
self.assertEquals(metadata_dict.get("Type"), "Text") # ['ppm', 'PPM - Portable Pixelmap'],
self.assertEquals(metadata_dict.get("MIMEType"),\ # ['pps', 'Microsoft PowerPoint 97/2000/XP'],
"application/vnd.oasis.opendocument.text") # ['ppt', 'Microsoft PowerPoint 97/2000/XP'],
# ['ras', 'RAS - Sun Raster Image'],
def testgetFileMetadataItemListWithData(self): # ['sda', 'StarDraw 5.0 (OpenOffice.org Impress)'],
"""Test server using method getFileMetadataItemList. With data converted""" # ['sdd', 'StarDraw 3.0 (OpenOffice.org Impress)'],
document_output_url = join(self.tmp_url, "testGetMetadata.odt") # ['sdd', 'StarImpress 4.0'], ['sdd', 'StarImpress 5.0'],
data = open(join('data', 'testMetadata.odt'), 'r').read() # ['svg', 'SVG - Scalable Vector Graphics'],
metadata_dict = self.proxy.getFileMetadataItemList(encodestring(data), # ['svm', 'SVM - StarView Metafile'],
"odt", # ['sxd', 'OpenOffice.org 1.0 Drawing (OpenOffice.org Impress)'],
True) # ['sxi', 'OpenOffice.org 1.0 Presentation'],
self.assertNotEquals(metadata_dict.get("Data"), None) # ['tif', 'TIFF - Tagged Image File Format'],
open(document_output_url, 'w').write(decodestring(metadata_dict["Data"])) # ['tiff', 'TIFF - Tagged Image File Format'],
content_type = self._getFileType(document_output_url) # ['wmf', 'WMF - Windows Metafile'],
self.assertEquals(content_type, 'application/vnd.oasis.opendocument.text') # ['xhtml', 'XHTML'], ['xpm', 'XPM - X PixMap']]
self.assertEquals(metadata_dict.get("Title"), "cloudooo Test")
self.assertEquals(metadata_dict.get("Subject"), "Subject Test") # self.presentation_expected_list.sort()
self.assertEquals(metadata_dict.get("Description"), "cloudooo Comments")
self.assertEquals(metadata_dict.get("Type"), "Text") # def testGetAllowedExtensionListByType(self):
self.assertEquals(metadata_dict.get("MIMEType"),\ # """Call getAllowedExtensionList and verify if the returns is a list with
"application/vnd.oasis.opendocument.text") # extension and ui_name. The request is by document type"""
# text_request = {'document_type': "text"}
def testupdateFileMetadata(self): # text_allowed_list = self.proxy.getAllowedExtensionList(text_request)
"""Test server using method updateFileMetadata""" # text_allowed_list.sort()
document_output_url = join(self.tmp_url, "testSetMetadata.odt") # for arg in text_allowed_list:
data = open(join('data', 'testMetadata.odt'), 'r').read() # self.assertTrue(arg in self.text_expected_list,
odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt', # "%s not in %s" % (arg, self.text_expected_list))
{"Title": "testSetMetadata"}) # request_dict = {'document_type': "presentation"}
open(document_output_url, 'w').write(decodestring(odf_data)) # presentation_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
content_type = self._getFileType(document_output_url) # presentation_allowed_list.sort()
self.assertEquals(content_type, 'application/vnd.oasis.opendocument.text') # for arg in presentation_allowed_list:
metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt') # self.assertTrue(arg in self.presentation_expected_list,
self.assertEquals(metadata_dict.get("Title"), "testSetMetadata") # "%s not in %s" % (arg, self.presentation_expected_list))
self.assertEquals(metadata_dict.get("CreationDate"), "9/7/2009 17:38:25")
self.assertEquals(metadata_dict.get("Description"), "cloudooo Comments") # def testGetAllowedExtensionListByExtension(self):
# """Call getAllowedExtensionList and verify if the returns is a list with
def testupdateFileMetadataWithUserMetadata(self): # extension and ui_name. The request is by extension"""
"""Test server using method updateFileMetadata with unsual metadata""" # doc_allowed_list = self.proxy.getAllowedExtensionList({'extension': "doc"})
document_output_url = join(self.tmp_url, "testSetMetadata.odt") # doc_allowed_list.sort()
data = open(join('data', 'testMetadata.odt'), 'r').read() # for arg in doc_allowed_list:
# self.assertTrue(arg in self.text_expected_list,
odf_data = self.proxy.updateFileMetadata(encodestring(data), # "%s not in %s" % (arg, self.text_expected_list))
'odt',
{"Reference": "testSetMetadata"}) # def testGetAllowedExtensionListByMimetype(self):
open(document_output_url, 'w').write(decodestring(odf_data)) # """Call getAllowedExtensionList and verify if the returns is a list with
content_type = self._getFileType(document_output_url) # extension and ui_name. The request is by mimetype"""
self.assertEquals(content_type, 'application/vnd.oasis.opendocument.text') # request_dict = {"mimetype": "application/msword"}
metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt') # msword_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
self.assertEquals(metadata_dict.get("Reference"), "testSetMetadata") # msword_allowed_list.sort()
# for arg in msword_allowed_list:
def testupdateFileMetadataUpdateSomeMetadata(self): # self.assertTrue(arg in self.text_expected_list,
"""Test server using method updateFileMetadata when the same metadata is # "%s not in %s" % (arg, self.text_expected_list))
updated"""
document_output_url = join(self.tmp_url, "testSetMetadata.odt") # def testRunConvertMethod(self):
data = open(join('data', 'testMetadata.odt'), 'r').read() # """Test run_convert method"""
odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt', # data = open(join('data', 'test.doc'), 'r').read()
{"Reference": "testSetMetadata", "Something": "ABC"}) # response_code, response_dict, response_message = \
new_odf_data = self.proxy.updateFileMetadata(odf_data, 'odt', # self.proxy.run_convert('test.doc', encodestring(data))
{"Reference": "new value", "Something": "ABC"}) # self.assertEquals(response_code, 200)
open(document_output_url, 'w').write(decodestring(new_odf_data)) # self.assertEquals(type(response_dict), DictType)
content_type = self._getFileType(document_output_url) # self.assertNotEquals(response_dict['data'], '')
self.assertEquals(content_type, 'application/vnd.oasis.opendocument.text') # self.assertEquals(sorted(response_dict.keys()),
metadata_dict = self.proxy.getFileMetadataItemList(new_odf_data, 'odt') # ['data', 'meta', 'mime'])
self.assertEquals(metadata_dict.get("Reference"), "new value") # self.assertEquals(response_message, '')
self.assertEquals(metadata_dict.get("Something"), "ABC") # self.assertEquals(response_dict['meta']['MIMEType'],
# 'application/vnd.oasis.opendocument.text')
def testupdateFileMetadataAlreadyHasMetadata(self):
"""Test document that already has metadata. Check if the metadata is not # def testRunConvertFailResponse(self):
deleted""" # """Test run_convert method with invalid file"""
data = open(join('data', 'testMetadata.odt'), 'r').read() # data = open(join('data', 'test.doc'), 'r').read()[:30]
metadata_dict = self.proxy.getFileMetadataItemList(encodestring(data), 'odt') # response_code, response_dict, response_message = \
self.assertEquals(metadata_dict["Description"], "cloudooo Comments") # self.proxy.run_convert('test.doc', encodestring(data))
self.assertEquals(metadata_dict["Keywords"], "Keywords Test") # self.assertEquals(response_code, 402)
self.assertEquals(metadata_dict["Title"], "cloudooo Test") # self.assertEquals(type(response_dict), DictType)
odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt', # self.assertEquals(response_dict, {})
{"Title": "cloudooo Title"}) # msg = "This document can not be loaded or is empty\n"
odf_metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt') # self.assertTrue(response_message.endswith(msg),
self.assertEquals(odf_metadata_dict["Description"], "cloudooo Comments") # "%s != %s" % (response_message, msg))
self.assertEquals(odf_metadata_dict["Keywords"], "Keywords Test")
self.assertEquals(odf_metadata_dict["Title"], "cloudooo Title") # def testRunGenerateMethod(self):
# """Test run_generate method"""
def testWithZipFile(self): # data = open(join('data', 'test.odt'), 'r').read()
"""Test if send a zipfile returns a document correctly""" # generate_result = self.proxy.run_generate('test.odt',
self._testConvertFile("data/test.zip", # encodestring(data),
join(self.tmp_url, "output_zipfile.zip"), # None, 'pdf',
'zip', # 'application/vnd.oasis.opendocument.text')
'txt', # response_code, response_dict, response_message = generate_result
'application/zip', # self.assertEquals(response_code, 200)
True) # self.assertEquals(type(response_dict), DictType)
# self.assertNotEquals(response_dict['data'], '')
def testSendZipAndReturnTxt(self): # self.assertEquals(response_dict['mime'], 'application/pdf')
"""Convert compressed html to txt"""
output_url = join(self.tmp_url, "output.txt") # def testRunGenerateMethodConvertOdsToHTML(self):
self._testConvertFile("data/test.zip", # """Test run_generate method. This test is to validate a bug convertions to
output_url, # html"""
'zip', # data = open(join('data', 'test.ods'), 'r').read()
'txt', # generate_result = self.proxy.run_generate('test.ods',
'text/plain') # encodestring(data),
self.assertTrue(open(output_url).read().endswith('cloudooo Test\n \n')) # None, 'html',
# "application/vnd.oasis.opendocument.spreadsheet")
def testConvertPNGToSVG(self): # response_code, response_dict, response_message = generate_result
"""Test export png to svg""" # self.assertEquals(response_code, 200)
output_url = join(self.tmp_url, "output.svg") # self.assertEquals(type(response_dict), DictType)
self._testConvertFile("data/test.png", # self.assertNotEquals(response_dict['data'], '')
output_url, # self.assertEquals(response_dict['mime'], 'application/zip')
'png', # output_url = join(self.tmp_url, "zip.zip")
'svg', # open(output_url, 'w').write(decodestring(response_dict['data']))
'image/svg+xml') # self.assertTrue(is_zipfile(output_url))
# filename_list = [file.filename for file in ZipFile(output_url).filelist]
def testConvertPPTXToODP(self): # for filename in filename_list:
"""Test export pptx to odp""" # if filename.endswith("impr.html"):
self._testConvertFile("data/test.pptx", # break
join(self.tmp_url, "output.pptx"), # else:
'pptx', # self.fail("Not exists one file with 'impr.html' format")
'odp', # if exists(output_url):
'application/vnd.oasis.opendocument.presentation') # remove(output_url)
def testConvertDocxToODT(self): # def testPNGFileToConvertOdpToHTML(self):
"""Test export docx to odt""" # """Test run_generate method. This test if returns good png files"""
self._testConvertFile("data/test.docx", # data = open(join('data', 'test_png.odp'), 'r').read()
join(self.tmp_url, "output_docx.odt"), # generate_result = self.proxy.run_generate('test_png.odp',
'docx', # encodestring(data),
'odt', # None, 'html',
'application/vnd.oasis.opendocument.text') # 'application/vnd.oasis.opendocument.presentation')
# response_code, response_dict, response_message = generate_result
def testConvertPyToPDF(self): # self.assertEquals(response_code, 200)
"""Test export python to pdf""" # self.assertEquals(type(response_dict), DictType)
self._testConvertFile(__file__, # self.assertNotEquals(response_dict['data'], '')
join(self.tmp_url, "output.py"), # self.assertEquals(response_dict['mime'], 'application/zip')
'py', # output_url = join(self.tmp_url, "zip.zip")
'pdf', # open(output_url, 'w').write(decodestring(response_dict['data']))
'application/pdf') # self.assertTrue(is_zipfile(output_url))
# zipfile = ZipFile(output_url)
def testSendEmptyRequest(self): # try:
"""Test to verify if the behavior of server is normal when a empty string # png_path = join(self.tmp_url, "img0.png")
is sent""" # zipfile.extractall(self.tmp_url)
data = encodestring("") # content_type = self._getFileType(png_path)
self.assertRaises(Fault, self.proxy.convertFile, (data, '', '')) # self.assertEquals(content_type, 'image/png')
self.assertRaises(Fault, self.proxy.getFileMetadataItemList, (data, '')) # m = magic.Magic()
# self.assertTrue("8-bit/color RGB" in m.from_file(png_path))
def testConvertDocumentToInvalidFormat(self): # finally:
"""Try convert one document for a invalid format""" # zipfile.close()
data = open(join('data', 'test.doc'), 'r').read() # if exists(output_url):
self.assertRaises(Fault, self.proxy.convertFile, (data, 'doc', 'xyz')) # remove(output_url)
def testConvertDocumentToImpossibleFormat(self): # def testRunGenerateMethodConvertOdpToHTML(self):
"""Try convert one document to format not possible""" # """Test run_generate method. This test is to validate a bug convertions to
data = open(join('data', 'test.odp'), 'r').read() # html"""
self.assertRaises(Fault, self.proxy.convertFile, (data, 'odp', 'doc')) # data = open(join('data', 'test.odp'), 'r').read()
# generate_result = self.proxy.run_generate('test.odp',
def testRunConvertMethod(self): # encodestring(data),
"""Test run_convert method""" # None, 'html',
data = open(join('data', 'test.doc'), 'r').read() # 'application/vnd.oasis.opendocument.presentation')
response_code, response_dict, response_message = \ # response_code, response_dict, response_message = generate_result
self.proxy.run_convert('test.doc', encodestring(data)) # self.assertEquals(response_code, 200)
self.assertEquals(response_code, 200) # self.assertEquals(type(response_dict), DictType)
self.assertEquals(type(response_dict), DictType) # self.assertNotEquals(response_dict['data'], '')
self.assertNotEquals(response_dict['data'], '') # self.assertEquals(response_dict['mime'], 'application/zip')
self.assertEquals(sorted(response_dict.keys()), # output_url = join(self.tmp_url, "zip.zip")
['data', 'meta', 'mime']) # open(output_url, 'w').write(decodestring(response_dict['data']))
self.assertEquals(response_message, '') # self.assertTrue(is_zipfile(output_url))
self.assertEquals(response_dict['meta']['MIMEType'], # filename_list = [file.filename for file in ZipFile(output_url).filelist]
'application/vnd.oasis.opendocument.text') # for filename in filename_list:
# if filename.endswith("impr.html"):
def testRunConvertFailResponse(self): # break
"""Test run_convert method with invalid file""" # else:
data = open(join('data', 'test.doc'), 'r').read()[:30] # self.fail("Not exists one file with 'impr.html' format")
response_code, response_dict, response_message = \
self.proxy.run_convert('test.doc', encodestring(data)) # # XXX disable this test because LibreOffice 3.3 can open such a broken
self.assertEquals(response_code, 402) # # document.
self.assertEquals(type(response_dict), DictType) # def _testRunGenerateMethodFailResponse(self):
self.assertEquals(response_dict, {}) # """Test run_generate method with invalid document"""
msg = "This document can not be loaded or is empty\n" # data = open(join('data', 'test.odt'), 'r').read()[:100]
self.assertTrue(response_message.endswith(msg), # generate_result = self.proxy.run_generate('test.odt',
"%s != %s" % (response_message, msg)) # encodestring(data),
# None, 'pdf', 'application/vnd.oasis.opendocument.text')
def testRunGenerateMethod(self): # response_code, response_dict, response_message = generate_result
"""Test run_generate method""" # self.assertEquals(response_code, 402)
data = open(join('data', 'test.odt'), 'r').read() # self.assertEquals(type(response_dict), DictType)
generate_result = self.proxy.run_generate('test.odt', # self.assertEquals(response_dict, {})
encodestring(data), # self.assertTrue(response_message.startswith('Traceback'))
None, 'pdf',
'application/vnd.oasis.opendocument.text') # def testRunSetMetadata(self):
response_code, response_dict, response_message = generate_result # """Test run_setmetadata method"""
self.assertEquals(response_code, 200) # data = open(join('data', 'testMetadata.odt'), 'r').read()
self.assertEquals(type(response_dict), DictType) # setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
self.assertNotEquals(response_dict['data'], '') # encodestring(data),
self.assertEquals(response_dict['mime'], 'application/pdf') # {"Title": "testSetMetadata", "Description": "Music"})
# response_code, response_dict, response_message = setmetadata_result
def testRunGenerateMethodConvertOdsToHTML(self): # self.assertEquals(response_code, 200)
"""Test run_generate method. This test is to validate a bug convertions to # self.assertNotEquals(response_dict['data'], '')
html""" # getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt',
data = open(join('data', 'test.ods'), 'r').read() # response_dict['data'])
generate_result = self.proxy.run_generate('test.ods', # response_code, response_dict, response_message = getmetadata_result
encodestring(data), # self.assertEquals(response_code, 200)
None, 'html', # self.assertEquals(response_dict['meta']['MIMEType'],
"application/vnd.oasis.opendocument.spreadsheet") # 'application/vnd.oasis.opendocument.text')
response_code, response_dict, response_message = generate_result # self.assertEquals(response_dict['meta']['Description'], "Music")
self.assertEquals(response_code, 200) # setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
self.assertEquals(type(response_dict), DictType) # encodestring(data),
self.assertNotEquals(response_dict['data'], '') # {"Title": "Namie's working record",
self.assertEquals(response_dict['mime'], 'application/zip') # "Description": "Music"})
output_url = join(self.tmp_url, "zip.zip") # response_code, response_dict, response_message = setmetadata_result
open(output_url, 'w').write(decodestring(response_dict['data'])) # getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt',
self.assertTrue(is_zipfile(output_url)) # response_dict['data'])
filename_list = [file.filename for file in ZipFile(output_url).filelist] # response_code, response_dict, response_message = getmetadata_result
for filename in filename_list: # self.assertEquals(response_code, 200)
if filename.endswith("impr.html"): # self.assertEquals(response_dict['meta']['title'],
break # "Namie's working record")
else:
self.fail("Not exists one file with 'impr.html' format") # def testRunSetMetadataFailResponse(self):
if exists(output_url): # """Test run_setmetadata method with invalid document"""
remove(output_url) # data = open(join('data', 'testMetadata.odt'), 'r').read()[:100]
# setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
def testPNGFileToConvertOdpToHTML(self): # encodestring(data),
"""Test run_generate method. This test if returns good png files""" # {"Title": "testSetMetadata", "Description": "Music"})
data = open(join('data', 'test_png.odp'), 'r').read() # response_code, response_dict, response_message = setmetadata_result
generate_result = self.proxy.run_generate('test_png.odp', # self.assertEquals(response_code, 402)
encodestring(data), # self.assertEquals(response_dict, {})
None, 'html', # self.assertTrue(response_message.startswith('Traceback'))
'application/vnd.oasis.opendocument.presentation')
response_code, response_dict, response_message = generate_result # def testGetAllowedTargetItemList(self):
self.assertEquals(response_code, 200) # """Test if filter name returns correctly with ERP5 API"""
self.assertEquals(type(response_dict), DictType) # mimetype = 'application/vnd.oasis.opendocument.text'
self.assertNotEquals(response_dict['data'], '') # response_code, response_dict, response_message = \
self.assertEquals(response_dict['mime'], 'application/zip') # self.proxy.getAllowedTargetItemList(mimetype)
output_url = join(self.tmp_url, "zip.zip") # self.assertEquals(response_code, 200)
open(output_url, 'w').write(decodestring(response_dict['data'])) # self.assertEquals(len(response_dict['response_data']), 17)
self.assertTrue(is_zipfile(output_url)) # self.assertTrue(['html', 'HTML Document (OpenOffice.org Writer)'] in response_dict['response_data'])
zipfile = ZipFile(output_url) # self.assertFalse(['html', 'HTML Document'] in response_dict['response_data'])
try:
png_path = join(self.tmp_url, "img0.png") # def testGetTableItemList(self):
zipfile.extractall(self.tmp_url) # """Test if manager can get the table item list"""
content_type = self._getFileType(png_path) # table_list = [['Developers', ''],
self.assertEquals(content_type, 'image/png') # ['Prices', 'Table 1: Prices table from Mon Restaurant'],
m = magic.Magic() # ['SoccerTeams', 'Tabela 2: Soccer Teams']]
self.assertTrue("8-bit/color RGB" in m.from_file(png_path)) # data = encodestring(open("data/granulate_table_test.odt").read())
finally: # granulated_table = self.proxy.getTableItemList(data, "odt")
zipfile.close() # self.assertEquals(table_list, granulated_table)
if exists(output_url): # #.doc
remove(output_url) # table_list = [['Table1', ''],
# ['Table2', 'Table 1: Prices table from Mon Restaurant'],
def testRunGenerateMethodConvertOdpToHTML(self): # ['Table3', 'Tabela 2: Soccer Teams']]
"""Test run_generate method. This test is to validate a bug convertions to # data = encodestring(open("data/granulate_table_test.doc").read())
html""" # granulated_table = self.proxy.getTableItemList(data, "doc")
data = open(join('data', 'test.odp'), 'r').read() # self.assertEquals(table_list, granulated_table)
generate_result = self.proxy.run_generate('test.odp',
encodestring(data), # def testGetTable(self):
None, 'html', # """Test if manager can get a item of some granulated table"""
'application/vnd.oasis.opendocument.presentation') # data = encodestring(open("./data/granulate_table_test.odt").read())
response_code, response_dict, response_message = generate_result # granulated_table = self.proxy.getTableItemList(data, "odt")
self.assertEquals(response_code, 200) # table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0],
self.assertEquals(type(response_dict), DictType) # "odt"))
self.assertNotEquals(response_dict['data'], '') # content_xml_str = ZipFile(StringIO(table_item)).read('content.xml')
self.assertEquals(response_dict['mime'], 'application/zip') # content_xml = etree.fromstring(content_xml_str)
output_url = join(self.tmp_url, "zip.zip") # table_list = content_xml.xpath('//table:table',
open(output_url, 'w').write(decodestring(response_dict['data'])) # namespaces=content_xml.nsmap)
self.assertTrue(is_zipfile(output_url)) # self.assertEquals(1, len(table_list))
filename_list = [file.filename for file in ZipFile(output_url).filelist] # table = table_list[0]
for filename in filename_list: # name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
if filename.endswith("impr.html"): # self.assertEquals(granulated_table[1][0], table.attrib[name_key])
break # #.doc
else: # data = encodestring(open("./data/granulate_table_test.doc").read())
self.fail("Not exists one file with 'impr.html' format") # granulated_table = self.proxy.getTableItemList(data, "doc")
# self.proxy.getTable(data, granulated_table[1][0], "doc")
# XXX disable this test because LibreOffice 3.3 can open such a broken # table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0],
# document. # "doc"))
def _testRunGenerateMethodFailResponse(self): # content_xml_str = ZipFile(StringIO(table_item)).read('content.xml')
"""Test run_generate method with invalid document""" # content_xml = etree.fromstring(content_xml_str)
data = open(join('data', 'test.odt'), 'r').read()[:100] # table_list = content_xml.xpath('//table:table',
generate_result = self.proxy.run_generate('test.odt', # namespaces=content_xml.nsmap)
encodestring(data), # self.assertEquals(1, len(table_list))
None, 'pdf', 'application/vnd.oasis.opendocument.text') # table = table_list[0]
response_code, response_dict, response_message = generate_result # name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self.assertEquals(response_code, 402) # self.assertEquals(granulated_table[1][0], table.attrib[name_key])
self.assertEquals(type(response_dict), DictType)
self.assertEquals(response_dict, {}) # def testGetColumnItemList(self):
self.assertTrue(response_message.startswith('Traceback')) # """Test if manager can get the list of column item"""
# data = encodestring(open("./data/granulate_table_test.odt").read())
def testRunSetMetadata(self): # columns = self.proxy.getColumnItemList(data, "SoccerTeams", "odt")
"""Test run_setmetadata method""" # self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
data = open(join('data', 'testMetadata.odt'), 'r').read() # #.doc
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', # data = encodestring(open("./data/granulate_table_test.doc").read())
encodestring(data), # #in the doc format the tables lose their names
{"Title": "testSetMetadata", "Description": "Music"}) # columns = self.proxy.getColumnItemList(data, "Table3", "doc")
response_code, response_dict, response_message = setmetadata_result # self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
self.assertEquals(response_code, 200)
self.assertNotEquals(response_dict['data'], '') # def testGetLineItemList(self):
getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt', # """Test if manager can get the list of lines items"""
response_dict['data']) # data = encodestring(open("./data/granulate_table_test.odt").read())
response_code, response_dict, response_message = getmetadata_result # line_item_list = self.proxy.getLineItemList(data, "Developers", "odt")
self.assertEquals(response_code, 200) # self.assertEquals([['Name', 'Hugo'], ['Phone', '+55 (22) 8888-8888'],
self.assertEquals(response_dict['meta']['MIMEType'], # ['Email', 'hugomaia@tiolive.com'], ['Name', 'Rafael'],
'application/vnd.oasis.opendocument.text') # ['Phone', '+55 (22) 9999-9999'],
self.assertEquals(response_dict['meta']['Description'], "Music") # ['Email', 'rafael@tiolive.com']], line_item_list)
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', # #.doc
encodestring(data), # data = encodestring(open("./data/granulate_table_test.doc").read())
{"Title": "Namie's working record", # line_item_list = self.proxy.getLineItemList(data, "Table1", "doc")
"Description": "Music"}) # self.assertEquals([['Name', 'Hugo'], ['Phone', '+55 (22) 8888-8888'],
response_code, response_dict, response_message = setmetadata_result # ['Email', 'hugomaia@tiolive.com'], ['Name', 'Rafael'],
getmetadata_result = self.proxy.run_getmetadata('testMetadata.odt', # ['Phone', '+55 (22) 9999-9999'],
response_dict['data']) # ['Email', 'rafael@tiolive.com']], line_item_list)
response_code, response_dict, response_message = getmetadata_result
self.assertEquals(response_code, 200) # def testGetImageItemList(self):
self.assertEquals(response_dict['meta']['title'], # """Test if manager can get the list of images items"""
"Namie's working record") # data = encodestring(open("./data/granulate_test.odt").read())
# image_list = self.proxy.getImageItemList(data, "odt")
def testRunSetMetadataFailResponse(self): # self.assertEquals([['10000000000000C80000009C38276C51.jpg', ''],
"""Test run_setmetadata method with invalid document""" # ['10000201000000C80000004E7B947D46.png', 'TioLive Logo'],
data = open(join('data', 'testMetadata.odt'), 'r').read()[:100] # ['10000201000000C80000004E7B947D46.png', ''],
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', # ['2000004F00004233000013707E7DE37A.svm', 'Python Logo'],
encodestring(data), # ['10000201000000C80000004E7B947D46.png',
{"Title": "testSetMetadata", "Description": "Music"}) # 'Again TioLive Logo']],
response_code, response_dict, response_message = setmetadata_result # image_list)
self.assertEquals(response_code, 402) # #.doc
self.assertEquals(response_dict, {}) # data = encodestring(open("./data/granulate_test.doc").read())
self.assertTrue(response_message.startswith('Traceback')) # image_list = self.proxy.getImageItemList(data, "doc")
# self.assertEquals([['10000000000000C80000009C38276C51.jpg', ''],
def testGetAllowedTargetItemList(self): # ['10000201000000C80000004E7B947D46.png', 'TioLive Logo'],
"""Test if filter name returns correctly with ERP5 API""" # ['10000201000000C80000004E7B947D46.png', ''],
mimetype = 'application/vnd.oasis.opendocument.text' # ['200003160000423300001370F468B63D.wmf', 'Python Logo'],
response_code, response_dict, response_message = \ # ['10000201000000C80000004E7B947D46.png',
self.proxy.getAllowedTargetItemList(mimetype) # 'Again TioLive Logo']],
self.assertEquals(response_code, 200) # image_list)
self.assertEquals(len(response_dict['response_data']), 17)
self.assertTrue(['html', 'HTML Document (OpenOffice.org Writer)'] in response_dict['response_data']) # def testGetImage(self):
self.assertFalse(['html', 'HTML Document'] in response_dict['response_data']) # """Test if manager can get a image"""
# data = encodestring(open("./data/granulate_test.odt").read())
def testGetTableItemList(self): # zip = ZipFile(StringIO(decodestring(data)))
"""Test if manager can get the table item list""" # image_id = '10000000000000C80000009C38276C51.jpg'
table_list = [['Developers', ''], # original_image = zip.read('Pictures/%s' % image_id)
['Prices', 'Table 1: Prices table from Mon Restaurant'], # geted_image = decodestring(self.proxy.getImage(data, image_id, "odt"))
['SoccerTeams', 'Tabela 2: Soccer Teams']] # self.assertEquals(original_image, geted_image)
data = encodestring(open("data/granulate_table_test.odt").read()) # #.doc
granulated_table = self.proxy.getTableItemList(data, "odt") # data = encodestring(open("./data/granulate_test.doc").read())
self.assertEquals(table_list, granulated_table) # #This conversion is necessary to catch the image from the doc file;
#.doc # #so compare with the server return.
table_list = [['Table1', ''], # data_odt = self.proxy.convertFile(data, 'doc', 'odt', False)
['Table2', 'Table 1: Prices table from Mon Restaurant'], # zip = ZipFile(StringIO(decodestring(data_odt)))
['Table3', 'Tabela 2: Soccer Teams']] # image_id = '10000000000000C80000009C38276C51.jpg'
data = encodestring(open("data/granulate_table_test.doc").read()) # original_image = zip.read('Pictures/%s' % image_id)
granulated_table = self.proxy.getTableItemList(data, "doc") # geted_image = decodestring(self.proxy.getImage(data, image_id, "doc"))
self.assertEquals(table_list, granulated_table) # self.assertEquals(original_image, geted_image)
def testGetTable(self): # def testGetParagraphItemList(self):
"""Test if manager can get a item of some granulated table""" # """Test if paragraphs are extracted correctly from document"""
data = encodestring(open("./data/granulate_table_test.odt").read()) # data = encodestring(open("./data/granulate_test.odt").read())
granulated_table = self.proxy.getTableItemList(data, "odt") # paragraph_list = self.proxy.getParagraphItemList(data, "odt")
table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0], # self.assertEquals([[0, 'P3'], [1, 'P1'], [2, 'P12'], [3, 'P6'], [4, 'P7'],
"odt")) # [5, 'P8'], [6, 'P6'], [7, 'P6'], [8, 'P13'], [9, 'P9'],
content_xml_str = ZipFile(StringIO(table_item)).read('content.xml') # [10, 'P9'], [11, 'P9'], [12, 'P4'], [13, 'P10'], [14,
content_xml = etree.fromstring(content_xml_str) # 'P5'], [15, 'P5'], [16, 'P14'], [17, 'P11'], [18, 'P11'],
table_list = content_xml.xpath('//table:table', # [19, 'Standard'], [20, 'P2'], [21, 'P2'], [22, 'P2'],
namespaces=content_xml.nsmap) # [23, 'P2'], [24, 'P2'], [25, 'P2'], [26, 'P2'], [27,
self.assertEquals(1, len(table_list)) # 'P2'], [28, 'P2'], [29, 'P2']], paragraph_list)
table = table_list[0]
name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name' # def testGetParagraphItem(self):
self.assertEquals(granulated_table[1][0], table.attrib[name_key]) # """Test if manager can get a paragraph"""
#.doc # data = encodestring(open("./data/granulate_test.odt").read())
data = encodestring(open("./data/granulate_table_test.doc").read()) # paragraph = self.proxy.getParagraph(data, 1, "odt")
granulated_table = self.proxy.getTableItemList(data, "doc") # self.assertEquals(['', 'P1'], paragraph)
self.proxy.getTable(data, granulated_table[1][0], "doc")
table_item = decodestring(self.proxy.getTable(data, granulated_table[1][0], # def testGetChapterItemList(self):
"doc")) # """Test if the chapters list is extracted correctly from document"""
content_xml_str = ZipFile(StringIO(table_item)).read('content.xml') # data = encodestring(open("./data/granulate_chapters_test.odt").read())
content_xml = etree.fromstring(content_xml_str) # chapter_list = self.proxy.getChapterItemList(data, "odt")
table_list = content_xml.xpath('//table:table', # self.assertEquals([[0, 'Title 0'], [1, 'Title 1'], [2, 'Title 2'],
namespaces=content_xml.nsmap) # [3, 'Title 3'], [4, 'Title 4'], [5, 'Title 5'],
self.assertEquals(1, len(table_list)) # [6, 'Title 6'], [7, 'Title 7'], [8, 'Title 8'],
table = table_list[0] # [9, 'Title 9'], [10, 'Title 10']] , chapter_list)
name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
self.assertEquals(granulated_table[1][0], table.attrib[name_key]) # def testGetChapterItem(self):
# """Test if manager can get a chapter"""
def testGetColumnItemList(self): # data = encodestring(open("./data/granulate_chapters_test.odt").read())
"""Test if manager can get the list of column item""" # chapter = self.proxy.getChapterItem(1, data, "odt")
data = encodestring(open("./data/granulate_table_test.odt").read()) # self.assertEquals(['Title 1', 1], chapter)
columns = self.proxy.getColumnItemList(data, "SoccerTeams", "odt")
self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
#.doc
data = encodestring(open("./data/granulate_table_test.doc").read())
#in the doc format the tables lose their names
columns = self.proxy.getColumnItemList(data, "Table3", "doc")
self.assertEquals([[0, 'Name'], [1, 'Country']], columns)
def testGetLineItemList(self):
"""Test if manager can get the list of lines items"""
data = encodestring(open("./data/granulate_table_test.odt").read())
line_item_list = self.proxy.getLineItemList(data, "Developers", "odt")
self.assertEquals([['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)
#.doc
data = encodestring(open("./data/granulate_table_test.doc").read())
line_item_list = self.proxy.getLineItemList(data, "Table1", "doc")
self.assertEquals([['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)
def testGetImageItemList(self):
"""Test if manager can get the list of images items"""
data = encodestring(open("./data/granulate_test.odt").read())
image_list = self.proxy.getImageItemList(data, "odt")
self.assertEquals([['10000000000000C80000009C38276C51.jpg', ''],
['10000201000000C80000004E7B947D46.png', 'TioLive Logo'],
['10000201000000C80000004E7B947D46.png', ''],
['2000004F00004233000013707E7DE37A.svm', 'Python Logo'],
['10000201000000C80000004E7B947D46.png',
'Again TioLive Logo']],
image_list)
#.doc
data = encodestring(open("./data/granulate_test.doc").read())
image_list = self.proxy.getImageItemList(data, "doc")
self.assertEquals([['10000000000000C80000009C38276C51.jpg', ''],
['10000201000000C80000004E7B947D46.png', 'TioLive Logo'],
['10000201000000C80000004E7B947D46.png', ''],
['200003160000423300001370F468B63D.wmf', 'Python Logo'],
['10000201000000C80000004E7B947D46.png',
'Again TioLive Logo']],
image_list)
def testGetImage(self):
"""Test if manager can get a image"""
data = encodestring(open("./data/granulate_test.odt").read())
zip = ZipFile(StringIO(decodestring(data)))
image_id = '10000000000000C80000009C38276C51.jpg'
original_image = zip.read('Pictures/%s' % image_id)
geted_image = decodestring(self.proxy.getImage(data, image_id, "odt"))
self.assertEquals(original_image, geted_image)
#.doc
data = encodestring(open("./data/granulate_test.doc").read())
#This conversion is necessary to catch the image from the doc file;
#so compare with the server return.
data_odt = self.proxy.convertFile(data, 'doc', 'odt', False)
zip = ZipFile(StringIO(decodestring(data_odt)))
image_id = '10000000000000C80000009C38276C51.jpg'
original_image = zip.read('Pictures/%s' % image_id)
geted_image = decodestring(self.proxy.getImage(data, image_id, "doc"))
self.assertEquals(original_image, geted_image)
def testGetParagraphItemList(self):
"""Test if paragraphs are extracted correctly from document"""
data = encodestring(open("./data/granulate_test.odt").read())
paragraph_list = self.proxy.getParagraphItemList(data, "odt")
self.assertEquals([[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'],
[19, 'Standard'], [20, 'P2'], [21, 'P2'], [22, 'P2'],
[23, 'P2'], [24, 'P2'], [25, 'P2'], [26, 'P2'], [27,
'P2'], [28, 'P2'], [29, 'P2']], paragraph_list)
def testGetParagraphItem(self):
"""Test if manager can get a paragraph"""
data = encodestring(open("./data/granulate_test.odt").read())
paragraph = self.proxy.getParagraph(data, 1, "odt")
self.assertEquals(['', 'P1'], paragraph)
def testGetChapterItemList(self):
"""Test if the chapters list is extracted correctly from document"""
data = encodestring(open("./data/granulate_chapters_test.odt").read())
chapter_list = self.proxy.getChapterItemList(data, "odt")
self.assertEquals([[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)
def testGetChapterItem(self):
"""Test if manager can get a chapter"""
data = encodestring(open("./data/granulate_chapters_test.odt").read())
chapter = self.proxy.getChapterItem(1, data, "odt")
self.assertEquals(['Title 1', 1], chapter)
def test_suite(): def test_suite():
return make_suite(TestServer) return make_suite(TestServer)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment