Remove requirement that audio/video dependencies must be installed for tests

Some tests were added for running audio and video submission tests in
test_submission.py.  Unfortunately these were not skipped if these
dependencies were not installed.  This patch attempts to fix that while
leaving the tests intact.
This commit is contained in:
Christopher Allan Webber 2016-02-23 15:14:29 -08:00
parent 339cfb3894
commit 0ce775ac2a
5 changed files with 206 additions and 60 deletions

View File

@ -36,6 +36,7 @@ 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]]
## These ones enabled by specific applications
# [[mediagoblin.media_types.video]]
# [[mediagoblin.media_types.audio]]
# [[mediagoblin.media_types.pdf]]

View File

@ -0,0 +1,20 @@
[mediagoblin]
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
[storage:publicstore]
base_dir = %(here)s/user_dev/media/public
base_url = /mgoblin_media/
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
[celery]
CELERY_ALWAYS_EAGER = true
CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
[plugins]
[[mediagoblin.plugins.basic_auth]]
[[mediagoblin.media_types.audio]]

View File

@ -0,0 +1,21 @@
[mediagoblin]
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
[storage:publicstore]
base_dir = %(here)s/user_dev/media/public
base_url = /mgoblin_media/
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
[celery]
CELERY_ALWAYS_EAGER = true
CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
[plugins]
[[mediagoblin.plugins.basic_auth]]
[[mediagoblin.media_types.audio]]
[[mediagoblin.media_types.video]]

View File

@ -0,0 +1,20 @@
[mediagoblin]
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
[storage:publicstore]
base_dir = %(here)s/user_dev/media/public
base_url = /mgoblin_media/
[storage:queuestore]
base_dir = %(here)s/user_dev/media/queue
[celery]
CELERY_ALWAYS_EAGER = true
CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
[plugins]
[[mediagoblin.plugins.basic_auth]]
[[mediagoblin.media_types.video]]

View File

@ -14,6 +14,28 @@
# 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
@ -24,17 +46,12 @@ 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
@ -52,22 +69,40 @@ FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form']
REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
SKIP_AUDIO = False
SKIP_VIDEO = False
@pytest.fixture()
def audio_plugin_app(request):
return get_app(
request,
mgoblin_config=pkg_resources.resource_filename(
'mediagoblin.tests',
'test_mgoblin_app_audio.ini'))
try:
import gi.repository.Gst
except ImportError:
SKIP_AUDIO = True
SKIP_VIDEO = True
@pytest.fixture()
def video_plugin_app(request):
return get_app(
request,
mgoblin_config=pkg_resources.resource_filename(
'mediagoblin.tests',
'test_mgoblin_app_video.ini'))
try:
import scikits.audiolab
except ImportError:
SKIP_AUDIO = True
@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 TestSubmission:
class BaseTestSubmission:
@pytest.fixture(autouse=True)
def setup(self, test_app):
self.test_app = test_app
@ -124,17 +159,6 @@ class TestSubmission:
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
@ -162,6 +186,19 @@ class TestSubmission:
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
@ -188,14 +225,6 @@ class TestSubmission:
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)
@ -404,24 +433,6 @@ class TestSubmission:
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']
@ -507,3 +518,76 @@ class TestSubmission:
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