Commit 1ed7870d authored by Priscila Manhaes's avatar Priscila Manhaes

Implementing Ihandler into FFMPEGHandler and adding test for its server

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43642 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1f86098f
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
# #
############################################################################## ##############################################################################
from zope.interface import implements
from cloudooo.interfaces.handler import IHandler
from cloudooo.file import File from cloudooo.file import File
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from tempfile import mktemp from tempfile import mktemp
...@@ -34,6 +35,8 @@ from tempfile import mktemp ...@@ -34,6 +35,8 @@ from tempfile import mktemp
class FFMPEGHandler(object): class FFMPEGHandler(object):
"""FFMPEGHandler is used to handler inputed video files""" """FFMPEGHandler is used to handler inputed video files"""
implements(IHandler)
def __init__(self, base_folder_url, data, source_format, **kw): def __init__(self, base_folder_url, data, source_format, **kw):
""" """
...@@ -69,3 +72,16 @@ class FFMPEGHandler(object): ...@@ -69,3 +72,16 @@ class FFMPEGHandler(object):
return self.input.getContent() return self.input.getContent()
finally: finally:
self.input.trash() self.input.trash()
def getMetadata(self, base_document=False):
"""Returns a dictionary with all metadata of the video.
Keywords Arguments:
base_document -- Boolean variable. if true, the video is also returned
along with the metadata."""
def setMetadata(self, metadata):
"""Returns a document with new metadata.
Keyword arguments:
metadata -- expected an dictionary with metadata.
"""
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Priscila Manhaes <psilva@iff.edu.br>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from cloudooo.interfaces.handler import IHandler
from cloudooo.handler.ffmpeg.handler import FFMPEGHandler
from cloudooo.handler.tests.handlerTestCase import make_suite
class TestInterface(unittest.TestCase):
"""Test IHandler Interface"""
def testIHandler(self):
"""Test if Handlers implements IHandler"""
self.assertTrue(IHandler.implementedBy(FFMPEGHandler))
method_list = ['convert', 'getMetadata', 'setMetadata']
for method in method_list:
self.assertTrue(method in IHandler.names(),
"Method %s is not declared" % method)
self.assertEquals(len(method_list), len(IHandler.names()))
self.assertEquals(IHandler.get('convert').required, ('destination_format',))
self.assertEquals(IHandler.get('getMetadata').required,
('converted_data',))
self.assertEquals(IHandler.get('setMetadata').required,
('metadata_dict',))
def test_suite():
return make_suite(TestInterface)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestInterface)
unittest.TextTestRunner(verbosity=2).run(suite)
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Priscila Manhaes <psilva@iff.edu.br>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
from xmlrpclib import ServerProxy
from os.path import join
from base64 import encodestring, decodestring
from magic import Magic
DAEMON = True
class TestServer(HandlerTestCase):
"""Test XmlRpc Server. Needs cloudooo server started"""
def afterSetUp(self):
"""Creates a connection with cloudooo server"""
self.proxy = ServerProxy("http://%s:%s/RPC2" % \
(self.hostname, self.cloudooo_port), allow_none=True)
def testConvertPDFtoTxt(self):
"""Converts ogv video to mpeg format"""
data = open(join('data', 'test.ogv'), 'r').read()
video = self.proxy.convertFile(encodestring(data),
"ogv",
"mpeg")
mime = Magic(mime=True)
mimetype = mime.from_buffer(decodestring(video))
self.assertEquals(mimetype, 'video/mpeg')
def testGetMetadata(self):
"""test if metadata are extracted correctly"""
def testSetMetadata(self):
"""Test if metadata is inserted correctly"""
def test_suite():
return make_suite(TestServer)
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