Commit 958c7242 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor test and use python-magic if the function getContent() returns the document expected

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@42218 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent adfd9071
...@@ -118,20 +118,17 @@ class TestFileSystemDocument(unittest.TestCase): ...@@ -118,20 +118,17 @@ class TestFileSystemDocument(unittest.TestCase):
def testSendZipFile(self): def testSendZipFile(self):
"""Tests if the htm is extrated from zipfile""" """Tests if the htm is extrated from zipfile"""
# XXX it seems that only zipfile module is tested here
zip_input_url = 'data/test.zip' zip_input_url = 'data/test.zip'
zip_output_url = path.join(self.tmp_url, 'zipdocument.zip')
try:
data = open(zip_input_url).read() data = open(zip_input_url).read()
zipdocument = FileSystemDocument(self.tmp_url, data, 'zip') zipdocument = FileSystemDocument(self.tmp_url, data, 'zip')
open(zip_output_url, 'w').write(zipdocument.getContent(True)) mime = magic.Magic(mime=True)
self.assertTrue(is_zipfile(zip_output_url)) mimetype = mime.from_buffer(zipdocument.getContent(True))
zipfile = ZipFile(zip_output_url) self.assertEquals(mimetype, "application/zip")
mimetype = mime.from_buffer(zipdocument.getContent())
self.assertEquals(mimetype, "text/html")
zipfile = ZipFile(StringIO(zipdocument.getContent(True)))
self.assertEquals(sorted(zipfile.namelist()), self.assertEquals(sorted(zipfile.namelist()),
sorted(['logo.gif', 'test.htm'])) sorted(['logo.gif', 'test.htm']))
finally:
if path.exists(zip_output_url):
remove(zip_output_url)
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