Commit 144cc15d authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor to remove the static temporary folder. If the folder not exists, one is created

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@37869 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cac3f56e
...@@ -73,7 +73,7 @@ class TestAllFormats(cloudoooTestCase): ...@@ -73,7 +73,7 @@ class TestAllFormats(cloudoooTestCase):
data_output = self.proxy.convertFile(encodestring(data), data_output = self.proxy.convertFile(encodestring(data),
source_format, source_format,
extension[0]) extension[0])
output_file_url = 'output/test_%s.%s' % (document_type, extension[0]) output_file_url = '%s/test_%s.%s' % (self.tmp_url, document_type, extension[0])
open(output_file_url, 'w').write(decodestring(data_output)) open(output_file_url, 'w').write(decodestring(data_output))
stdout, stderr = Popen("file %s" % output_file_url, stdout, stderr = Popen("file %s" % output_file_url,
shell=True, shell=True,
......
...@@ -39,17 +39,16 @@ class TestHighLoad(cloudoooTestCase): ...@@ -39,17 +39,16 @@ class TestHighLoad(cloudoooTestCase):
def afterSetUp(self): def afterSetUp(self):
"""Creates connection with cloudooo Server""" """Creates connection with cloudooo Server"""
self.output_folder = "output"
self.proxy = ServerProxy("http://%s:%s" % (self.hostname, self.cloudooo_port)) self.proxy = ServerProxy("http://%s:%s" % (self.hostname, self.cloudooo_port))
def basicTestToGenerate(self, id, data, source_format, destination_format): def basicTestToGenerate(self, id, data, source_format, destination_format):
"""Test to use method generate of server""" """Test to use method generate of server"""
document = self.proxy.convertFile(data, source_format, destination_format) document = self.proxy.convertFile(data, source_format, destination_format)
document_output_url = os.path.join(self.output_folder,"%s.%s" % (id, destination_format)) document_output_url = os.path.join(self.tmp_url, "%s.%s" % (id, destination_format))
open(document_output_url,'wb').write(decodestring(document)) open(document_output_url,'wb').write(decodestring(document))
stdout, stderr = subprocess.Popen("file %s" % document_output_url, stdout, stderr = subprocess.Popen("file -b %s" % document_output_url,
shell=True, stdout=subprocess.PIPE).communicate() shell=True, stdout=subprocess.PIPE).communicate()
self.assertEquals(stdout, 'output/%s.pdf: PDF document, version 1.4\n' % id) self.assertEquals(stdout, 'PDF document, version 1.4\n')
self.assertEquals(stderr, None) self.assertEquals(stderr, None)
os.remove(document_output_url) os.remove(document_output_url)
self.assertEquals(os.path.exists(document_output_url), False) self.assertEquals(os.path.exists(document_output_url), False)
......
...@@ -106,7 +106,7 @@ class TestServer(cloudoooTestCase): ...@@ -106,7 +106,7 @@ class TestServer(cloudoooTestCase):
source_format, source_format,
destination_format, zip) destination_format, zip)
open(output_url, 'w').write(decodestring(output_data)) open(output_url, 'w').write(decodestring(output_data))
stdout, stderr = Popen("file %s" % output_url, shell=True, stdout, stderr = Popen("file -b %s" % output_url, shell=True,
stdout=PIPE).communicate() stdout=PIPE).communicate()
self.assertEquals(stdout, stdout_msg) self.assertEquals(stdout, stdout_msg)
self.assertEquals(stderr, None) self.assertEquals(stderr, None)
...@@ -149,18 +149,18 @@ class TestServer(cloudoooTestCase): ...@@ -149,18 +149,18 @@ class TestServer(cloudoooTestCase):
def testConvertDocToOdt(self): def testConvertDocToOdt(self):
"""Test Convert Doc -> Odt""" """Test Convert Doc -> Odt"""
self._testConvertFile("data/test.doc", self._testConvertFile("data/test.doc",
"output/document_output.odt", join(self.tmp_url, "document_output.odt"),
'doc', 'doc',
'odt', 'odt',
'output/document_output.odt: OpenDocument Text\n') 'OpenDocument Text\n')
def testconvertDocToPdf(self): def testconvertDocToPdf(self):
"""Test Convert Doc -> Pdf""" """Test Convert Doc -> Pdf"""
self._testConvertFile("data/test.doc", self._testConvertFile("data/test.doc",
"output/document_output.pdf", join(self.tmp_url, "document_output.pdf"),
'doc', 'doc',
'pdf', 'pdf',
'output/document_output.pdf: PDF document, version 1.4\n') 'PDF document, version 1.4\n')
def testgetFileMetadataItemListWithoutData(self): def testgetFileMetadataItemListWithoutData(self):
"""Test server using method getFileMetadataItemList. Without data """Test server using method getFileMetadataItemList. Without data
...@@ -178,16 +178,16 @@ class TestServer(cloudoooTestCase): ...@@ -178,16 +178,16 @@ class TestServer(cloudoooTestCase):
def testgetFileMetadataItemListWithData(self): def testgetFileMetadataItemListWithData(self):
"""Test server using method getFileMetadataItemList. With data converted""" """Test server using method getFileMetadataItemList. With data converted"""
document_output_url = "output/testGetMetadata.odt" document_output_url = join(self.tmp_url, "testGetMetadata.odt")
data = open(join('data','testMetadata.odt'),'r').read() data = open(join('data','testMetadata.odt'),'r').read()
metadata_dict = self.proxy.getFileMetadataItemList(encodestring(data), metadata_dict = self.proxy.getFileMetadataItemList(encodestring(data),
"odt", "odt",
True) True)
self.assertNotEquals(metadata_dict.get("Data"), None) self.assertNotEquals(metadata_dict.get("Data"), None)
open(document_output_url, 'w').write(decodestring(metadata_dict["Data"])) open(document_output_url, 'w').write(decodestring(metadata_dict["Data"]))
stdout, stderr = Popen("file %s" % document_output_url, shell=True, stdout, stderr = Popen("file -b %s" % document_output_url, shell=True,
stdout=PIPE).communicate() stdout=PIPE).communicate()
self.assertEquals(stdout,'output/testGetMetadata.odt: OpenDocument Text\n') self.assertEquals(stdout, 'OpenDocument Text\n')
self.assertEquals(metadata_dict.get("Title"), "cloudooo Test") self.assertEquals(metadata_dict.get("Title"), "cloudooo Test")
self.assertEquals(metadata_dict.get("Subject"), "Subject Test") self.assertEquals(metadata_dict.get("Subject"), "Subject Test")
self.assertEquals(metadata_dict.get("Description"), "cloudooo Comments") self.assertEquals(metadata_dict.get("Description"), "cloudooo Comments")
...@@ -198,14 +198,14 @@ class TestServer(cloudoooTestCase): ...@@ -198,14 +198,14 @@ class TestServer(cloudoooTestCase):
def testupdateFileMetadata(self): def testupdateFileMetadata(self):
"""Test server using method updateFileMetadata""" """Test server using method updateFileMetadata"""
document_output_url = "output/testSetMetadata.odt" document_output_url = join(self.tmp_url, "testSetMetadata.odt")
data = open(join('data','testMetadata.odt'),'r').read() data = open(join('data','testMetadata.odt'),'r').read()
odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt', odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt',
{"Title":"testSetMetadata"}) {"Title":"testSetMetadata"})
open(document_output_url, 'w').write(decodestring(odf_data)) open(document_output_url, 'w').write(decodestring(odf_data))
stdout, stderr = Popen("file %s" % document_output_url, shell=True, stdout, stderr = Popen("file -b %s" % document_output_url, shell=True,
stdout=PIPE).communicate() stdout=PIPE).communicate()
self.assertEquals(stdout,'output/testSetMetadata.odt: OpenDocument Text\n') self.assertEquals(stdout, 'OpenDocument Text\n')
metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt') metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt')
self.assertEquals(metadata_dict.get("Title"), "testSetMetadata") self.assertEquals(metadata_dict.get("Title"), "testSetMetadata")
self.assertEquals(metadata_dict.get("CreationDate"), "9/7/2009 17:38:25") self.assertEquals(metadata_dict.get("CreationDate"), "9/7/2009 17:38:25")
...@@ -213,31 +213,32 @@ class TestServer(cloudoooTestCase): ...@@ -213,31 +213,32 @@ class TestServer(cloudoooTestCase):
def testupdateFileMetadataWithUserMetadata(self): def testupdateFileMetadataWithUserMetadata(self):
"""Test server using method updateFileMetadata with unsual metadata""" """Test server using method updateFileMetadata with unsual metadata"""
document_output_url = "output/testSetMetadata.odt" document_output_url = join(self.tmp_url, "testSetMetadata.odt")
data = open(join('data','testMetadata.odt'),'r').read() data = open(join('data','testMetadata.odt'),'r').read()
odf_data = self.proxy.updateFileMetadata(encodestring(data), odf_data = self.proxy.updateFileMetadata(encodestring(data),
'odt', 'odt',
{"Reference":"testSetMetadata"}) {"Reference":"testSetMetadata"})
open(document_output_url, 'w').write(decodestring(odf_data)) open(document_output_url, 'w').write(decodestring(odf_data))
stdout, stderr = Popen("file %s" % document_output_url, shell=True, stdout, stderr = Popen("file -b %s" % document_output_url, shell=True,
stdout=PIPE).communicate() stdout=PIPE).communicate()
self.assertEquals(stdout,'output/testSetMetadata.odt: OpenDocument Text\n') self.assertEquals(stdout, 'OpenDocument Text\n')
metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt') metadata_dict = self.proxy.getFileMetadataItemList(odf_data, 'odt')
self.assertEquals(metadata_dict.get("Reference"), "testSetMetadata") self.assertEquals(metadata_dict.get("Reference"), "testSetMetadata")
def testupdateFileMetadataUpdateSomeMetadata(self): def testupdateFileMetadataUpdateSomeMetadata(self):
"""Test server using method updateFileMetadata when the same metadata is """Test server using method updateFileMetadata when the same metadata is
updated""" updated"""
document_output_url = "output/testSetMetadata.odt" document_output_url = join(self.tmp_url, "testSetMetadata.odt")
data = open(join('data','testMetadata.odt'),'r').read() data = open(join('data','testMetadata.odt'),'r').read()
odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt', odf_data = self.proxy.updateFileMetadata(encodestring(data), 'odt',
{"Reference":"testSetMetadata", "Something":"ABC"}) {"Reference":"testSetMetadata", "Something":"ABC"})
new_odf_data = self.proxy.updateFileMetadata(odf_data, 'odt', new_odf_data = self.proxy.updateFileMetadata(odf_data, 'odt',
{"Reference":"new value", "Something": "ABC"}) {"Reference":"new value", "Something": "ABC"})
open(document_output_url, 'w').write(decodestring(new_odf_data)) open(document_output_url, 'w').write(decodestring(new_odf_data))
stdout, stderr = Popen("file %s" % document_output_url, shell=True, stdout, stderr = Popen("file -b %s" % document_output_url, shell=True,
stdout=PIPE).communicate() stdout=PIPE).communicate()
self.assertEquals(stdout,'output/testSetMetadata.odt: OpenDocument Text\n') self.assertEquals(stdout, 'OpenDocument Text\n')
metadata_dict = self.proxy.getFileMetadataItemList(new_odf_data, 'odt') metadata_dict = self.proxy.getFileMetadataItemList(new_odf_data, 'odt')
self.assertEquals(metadata_dict.get("Reference"), "new value") self.assertEquals(metadata_dict.get("Reference"), "new value")
self.assertEquals(metadata_dict.get("Something"), "ABC") self.assertEquals(metadata_dict.get("Something"), "ABC")
...@@ -259,10 +260,9 @@ class TestServer(cloudoooTestCase): ...@@ -259,10 +260,9 @@ class TestServer(cloudoooTestCase):
def testWithZipFile(self): def testWithZipFile(self):
"""Test if send a zipfile returns a document correctly""" """Test if send a zipfile returns a document correctly"""
output_msg = 'output/output_zipfile.zip: Zip archive data, \ output_msg = 'Zip archive data, at least v2.0 to extract\n'
at least v2.0 to extract\n'
self._testConvertFile("data/test.zip", self._testConvertFile("data/test.zip",
"output/output_zipfile.zip", join(self.tmp_url, "output_zipfile.zip"),
'html', 'html',
'txt', 'txt',
output_msg, output_msg,
...@@ -270,38 +270,38 @@ at least v2.0 to extract\n' ...@@ -270,38 +270,38 @@ at least v2.0 to extract\n'
def testSendZipAndReturnTxt(self): def testSendZipAndReturnTxt(self):
"""Convert compressed html to txt""" """Convert compressed html to txt"""
output_url = "output/output.txt" output_url = join(self.tmp_url, "output.txt")
self._testConvertFile("data/test.zip", self._testConvertFile("data/test.zip",
output_url, output_url,
'html', 'html',
'txt', 'txt',
'output/output.txt: ASCII text\n') 'ASCII text\n')
self.assertEquals(open(output_url).read().endswith('cloudooo Test\n \n'), True) self.assertEquals(open(output_url).read().endswith('cloudooo Test\n \n'), True)
def testConvertPNGToSVG(self): def testConvertPNGToSVG(self):
"""Test export png to svg""" """Test export png to svg"""
self._testConvertFile("data/test.png", self._testConvertFile("data/test.png",
"output/output.svg", join("output.svg"),
'png', 'png',
'svg', 'svg',
'output/output.svg: SVG Scalable Vector Graphics image\n') 'SVG Scalable Vector Graphics image\n')
def testConvertPPTXToODP(self): def testConvertPPTXToODP(self):
"""Test export pptx to odp""" """Test export pptx to odp"""
self._testConvertFile("data/test.pptx", self._testConvertFile("data/test.pptx",
"output/output.pptx", join(self.tmp_url, "output.pptx"),
'pptx', 'pptx',
'odp', 'odp',
'output/output.pptx: OpenDocument Presentation\n') 'OpenDocument Presentation\n')
def testConvertDocxToODT(self): def testConvertDocxToODT(self):
"""Test export docx to odt""" """Test export docx to odt"""
self._testConvertFile("data/test.docx", self._testConvertFile("data/test.docx",
"output/output_docx.odt", join(self.tmp_url, "output_docx.odt"),
'docx', 'docx',
'odt', 'odt',
'output/output_docx.odt: OpenDocument Text\n') 'OpenDocument Text\n')
def testSendInvalidFile(self): def testSendInvalidFile(self):
"""Test to verify if the behavior of server is normal when a invalid file is """Test to verify if the behavior of server is normal when a invalid file is
...@@ -398,7 +398,7 @@ at least v2.0 to extract\n' ...@@ -398,7 +398,7 @@ at least v2.0 to extract\n'
def testRunConvertFailResponse(self): def testRunConvertFailResponse(self):
"""Test run_convert method with invalid file""" """Test run_convert method with invalid file"""
data = open(join('data','test.doc'),'r').read()[:30] data = open(join('data', 'test.doc'),'r').read()[:30]
response_code, response_dict, response_message = \ response_code, response_dict, response_message = \
self.proxy.run_convert('test.doc', encodestring(data)) self.proxy.run_convert('test.doc', encodestring(data))
self.assertEquals(response_code, 402) self.assertEquals(response_code, 402)
...@@ -408,7 +408,7 @@ at least v2.0 to extract\n' ...@@ -408,7 +408,7 @@ at least v2.0 to extract\n'
def testRunGenerateMethod(self): def testRunGenerateMethod(self):
"""Test run_generate method""" """Test run_generate method"""
data = open(join('data','test.odt'),'r').read() data = open(join('data', 'test.odt'),'r').read()
generate_result = self.proxy.run_generate('test.odt', generate_result = self.proxy.run_generate('test.odt',
encodestring(data), encodestring(data),
None, 'pdf', 'odt') None, 'pdf', 'odt')
...@@ -421,7 +421,7 @@ at least v2.0 to extract\n' ...@@ -421,7 +421,7 @@ at least v2.0 to extract\n'
def testRunGenerateMethodConvertOdsToHTML(self): def testRunGenerateMethodConvertOdsToHTML(self):
"""Test run_generate method. This test is to validate a bug convertions to """Test run_generate method. This test is to validate a bug convertions to
html""" html"""
data = open(join('data','test.ods'),'r').read() data = open(join('data', 'test.ods'),'r').read()
generate_result = self.proxy.run_generate('test.ods', generate_result = self.proxy.run_generate('test.ods',
encodestring(data), encodestring(data),
None, 'html', 'ods') None, 'html', 'ods')
...@@ -430,7 +430,7 @@ at least v2.0 to extract\n' ...@@ -430,7 +430,7 @@ at least v2.0 to extract\n'
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(response_dict['mime'], 'application/zip')
output_url = "./output/zip.zip" output_url = join(self.tmp_url, "zip.zip")
open(output_url, 'w').write(decodestring(response_dict['data'])) open(output_url, 'w').write(decodestring(response_dict['data']))
self.assertTrue(is_zipfile(output_url)) self.assertTrue(is_zipfile(output_url))
filename_list = [file.filename for file in ZipFile(output_url).filelist] filename_list = [file.filename for file in ZipFile(output_url).filelist]
...@@ -452,7 +452,7 @@ at least v2.0 to extract\n' ...@@ -452,7 +452,7 @@ at least v2.0 to extract\n'
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(response_dict['mime'], 'application/zip')
output_url = "./output/zip.zip" output_url = join(self.tmp_url, "zip.zip")
open(output_url, 'w').write(decodestring(response_dict['data'])) open(output_url, 'w').write(decodestring(response_dict['data']))
self.assertTrue(is_zipfile(output_url)) self.assertTrue(is_zipfile(output_url))
filename_list = [file.filename for file in ZipFile(output_url).filelist] filename_list = [file.filename for file in ZipFile(output_url).filelist]
...@@ -509,7 +509,7 @@ at least v2.0 to extract\n' ...@@ -509,7 +509,7 @@ at least v2.0 to extract\n'
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)
self.assertEquals(len(response_dict['response_data']), 28) self.assertEquals(len(response_dict['response_data']), 31)
self.assertTrue(['htm', 'HTML Document'] in response_dict['response_data']) self.assertTrue(['htm', 'HTML Document'] in response_dict['response_data'])
def test_suite(): def test_suite():
......
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