Commit be6c35c0 authored by Jérome Perrin's avatar Jérome Perrin

manager/getAllowedExtensionList: use explicit extensions in ERP5 legacy mode

In python2, mimetypes module was not deterministic and this snippet:

    import mimetypes; print(mimetypes.guess_extension("text/html"))

use to be ".html" on python 2.7.14, but is ".htm" on python 2.7.18

Similarly:

    import mimetypes; print(mimetypes.guess_extension("application/msword"))

was ".doc" on 2.7.14 and ".dot" on 2.7.18 (this was in my observations, this
does not look deterministic as it is iterating on a dict, maybe this behaviour
is not always same)

For html conversion engine, ERP5 expect that the extension for text/html is
.html, not .htm. Some tests also expect that the conversion for word is .doc so
to keep compatibility with extensions used in ERP5 compatibility mode, define
explicitly these two extensions instead of depending on python standard library.
parent cd3ec5a5
Pipeline #15170 passed with stage
in 0 seconds
...@@ -51,46 +51,31 @@ class TestAllowedExtensions(TestCase): ...@@ -51,46 +51,31 @@ class TestAllowedExtensions(TestCase):
ui_name. The request is by document type as text""" 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() self.assertEqual(
for arg in text_allowed_list: sorted([tuple(x) for x in text_allowed_list]),
self.assertTrue(tuple(arg) in text_expected_tuple, sorted(text_expected_tuple))
"%s not in %s" % (arg, text_expected_tuple))
def testGetAllowedPresentationExtensionListByType(self): def testGetAllowedPresentationExtensionListByType(self):
"""Verify if getAllowedExtensionList returns is a list with extension and """Verify if getAllowedExtensionList returns is a list with extension and
ui_name. The request is by document type as presentation""" 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() self.assertTrue(presentation_allowed_list)
for arg in presentation_allowed_list: for arg in presentation_allowed_list:
self.assertTrue(tuple(arg) in presentation_expected_tuple, self.assertIn(tuple(arg), presentation_expected_tuple)
"%s not in %s" % (arg, presentation_expected_tuple))
def testGetAllowedExtensionListByExtension(self): def testGetAllowedExtensionListByExtension(self):
"""Verify if getAllowedExtensionList returns is a list with extension and """Verify if getAllowedExtensionList returns is a list with extension and
ui_name. The request is by extension""" ui_name. The request is by extension"""
doc_allowed_list = self.proxy.getAllowedExtensionList({'extension': "doc"}) doc_allowed_list = self.proxy.getAllowedExtensionList({'extension': "doc"})
# Verify all expected types ("doc"/"docy" MAY NOT be present) self.assertEqual(sorted([tuple(x) for x in doc_allowed_list]), sorted(text_expected_tuple))
# XXX - Actually I'm not sure about docy, test have been failing for several months,
# at least ignoring it makes the test pass.
doc_allowed_list = [(a, b) for a, b in doc_allowed_list if a not in ("htm", "dot", "doc", "docy")]
doc_allowed_list.append(('html', 'HTML Document (Writer)'))
self.assertEquals(sorted(doc_allowed_list),
sorted(list(filter(lambda (a, b): a not in ("doc", "docy"), text_expected_tuple))))
def testGetAllowedExtensionListByMimetype(self): def testGetAllowedExtensionListByMimetype(self):
"""Verify if getAllowedExtensionList returns is a list with extension and """Verify if getAllowedExtensionList returns is a list with extension and
ui_name. The request is by mimetype""" 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)
# Verify all expected types ("doc"/"docy" MAY NOT be present) self.assertEqual(sorted([tuple(x) for x in msword_allowed_list]), sorted(text_expected_tuple))
# XXX - Actually I'm not sure about docy, test have been failing for several months,
# at least ignoring it makes the test pass.
msword_allowed_list = [(a, b) for a, b in msword_allowed_list if a not in ("htm", "dot", "doc", "docy")]
msword_allowed_list.append(('html', 'HTML Document (Writer)'))
self.assertEquals(sorted(msword_allowed_list),
sorted(list(filter(lambda (a, b): a not in ("doc", "docy"), text_expected_tuple))))
class TestConversion(TestCase): class TestConversion(TestCase):
...@@ -404,14 +389,12 @@ class TestGetAllowedTargetItemList(TestCase): ...@@ -404,14 +389,12 @@ class TestGetAllowedTargetItemList(TestCase):
response_code, response_dict, response_message = \ response_code, response_dict, response_message = \
self.proxy.getAllowedTargetItemList(mimetype) self.proxy.getAllowedTargetItemList(mimetype)
self.assertEquals(response_code, 200) self.assertEquals(response_code, 200)
# Verify all expected types ("doc"/"docy" MAY NOT be present) # XXX in this test, docy is present in the allowed target extensions
# XXX - Actually I'm not sure about docy, test have been failing for several months,
# at least ignoring it makes the test pass.
doc_allowed_list = [(a, b) for a, b in response_dict['response_data'] if a not in ("htm", "dot", "odt", "docy")]
doc_allowed_list.append(('html', 'HTML Document (Writer)'))
self.assertEquals( self.assertEquals(
sorted(doc_allowed_list), sorted([(extension, ui_name)
sorted(list(filter(lambda (a, b): a not in ("doc", "odt", "docy"), text_expected_tuple)))) for (extension, ui_name) in response_dict['response_data']
if extension not in ('docy',)]),
sorted(text_expected_tuple))
class TestGetTableItemList(TestCase): class TestGetTableItemList(TestCase):
......
...@@ -84,10 +84,12 @@ def BBB_guess_extension(mimetype, title=None): ...@@ -84,10 +84,12 @@ def BBB_guess_extension(mimetype, title=None):
"Microsoft Word 2007-2013 XML": ".ms.docx", "Microsoft Word 2007-2013 XML": ".ms.docx",
}.get(title, None) or { }.get(title, None) or {
# mediatype : extension # mediatype : extension
"application/msword": ".doc",
"application/postscript": ".eps", "application/postscript": ".eps",
"application/vnd.ms-excel": ".xls", "application/vnd.ms-excel": ".xls",
"application/vnd.ms-excel.sheet.macroenabled.12": ".xlsm", "application/vnd.ms-excel.sheet.macroenabled.12": ".xlsm",
"application/vnd.ms-powerpoint": ".ppt", "application/vnd.ms-powerpoint": ".ppt",
"text/html": ".html",
"text/plain": ".txt", "text/plain": ".txt",
"image/jpeg": ".jpg", "image/jpeg": ".jpg",
}.get(parseContentType(mimetype).gettype(), None) or guess_extension(mimetype) }.get(parseContentType(mimetype).gettype(), None) or guess_extension(mimetype)
......
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