diff options
author | Boris Bobrov <breton@cynicmansion.ru> | 2014-06-20 07:18:33 +0400 |
---|---|---|
committer | Boris Bobrov <breton@cynicmansion.ru> | 2015-02-16 13:41:09 +0300 |
commit | c41705bffc2bcee3e283f39f2c479f8c852e6b8b (patch) | |
tree | c126de44895ea3de9a3a594a269ec09a368d9c3a /mediagoblin | |
parent | 919cd2fd4101e01a5295cb08ce0947e47fc425bb (diff) | |
download | mediagoblin-c41705bffc2bcee3e283f39f2c479f8c852e6b8b.tar.lz mediagoblin-c41705bffc2bcee3e283f39f2c479f8c852e6b8b.tar.xz mediagoblin-c41705bffc2bcee3e283f39f2c479f8c852e6b8b.zip |
added a/v submission testing
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/tests/media_tools.py | 61 | ||||
-rw-r--r-- | mediagoblin/tests/test_mgoblin_app.ini | 2 | ||||
-rw-r--r-- | mediagoblin/tests/test_submission.py | 19 |
3 files changed, 82 insertions, 0 deletions
diff --git a/mediagoblin/tests/media_tools.py b/mediagoblin/tests/media_tools.py new file mode 100644 index 00000000..8d58c024 --- /dev/null +++ b/mediagoblin/tests/media_tools.py @@ -0,0 +1,61 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2013 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from contextlib import contextmanager +import tempfile + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst +Gst.init(None) + +@contextmanager +def create_av(make_video=False, make_audio=False): + 'creates audio/video in `path`, throws AssertionError on any error' + media = tempfile.NamedTemporaryFile(suffix='.ogg') + pipeline = Gst.Pipeline() + mux = Gst.ElementFactory.make('oggmux', 'mux') + pipeline.add(mux) + if make_video: + video_src = Gst.ElementFactory.make('videotestsrc', 'video_src') + video_src.set_property('num-buffers', 20) + video_enc = Gst.ElementFactory.make('theoraenc', 'video_enc') + pipeline.add(video_src) + pipeline.add(video_enc) + assert video_src.link(video_enc) + assert video_enc.link(mux) + if make_audio: + audio_src = Gst.ElementFactory.make('audiotestsrc', 'audio_src') + audio_src.set_property('num-buffers', 20) + audio_enc = Gst.ElementFactory.make('vorbisenc', 'audio_enc') + pipeline.add(audio_src) + pipeline.add(audio_enc) + assert audio_src.link(audio_enc) + assert audio_enc.link(mux) + sink = Gst.ElementFactory.make('filesink', 'sink') + sink.set_property('location', media.name) + pipeline.add(sink) + mux.link(sink) + pipeline.set_state(Gst.State.PLAYING) + state = pipeline.get_state(Gst.SECOND) + assert state[0] == Gst.StateChangeReturn.SUCCESS + bus = pipeline.get_bus() + message = bus.timed_pop_filtered( + Gst.SECOND, # one second should be more than enough for 50-buf vid + Gst.MessageType.ERROR | Gst.MessageType.EOS) + assert message.type == Gst.MessageType.EOS + pipeline.set_state(Gst.State.NULL) + yield media.name diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini index 4cd3d9b6..6bc450cb 100644 --- a/mediagoblin/tests/test_mgoblin_app.ini +++ b/mediagoblin/tests/test_mgoblin_app.ini @@ -37,4 +37,6 @@ BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db" [[mediagoblin.plugins.basic_auth]] [[mediagoblin.plugins.openid]] [[mediagoblin.media_types.image]] +[[mediagoblin.media_types.video]] +[[mediagoblin.media_types.audio]] [[mediagoblin.media_types.pdf]] diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 03d255fb..65c4b3a3 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -26,7 +26,14 @@ import pytest import six.moves.urllib.parse as urlparse +# this gst initialization stuff is really required here +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst +Gst.init(None) + from mediagoblin.tests.tools import fixture_add_user +from .media_tools import create_av from mediagoblin import mg_globals from mediagoblin.db.models import MediaEntry, User from mediagoblin.db.base import Session @@ -365,6 +372,18 @@ class TestSubmission: media = self.check_media(None, {"title": u"With GPS data"}, 1) assert media.get_location.position["latitude"] == 59.336666666666666 + def test_audio(self): + with create_av(make_audio=True) as path: + self.check_normal_upload('Audio', path) + + def test_video(self): + with create_av(make_video=True) as path: + self.check_normal_upload('Video', path) + + def test_audio_and_video(self): + with create_av(make_audio=True, make_video=True) as path: + self.check_normal_upload('Audio and Video', path) + def test_processing(self): public_store_dir = mg_globals.global_config[ 'storage:publicstore']['base_dir'] |