Remove requirement that audio/video dependencies must be installed for tests
authorChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 23 Feb 2016 23:14:29 +0000 (15:14 -0800)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 18 Mar 2016 19:32:22 +0000 (12:32 -0700)
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.

mediagoblin/tests/test_mgoblin_app.ini
mediagoblin/tests/test_mgoblin_app_audio.ini [new file with mode: 0644]
mediagoblin/tests/test_mgoblin_app_audio_video.ini [new file with mode: 0644]
mediagoblin/tests/test_mgoblin_app_video.ini [new file with mode: 0644]
mediagoblin/tests/test_submission.py

index 6ac643216d6a17d553d4bf91e8c7c4b97cb168ca..a873f71fe9c7cb1b2fcae50a00bb47cb3258b5f9 100644 (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]]
diff --git a/mediagoblin/tests/test_mgoblin_app_audio.ini b/mediagoblin/tests/test_mgoblin_app_audio.ini
new file mode 100644 (file)
index 0000000..e3bdb11
--- /dev/null
@@ -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]]
diff --git a/mediagoblin/tests/test_mgoblin_app_audio_video.ini b/mediagoblin/tests/test_mgoblin_app_audio_video.ini
new file mode 100644 (file)
index 0000000..784015e
--- /dev/null
@@ -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]]
diff --git a/mediagoblin/tests/test_mgoblin_app_video.ini b/mediagoblin/tests/test_mgoblin_app_video.ini
new file mode 100644 (file)
index 0000000..8b0e16e
--- /dev/null
@@ -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]]
index 9a4f4645c884e68d9fb11720797fb057c7677402..f51b132c5bb8303c5948301f3ed8f32a4df37007 100644 (file)
 # 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
-
-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
@@ -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