# 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/>.
+## Optional audio/video stuff
+
+SKIP_AUDIO = False
+SKIP_VIDEO = False
+
+try:
+ import gi.repository.Gst
+ # 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 .media_tools import create_av
+except ImportError:
+ SKIP_AUDIO = True
+ SKIP_VIDEO = True
+
+try:
+ import scikits.audiolab
+except ImportError:
+ SKIP_AUDIO = True
+
import six
if six.PY2: # this hack only work in Python 2
import os
import pytest
import webtest.forms
+import pkg_resources
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, fixture_add_collection
-from .media_tools import create_av
+from mediagoblin.tests.tools import (
+ fixture_add_user, fixture_add_collection, get_app)
from mediagoblin import mg_globals
from mediagoblin.db.models import MediaEntry, User, LocalUser, Activity
from mediagoblin.db.base import Session
REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
-SKIP_AUDIO = False
-SKIP_VIDEO = False
-
-try:
- import gi.repository.Gst
-except ImportError:
- SKIP_AUDIO = True
- SKIP_VIDEO = True
-
-try:
- import scikits.audiolab
-except ImportError:
- SKIP_AUDIO = True
-
-
-class TestSubmission:
+@pytest.fixture()
+def audio_plugin_app(request):
+ return get_app(
+ request,
+ mgoblin_config=pkg_resources.resource_filename(
+ 'mediagoblin.tests',
+ 'test_mgoblin_app_audio.ini'))
+
+@pytest.fixture()
+def video_plugin_app(request):
+ return get_app(
+ request,
+ mgoblin_config=pkg_resources.resource_filename(
+ 'mediagoblin.tests',
+ 'test_mgoblin_app_video.ini'))
+
+@pytest.fixture()
+def audio_video_plugin_app(request):
+ return get_app(
+ request,
+ mgoblin_config=pkg_resources.resource_filename(
+ 'mediagoblin.tests',
+ 'test_mgoblin_app_audio_video.ini'))
+
+@pytest.fixture()
+def pdf_plugin_app(request):
+ return get_app(
+ request,
+ mgoblin_config=pkg_resources.resource_filename(
+ 'mediagoblin.tests',
+ 'test_mgoblin_app_pdf.ini'))
+
+
+class BaseTestSubmission:
@pytest.fixture(autouse=True)
def setup(self, test_app):
self.test_app = test_app
comments = request.db.Comment.query.filter_by(target_id=gmr.id)
assert count == comments.count()
- def test_missing_fields(self):
- # Test blank form
- # ---------------
- response, form = self.do_post({}, *FORM_CONTEXT)
- assert form.file.errors == [u'You must provide a file.']
-
- # Test blank file
- # ---------------
- response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)
- assert form.file.errors == [u'You must provide a file.']
-
def check_url(self, response, path):
assert urlparse.urlsplit(response.location)[2] == path
our_user.save()
Session.expunge(our_user)
+
+class TestSubmissionBasics(BaseTestSubmission):
+ def test_missing_fields(self):
+ # Test blank form
+ # ---------------
+ response, form = self.do_post({}, *FORM_CONTEXT)
+ assert form.file.errors == [u'You must provide a file.']
+
+ # Test blank file
+ # ---------------
+ response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)
+ assert form.file.errors == [u'You must provide a file.']
+
def test_normal_jpg(self):
# User uploaded should be 0
assert self.our_user().uploaded == 0
def test_normal_png(self):
self.check_normal_upload(u'Normal upload 2', GOOD_PNG)
- @pytest.mark.skipif("not os.path.exists(GOOD_PDF) or not pdf_check_prerequisites()")
- def test_normal_pdf(self):
- response, context = self.do_post({'title': u'Normal upload 3 (pdf)'},
- do_follow=True,
- **self.upload_data(GOOD_PDF))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
- assert 'mediagoblin/user_pages/user.html' in context
-
def test_default_upload_limits(self):
self.user_upload_limits(uploaded=500)
media = self.check_media(None, {"title": u"With GPS data"}, 1)
assert media.get_location.position["latitude"] == 59.336666666666666
- @pytest.mark.skipif(SKIP_AUDIO,
- reason="Dependencies for audio not met")
- def test_audio(self):
- with create_av(make_audio=True) as path:
- self.check_normal_upload('Audio', path)
-
- @pytest.mark.skipif(SKIP_VIDEO,
- reason="Dependencies for video not met")
- def test_video(self):
- with create_av(make_video=True) as path:
- self.check_normal_upload('Video', path)
-
- @pytest.mark.skipif(SKIP_AUDIO or SKIP_VIDEO,
- reason="Dependencies for audio or video not met")
- 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']
assert MediaEntry.query.filter_by(
actor=self.our_user().id
).count() == 3
+
+class TestSubmissionVideo(BaseTestSubmission):
+ @pytest.fixture(autouse=True)
+ def setup(self, video_plugin_app):
+ self.test_app = video_plugin_app
+
+ # TODO: Possibly abstract into a decorator like:
+ # @as_authenticated_user('chris')
+ fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+
+ self.login()
+
+ @pytest.mark.skipif(SKIP_VIDEO,
+ reason="Dependencies for video not met")
+ def test_video(self, video_plugin_app):
+ with create_av(make_video=True) as path:
+ self.check_normal_upload('Video', path)
+
+
+class TestSubmissionAudio(BaseTestSubmission):
+ @pytest.fixture(autouse=True)
+ def setup(self, audio_plugin_app):
+ self.test_app = audio_plugin_app
+
+ # TODO: Possibly abstract into a decorator like:
+ # @as_authenticated_user('chris')
+ fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+
+ self.login()
+
+ @pytest.mark.skipif(SKIP_AUDIO,
+ reason="Dependencies for audio not met")
+ def test_audio(self, audio_plugin_app):
+ with create_av(make_audio=True) as path:
+ self.check_normal_upload('Audio', path)
+
+
+class TestSubmissionAudioVideo(BaseTestSubmission):
+ @pytest.fixture(autouse=True)
+ def setup(self, audio_video_plugin_app):
+ self.test_app = audio_video_plugin_app
+
+ # TODO: Possibly abstract into a decorator like:
+ # @as_authenticated_user('chris')
+ fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+
+ self.login()
+
+ @pytest.mark.skipif(SKIP_AUDIO or SKIP_VIDEO,
+ reason="Dependencies for audio or video not met")
+ 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)
+
+
+class TestSubmissionPDF(BaseTestSubmission):
+ @pytest.fixture(autouse=True)
+ def setup(self, pdf_plugin_app):
+ self.test_app = pdf_plugin_app
+
+ # TODO: Possibly abstract into a decorator like:
+ # @as_authenticated_user('chris')
+ fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+
+ self.login()
+
+ @pytest.mark.skipif("not os.path.exists(GOOD_PDF) or not pdf_check_prerequisites()")
+ def test_normal_pdf(self):
+ response, context = self.do_post({'title': u'Normal upload 3 (pdf)'},
+ do_follow=True,
+ **self.upload_data(GOOD_PDF))
+ self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ assert 'mediagoblin/user_pages/user.html' in context