Commit b5981fb0 authored by Gabriel Monnerat's avatar Gabriel Monnerat

fix Backward compatibility. This code changes is to fix compatibilty with...

fix Backward compatibility. This code changes is to fix compatibilty with erp5. thanks luke and rafael

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@37460 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent df4dafa5
......@@ -143,7 +143,12 @@ class Manager(object):
try:
response_dict = {}
response_dict['meta'] = self.getFileMetadataItemList(file, orig_format, True)
response_dict['meta']['MIMEType'] = self.getFileMetadataItemList(response_dict['meta']['Data'],
orig_format)['MIMEType']
# XXX - Backward compatibility: Previous API expects 'mime' now we use 'MIMEType'"
response_dict['meta']['mime'] = response_dict['meta']['MIMEType']
response_dict['data'] = response_dict['meta']['Data']
response_dict['mime'] = response_dict['meta']['MIMEType']
del response_dict['meta']['Data']
return (200, response_dict, "")
except Exception, e:
......@@ -173,6 +178,8 @@ class Manager(object):
response_dict = {}
try:
response_dict['meta'] = self.getFileMetadataItemList(file, orig_format)
# XXX - Backward compatibility: Previous API expects 'title' now we use 'Title'"
response_dict['meta']['title'] = response_dict['meta']['Title']
return (200, response_dict, '')
except Exception, e:
logger.error(e)
......@@ -191,6 +198,12 @@ class Manager(object):
try:
response_dict = {}
response_dict['data'] = self.convertFile(file, orig_format, format, zip)
# FIXME: Fast solution to obtain the html or pdf mimetypes
if format == "html":
response_dict['mime'] = "text/html"
elif format == "pdf":
response_dict['mime'] = "application/pdf"
else:
response_dict['mime'] = self.getFileMetadataItemList(response_dict['data'],
format)['MIMEType']
return (200, response_dict, "")
......
......@@ -382,9 +382,10 @@ at least v2.0 to extract\n'
self.assertEquals(type(response_dict), DictType)
self.assertNotEquals(response_dict['data'], '')
self.assertEquals(sorted(response_dict.keys()),
['data', 'meta'])
['data', 'meta', 'mime'])
self.assertEquals(response_message, '')
self.assertEquals(response_dict['meta']['MIMEType'], 'application/msword')
self.assertEquals(response_dict['meta']['MIMEType'],
'application/vnd.oasis.opendocument.text')
def testRunConvertFailResponse(self):
"""Test run_convert method with invalid file"""
......@@ -401,13 +402,38 @@ at least v2.0 to extract\n'
data = open(join('data','test.odt'),'r').read()
generate_result = self.proxy.run_generate('test.odt',
encodestring(data),
None, 'odt', 'pdf')
None, 'pdf', 'odt')
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/vnd.oasis.opendocument.text')
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', 'ods')
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'], 'text/html')
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', 'odp')
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'], 'text/html')
def testRunGenerateMethodFailResponse(self):
"""Test run_generate method with invalid document"""
......
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