Ticket #5425: 0001-Remove-requirement-that-audio-video-dependencies-mus.patch

File 0001-Remove-requirement-that-audio-video-dependencies-mus.patch, 12.9 KB (added by Christopher Allan Webber, 9 years ago)
  • mediagoblin/tests/test_mgoblin_app.ini

    From bb496d4094d78768eb7651d5004fc4dc3bbed128 Mon Sep 17 00:00:00 2001
    From: Christopher Allan Webber <cwebber@dustycloud.org>
    Date: Tue, 23 Feb 2016 15:14:29 -0800
    Subject: [PATCH] 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.
    ---
     mediagoblin/tests/test_mgoblin_app.ini             |   7 +-
     mediagoblin/tests/test_mgoblin_app_audio.ini       |  20 ++
     mediagoblin/tests/test_mgoblin_app_audio_video.ini |  21 +++
     mediagoblin/tests/test_mgoblin_app_video.ini       |  20 ++
     mediagoblin/tests/test_submission.py               | 206 +++++++++++++++------
     5 files changed, 210 insertions(+), 64 deletions(-)
     create mode 100644 mediagoblin/tests/test_mgoblin_app_audio.ini
     create mode 100644 mediagoblin/tests/test_mgoblin_app_audio_video.ini
     create mode 100644 mediagoblin/tests/test_mgoblin_app_video.ini
    
    diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini
    index 6ac6432..a873f71 100644
    a b BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"  
    3636[[mediagoblin.plugins.basic_auth]]
    3737[[mediagoblin.plugins.openid]]
    3838[[mediagoblin.media_types.image]]
    39 [[mediagoblin.media_types.video]]
    40 [[mediagoblin.media_types.audio]]
    41 [[mediagoblin.media_types.pdf]]
     39## These ones enabled by specific applications
     40# [[mediagoblin.media_types.video]]
     41# [[mediagoblin.media_types.audio]]
     42# [[mediagoblin.media_types.pdf]]
  • new file mediagoblin/tests/test_mgoblin_app_audio.ini

    diff --git a/mediagoblin/tests/test_mgoblin_app_audio.ini b/mediagoblin/tests/test_mgoblin_app_audio.ini
    new file mode 100644
    index 0000000..e3bdb11
    - +  
     1[mediagoblin]
     2#Runs with an in-memory sqlite db for speed.
     3sql_engine = "sqlite://"
     4run_migrations = true
     5
     6[storage:publicstore]
     7base_dir = %(here)s/user_dev/media/public
     8base_url = /mgoblin_media/
     9
     10[storage:queuestore]
     11base_dir = %(here)s/user_dev/media/queue
     12
     13[celery]
     14CELERY_ALWAYS_EAGER = true
     15CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
     16BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
     17
     18[plugins]
     19[[mediagoblin.plugins.basic_auth]]
     20[[mediagoblin.media_types.audio]]
  • new file mediagoblin/tests/test_mgoblin_app_audio_video.ini

    diff --git a/mediagoblin/tests/test_mgoblin_app_audio_video.ini b/mediagoblin/tests/test_mgoblin_app_audio_video.ini
    new file mode 100644
    index 0000000..784015e
    - +  
     1[mediagoblin]
     2#Runs with an in-memory sqlite db for speed.
     3sql_engine = "sqlite://"
     4run_migrations = true
     5
     6[storage:publicstore]
     7base_dir = %(here)s/user_dev/media/public
     8base_url = /mgoblin_media/
     9
     10[storage:queuestore]
     11base_dir = %(here)s/user_dev/media/queue
     12
     13[celery]
     14CELERY_ALWAYS_EAGER = true
     15CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
     16BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
     17
     18[plugins]
     19[[mediagoblin.plugins.basic_auth]]
     20[[mediagoblin.media_types.audio]]
     21[[mediagoblin.media_types.video]]
  • new file mediagoblin/tests/test_mgoblin_app_video.ini

    diff --git a/mediagoblin/tests/test_mgoblin_app_video.ini b/mediagoblin/tests/test_mgoblin_app_video.ini
    new file mode 100644
    index 0000000..8b0e16e
    - +  
     1[mediagoblin]
     2#Runs with an in-memory sqlite db for speed.
     3sql_engine = "sqlite://"
     4run_migrations = true
     5
     6[storage:publicstore]
     7base_dir = %(here)s/user_dev/media/public
     8base_url = /mgoblin_media/
     9
     10[storage:queuestore]
     11base_dir = %(here)s/user_dev/media/queue
     12
     13[celery]
     14CELERY_ALWAYS_EAGER = true
     15CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
     16BROKER_URL = "sqlite:///%(here)s/test_user_dev/kombu.db"
     17
     18[plugins]
     19[[mediagoblin.plugins.basic_auth]]
     20[[mediagoblin.media_types.video]]
  • mediagoblin/tests/test_submission.py

    diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
    index 9a4f464..f51b132 100644
    a b  
    1414# You should have received a copy of the GNU Affero General Public License
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
     17## Optional audio/video stuff
     18
     19SKIP_AUDIO = False
     20SKIP_VIDEO = False
     21
     22try:
     23    import gi.repository.Gst
     24    # this gst initialization stuff is really required here
     25    import gi
     26    gi.require_version('Gst', '1.0')
     27    from gi.repository import Gst
     28    Gst.init(None)
     29    from .media_tools import create_av
     30except ImportError:
     31    SKIP_AUDIO = True
     32    SKIP_VIDEO = True
     33
     34try:
     35    import scikits.audiolab
     36except ImportError:
     37    SKIP_AUDIO = True
     38
    1739import six
    1840
    1941if six.PY2:  # this hack only work in Python 2
    if six.PY2: # this hack only work in Python 2  
    2446import os
    2547import pytest
    2648import webtest.forms
     49import pkg_resources
    2750
    2851import six.moves.urllib.parse as urlparse
    2952
    30 # this gst initialization stuff is really required here
    31 import gi
    32 gi.require_version('Gst', '1.0')
    33 from gi.repository import Gst
    34 Gst.init(None)
    35 
    36 from mediagoblin.tests.tools import fixture_add_user, fixture_add_collection
    37 from .media_tools import create_av
     53from mediagoblin.tests.tools import (
     54    fixture_add_user, fixture_add_collection, get_app)
    3855from mediagoblin import mg_globals
    3956from mediagoblin.db.models import MediaEntry, User, LocalUser, Activity
    4057from mediagoblin.db.base import Session
    FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form']  
    5269REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
    5370
    5471
    55 SKIP_AUDIO = False
    56 SKIP_VIDEO = False
    57 
    58 try:
    59     import gi.repository.Gst
    60 except ImportError:
    61     SKIP_AUDIO = True
    62     SKIP_VIDEO = True
    63 
    64 try:
    65     import scikits.audiolab
    66 except ImportError:
    67     SKIP_AUDIO = True
    68 
    69 
    70 class TestSubmission:
     72@pytest.fixture()
     73def audio_plugin_app(request):
     74    return get_app(
     75        request,
     76        mgoblin_config=pkg_resources.resource_filename(
     77            'mediagoblin.tests',
     78            'test_mgoblin_app_audio.ini'))
     79
     80@pytest.fixture()
     81def video_plugin_app(request):
     82    return get_app(
     83        request,
     84        mgoblin_config=pkg_resources.resource_filename(
     85            'mediagoblin.tests',
     86            'test_mgoblin_app_video.ini'))
     87
     88@pytest.fixture()
     89def audio_video_plugin_app(request):
     90    return get_app(
     91        request,
     92        mgoblin_config=pkg_resources.resource_filename(
     93            'mediagoblin.tests',
     94            'test_mgoblin_app_audio_video.ini'))
     95
     96@pytest.fixture()
     97def pdf_plugin_app(request):
     98    return get_app(
     99        request,
     100        mgoblin_config=pkg_resources.resource_filename(
     101            'mediagoblin.tests',
     102            'test_mgoblin_app_pdf.ini'))
     103
     104
     105class BaseTestSubmission:
    71106    @pytest.fixture(autouse=True)
    72107    def setup(self, test_app):
    73108        self.test_app = test_app
    class TestSubmission:  
    124159        comments = request.db.Comment.query.filter_by(target_id=gmr.id)
    125160        assert count == comments.count()
    126161
    127     def test_missing_fields(self):
    128         # Test blank form
    129         # ---------------
    130         response, form = self.do_post({}, *FORM_CONTEXT)
    131         assert form.file.errors == [u'You must provide a file.']
    132 
    133         # Test blank file
    134         # ---------------
    135         response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)
    136         assert form.file.errors == [u'You must provide a file.']
    137 
    138162    def check_url(self, response, path):
    139163        assert urlparse.urlsplit(response.location)[2] == path
    140164
    class TestSubmission:  
    162186        our_user.save()
    163187        Session.expunge(our_user)
    164188
     189
     190class TestSubmissionBasics(BaseTestSubmission):
     191    def test_missing_fields(self):
     192        # Test blank form
     193        # ---------------
     194        response, form = self.do_post({}, *FORM_CONTEXT)
     195        assert form.file.errors == [u'You must provide a file.']
     196
     197        # Test blank file
     198        # ---------------
     199        response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)
     200        assert form.file.errors == [u'You must provide a file.']
     201
    165202    def test_normal_jpg(self):
    166203        # User uploaded should be 0
    167204        assert self.our_user().uploaded == 0
    class TestSubmission:  
    188225    def test_normal_png(self):
    189226        self.check_normal_upload(u'Normal upload 2', GOOD_PNG)
    190227
    191     @pytest.mark.skipif("not os.path.exists(GOOD_PDF) or not pdf_check_prerequisites()")
    192     def test_normal_pdf(self):
    193         response, context = self.do_post({'title': u'Normal upload 3 (pdf)'},
    194                                          do_follow=True,
    195                                          **self.upload_data(GOOD_PDF))
    196         self.check_url(response, '/u/{0}/'.format(self.our_user().username))
    197         assert 'mediagoblin/user_pages/user.html' in context
    198 
    199228    def test_default_upload_limits(self):
    200229        self.user_upload_limits(uploaded=500)
    201230
    class TestSubmission:  
    404433        media = self.check_media(None, {"title": u"With GPS data"}, 1)
    405434        assert media.get_location.position["latitude"] == 59.336666666666666
    406435
    407     @pytest.mark.skipif(SKIP_AUDIO,
    408                         reason="Dependencies for audio not met")
    409     def test_audio(self):
    410         with create_av(make_audio=True) as path:
    411             self.check_normal_upload('Audio', path)
    412 
    413     @pytest.mark.skipif(SKIP_VIDEO,
    414                         reason="Dependencies for video not met")
    415     def test_video(self):
    416         with create_av(make_video=True) as path:
    417             self.check_normal_upload('Video', path)
    418 
    419     @pytest.mark.skipif(SKIP_AUDIO or SKIP_VIDEO,
    420                         reason="Dependencies for audio or video not met")
    421     def test_audio_and_video(self):
    422         with create_av(make_audio=True, make_video=True) as path:
    423             self.check_normal_upload('Audio and Video', path)
    424 
    425436    def test_processing(self):
    426437        public_store_dir = mg_globals.global_config[
    427438            'storage:publicstore']['base_dir']
    class TestSubmission:  
    507518        assert MediaEntry.query.filter_by(
    508519            actor=self.our_user().id
    509520        ).count() == 3
     521
     522class TestSubmissionVideo(BaseTestSubmission):
     523    @pytest.fixture(autouse=True)
     524    def setup(self, video_plugin_app):
     525        self.test_app = video_plugin_app
     526
     527        # TODO: Possibly abstract into a decorator like:
     528        # @as_authenticated_user('chris')
     529        fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
     530
     531        self.login()
     532
     533    @pytest.mark.skipif(SKIP_VIDEO,
     534                        reason="Dependencies for video not met")
     535    def test_video(self, video_plugin_app):
     536        with create_av(make_video=True) as path:
     537            self.check_normal_upload('Video', path)
     538
     539
     540class TestSubmissionAudio(BaseTestSubmission):
     541    @pytest.fixture(autouse=True)
     542    def setup(self, audio_plugin_app):
     543        self.test_app = audio_plugin_app
     544
     545        # TODO: Possibly abstract into a decorator like:
     546        # @as_authenticated_user('chris')
     547        fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
     548
     549        self.login()
     550
     551    @pytest.mark.skipif(SKIP_AUDIO,
     552                        reason="Dependencies for audio not met")
     553    def test_audio(self, audio_plugin_app):
     554        with create_av(make_audio=True) as path:
     555            self.check_normal_upload('Audio', path)
     556
     557
     558class TestSubmissionAudioVideo(BaseTestSubmission):
     559    @pytest.fixture(autouse=True)
     560    def setup(self, audio_video_plugin_app):
     561        self.test_app = audio_video_plugin_app
     562
     563        # TODO: Possibly abstract into a decorator like:
     564        # @as_authenticated_user('chris')
     565        fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
     566
     567        self.login()
     568
     569    @pytest.mark.skipif(SKIP_AUDIO or SKIP_VIDEO,
     570                        reason="Dependencies for audio or video not met")
     571    def test_audio_and_video(self):
     572        with create_av(make_audio=True, make_video=True) as path:
     573            self.check_normal_upload('Audio and Video', path)
     574
     575
     576class TestSubmissionPDF(BaseTestSubmission):
     577    @pytest.fixture(autouse=True)
     578    def setup(self, pdf_plugin_app):
     579        self.test_app = pdf_plugin_app
     580
     581        # TODO: Possibly abstract into a decorator like:
     582        # @as_authenticated_user('chris')
     583        fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
     584
     585        self.login()
     586
     587    @pytest.mark.skipif("not os.path.exists(GOOD_PDF) or not pdf_check_prerequisites()")
     588    def test_normal_pdf(self):
     589        response, context = self.do_post({'title': u'Normal upload 3 (pdf)'},
     590                                         do_follow=True,
     591                                         **self.upload_data(GOOD_PDF))
     592        self.check_url(response, '/u/{0}/'.format(self.our_user().username))
     593        assert 'mediagoblin/user_pages/user.html' in context