Commit 903e7b7f authored by Nicolas Delaby's avatar Nicolas Delaby

Rename All IHandler Class with name "Handler" as it make them easier to imports

dynamically.
As they all belong to a different namespace they can not collide with each other.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43966 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7c3f182a
......@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp
class FFMPEGHandler(object):
"""FFMPEGHandler is used to handler inputed video files"""
class Handler(object):
"""FFMPEG Handler is used to handler inputed video files"""
implements(IHandler)
......
......@@ -27,7 +27,7 @@
##############################################################################
from magic import Magic
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler
from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
......@@ -36,11 +36,11 @@ class TestAllSupportedFormat(HandlerTestCase):
def afterSetUp(self):
self.data = open("./data/test.ogv").read()
self.kw = dict(env=dict(PATH=self.env_path))
self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv", **self.kw)
self.input = Handler(self.tmp_url, self.data, "ogv", **self.kw)
self.file_detector = Magic(mime=True)
def afterFormat(self, data):
ogv_file = FFMPEGHandler(self.tmp_url, data, "avi", **self.kw)
ogv_file = Handler(self.tmp_url, data, "avi", **self.kw)
ogv_data = ogv_file.convert("ogv")
ogv_mimetype = self.file_detector.from_buffer(ogv_data)
return ogv_mimetype
......
......@@ -27,16 +27,16 @@
##############################################################################
import magic
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler
from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
class TestFFMPEGHandler(HandlerTestCase):
class TestHandler(HandlerTestCase):
def afterSetUp(self):
self.data = open("./data/test.ogv").read()
kw = dict(env=dict(PATH=self.env_path))
self.input = FFMPEGHandler(self.tmp_url, self.data, "ogv", **kw)
self.input = Handler(self.tmp_url, self.data, "ogv", **kw)
def testConvertVideo(self):
"""Test coversion of video to another format"""
......@@ -55,4 +55,4 @@ class TestFFMPEGHandler(HandlerTestCase):
def test_suite():
return make_suite(TestFFMPEGHandler)
return make_suite(TestHandler)
......@@ -28,7 +28,7 @@
import unittest
from cloudooo.interfaces.handler import IHandler
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler
from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import make_suite
......@@ -37,8 +37,8 @@ class TestInterface(unittest.TestCase):
def testIHandler(self):
"""Test if Handlers implements IHandler"""
# XXX this might verify FFMPEGHandler methods too
self.assertTrue(IHandler.implementedBy(FFMPEGHandler))
# XXX this might verify Handler methods too
self.assertTrue(IHandler.implementedBy(Handler))
def test_suite():
......
......@@ -34,8 +34,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp
class ImageMagickHandler(object):
"""ImageMagicHandler is used to handler images."""
class Handler(object):
"""ImageMagic Handler is used to handler images."""
implements(IHandler)
......
......@@ -28,11 +28,11 @@
import magic
from cloudooo.handler.imagemagick.handler import ImageMagickHandler
from cloudooo.handler.imagemagick.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
class TestImageMagickHandler(HandlerTestCase):
class TestHandler(HandlerTestCase):
def afterSetUp(self):
self.kw = dict(env=dict(PATH=self.env_path))
......@@ -40,7 +40,7 @@ class TestImageMagickHandler(HandlerTestCase):
def testConvertPNGtoJPG(self):
"""Test conversion of png to jpg"""
png_file = open("data/test.png").read()
handler = ImageMagickHandler(self.tmp_url, png_file, "png", **self.kw)
handler = Handler(self.tmp_url, png_file, "png", **self.kw)
jpg_file = handler.convert("jpg")
mime = magic.Magic(mime=True)
jpg_mimetype = mime.from_buffer(jpg_file)
......@@ -49,7 +49,7 @@ class TestImageMagickHandler(HandlerTestCase):
def testgetMetadataFromImage(self):
"""Test if metadata is extracted from image correctly"""
png_file = open("data/test.png").read()
handler = ImageMagickHandler(self.tmp_url, png_file, "png", **self.kw)
handler = Handler(self.tmp_url, png_file, "png", **self.kw)
metadata = handler.getMetadata()
self.assertEquals(metadata.get("Compression"), "Zip")
self.assertEquals(metadata.get("Colorspace"), "RGB")
......@@ -57,9 +57,9 @@ class TestImageMagickHandler(HandlerTestCase):
def testsetMetadata(self):
""" Test if metadata are inserted correclty """
handler = ImageMagickHandler(self.tmp_url, "", "png", **self.kw)
handler = Handler(self.tmp_url, "", "png", **self.kw)
self.assertRaises(NotImplementedError, handler.setMetadata)
def test_suite():
return make_suite(TestImageMagickHandler)
return make_suite(TestHandler)
......@@ -43,8 +43,8 @@ from cloudooo.utils.utils import logger
from psutil import pid_exists
class OOHandler(object):
"""OOHandler is used to access the one Document and OpenOffice.
class Handler(object):
"""OOO Handler is used to access the one Document and OpenOffice.
For each Document inputed is created on instance of this class to manipulate
the document. This Document must be able to create and remove a temporary
document at FS, load and export.
......
......@@ -28,7 +28,7 @@
import unittest
from cloudooo.handler.ooo.document import FileSystemDocument, OdfDocument
from cloudooo.handler.ooo.handler import OOHandler
from cloudooo.handler.ooo.handler import Handler
from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudooo.manager import Manager
from cloudooo.handler.ooo.mimemapper import MimeMapper
......@@ -142,7 +142,7 @@ class TestInterface(unittest.TestCase):
def testIHandler(self):
"""Test if Handlers implements IHandler"""
self.assertTrue(IHandler.implementedBy(OOHandler))
self.assertTrue(IHandler.implementedBy(Handler))
method_list = ['convert', 'getMetadata', 'setMetadata']
for method in method_list:
self.assertTrue(method in IHandler.names(),
......
......@@ -30,7 +30,7 @@ import magic
from os import path
from base64 import encodestring, decodestring
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from cloudooo.handler.ooo.handler import OOHandler
from cloudooo.handler.ooo.handler import Handler
from cloudooo.handler.ooo.application.openoffice import openoffice
import os
from lxml import etree
......@@ -39,8 +39,8 @@ from zipfile import ZipFile
OPENOFFICE = True
class TestOOHandler(HandlerTestCase):
"""Test OOHandler and manipulation of OOo Instance"""
class TestHandler(HandlerTestCase):
"""Test OOO Handler and manipulation of OOo Instance"""
_file_path_list = []
......@@ -69,7 +69,7 @@ class TestOOHandler(HandlerTestCase):
def testConvertOdtToDoc(self):
"""Test convert ODT to DOC"""
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt')
doc_exported = handler.convert("doc")
......@@ -78,7 +78,7 @@ class TestOOHandler(HandlerTestCase):
def testConvertDocToOdt(self):
"""Test convert DOC to ODT"""
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'doc')
doc_exported = handler.convert("odt")
......@@ -88,7 +88,7 @@ class TestOOHandler(HandlerTestCase):
def testGetMetadata(self):
"""Test getMetadata"""
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt')
metadata = handler.getMetadata()
......@@ -101,20 +101,20 @@ class TestOOHandler(HandlerTestCase):
def testSetMetadata(self):
"""Test setMetadata"""
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt')
new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url,
new_handler = Handler(self.tmp_url,
new_data,
'odt')
metadata = new_handler.getMetadata()
self.assertEquals(metadata.get('Title'), "cloudooo Test -")
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt')
new_data = handler.setMetadata({"Title": "Namie's working record"})
new_handler = OOHandler(self.tmp_url,
new_handler = Handler(self.tmp_url,
new_data,
'odt')
metadata = new_handler.getMetadata()
......@@ -124,7 +124,7 @@ class TestOOHandler(HandlerTestCase):
"""Test convert with openoffice stopped"""
openoffice.stop()
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'doc')
doc_exported = handler.convert("odt")
......@@ -135,7 +135,7 @@ class TestOOHandler(HandlerTestCase):
"""Test getMetadata with openoffice stopped"""
openoffice.stop()
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt')
metadata = handler.getMetadata()
......@@ -147,11 +147,11 @@ class TestOOHandler(HandlerTestCase):
"""Test setMetadata with openoffice stopped"""
openoffice.stop()
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'doc')
new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url,
new_handler = Handler(self.tmp_url,
new_data,
'doc')
metadata = new_handler.getMetadata()
......@@ -161,7 +161,7 @@ class TestOOHandler(HandlerTestCase):
"""Test refresh argument"""
# Check when refreshing is disabled
data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt',
refresh=False)
......@@ -175,7 +175,7 @@ class TestOOHandler(HandlerTestCase):
# Check when refreshing is enabled
data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url,
handler = Handler(self.tmp_url,
decodestring(data),
'odt',
refresh=True)
......@@ -189,4 +189,4 @@ class TestOOHandler(HandlerTestCase):
def test_suite():
return make_suite(TestOOHandler)
return make_suite(TestHandler)
......@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE
from tempfile import mktemp
class PDFHandler(object):
"""PDFHandler is used to handler inputed pdf document."""
class Handler(object):
"""PDF Handler is used to handler inputed pdf document."""
implements(IHandler)
......
......@@ -27,12 +27,12 @@
##############################################################################
from cloudooo.handler.pdf.handler import PDFHandler
from cloudooo.handler.pdf.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from types import DictType
class TestPDFHandler(HandlerTestCase):
class TestHandler(HandlerTestCase):
def afterSetUp(self):
self.kw = dict(env=dict(PATH=self.env_path))
......@@ -40,14 +40,14 @@ class TestPDFHandler(HandlerTestCase):
def testConvertPDFtoText(self):
"""Test conversion of pdf to txt"""
pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw)
handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
txt_document = handler.convert("txt")
self.assertTrue(txt_document.startswith("UNG Docs Architecture"))
def testgetMetadata(self):
"""Test if the metadata are extracted correctly"""
pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw)
handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
metadata = handler.getMetadata()
self.assertEquals(type(metadata), DictType)
self.assertNotEquals(metadata, {})
......@@ -56,14 +56,14 @@ class TestPDFHandler(HandlerTestCase):
def testsetMetadata(self):
"""Test if the metadata is inserted correctly"""
pdf_document = open("data/test.pdf").read()
handler = PDFHandler(self.tmp_url, pdf_document, "pdf", **self.kw)
handler = Handler(self.tmp_url, pdf_document, "pdf", **self.kw)
metadata_dict = {"title": "Set Metadata Test", "creator": "gabriel\'@"}
new_document = handler.setMetadata(metadata_dict)
handler = PDFHandler(self.tmp_url, new_document, "pdf", **self.kw)
handler = Handler(self.tmp_url, new_document, "pdf", **self.kw)
metadata = handler.getMetadata()
self.assertEquals(metadata["title"], 'Set Metadata Test')
self.assertEquals(metadata['creator'], 'gabriel\'@')
def test_suite():
return make_suite(TestPDFHandler)
return make_suite(TestHandler)
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