Commit 0262a86d authored by Priscila Manhaes's avatar Priscila Manhaes

refactor to new methods from testcase

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