refactor to remove unsed variable
[cloudooo.git] / cloudooo / handler / ffmpeg / tests / testFfmpegHandler.py
1 ##############################################################################
2 #
3 # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
4 # Priscila Manhaes <psilva@iff.edu.br>
5 #
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
11 # Service Company
12 #
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #
27 ##############################################################################
28
29 from magic import Magic
30 from cloudooo.handler.ffmpeg.handler import Handler
31 from cloudooo.tests.handlerTestCase import HandlerTestCase, make_suite
32
33
34 class TestHandler(HandlerTestCase):
35
36 def afterSetUp(self):
37 self.data = open("./data/test.ogv").read()
38 self.kw = dict(env=dict(PATH=self.env_path))
39 self.input = Handler(self.tmp_url, self.data, "ogv", **self.kw)
40 self.file_detector = Magic(mime=True)
41
42 def testConvertVideo(self):
43 """Test coversion of video to another format"""
44 output_data = self.input.convert("mpeg")
45 file_format = self.file_detector.from_buffer(output_data)
46 self.assertEquals(file_format, 'video/mpeg')
47
48 def testgetMetadata(self):
49 """Test if metadata is extracted from"""
50 output_metadata = self.input.getMetadata()
51 self.assertEquals(output_metadata, {'Encoder': 'Lavf52.64.2'})
52
53 def testsetMetadata(self):
54 """ Test if metadata are inserted correclty """
55 metadata_dict = {"title": "Set Metadata Test", "creator": "cloudooo"}
56 output = self.input.setMetadata(metadata_dict)
57 handler = Handler(self.tmp_url, output, "ogv", **self.kw)
58 metadata = handler.getMetadata()
59 self.assertEquals(metadata["Title"], "Set Metadata Test")
60 self.assertEquals(metadata["Creator"], "cloudooo")
61
62 def testConvertAudio(self):
63 """Test coversion of audio to another format"""
64 self.data = open("./data/test.ogg").read()
65 self.input = Handler(self.tmp_url, self.data, "ogg", **self.kw)
66 output_data = self.input.convert("wav")
67 file_format = self.file_detector.from_buffer(output_data)
68 # XXX this might expect 'audio/vnd.wave' but magic only got 'audio/x-wav'
69 self.assertEquals(file_format, 'audio/x-wav')
70
71
72 def test_suite():
73 return make_suite(TestHandler)