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 , 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" 36 36 [[mediagoblin.plugins.basic_auth]] 37 37 [[mediagoblin.plugins.openid]] 38 38 [[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. 3 sql_engine = "sqlite://" 4 run_migrations = true 5 6 [storage:publicstore] 7 base_dir = %(here)s/user_dev/media/public 8 base_url = /mgoblin_media/ 9 10 [storage:queuestore] 11 base_dir = %(here)s/user_dev/media/queue 12 13 [celery] 14 CELERY_ALWAYS_EAGER = true 15 CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db" 16 BROKER_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. 3 sql_engine = "sqlite://" 4 run_migrations = true 5 6 [storage:publicstore] 7 base_dir = %(here)s/user_dev/media/public 8 base_url = /mgoblin_media/ 9 10 [storage:queuestore] 11 base_dir = %(here)s/user_dev/media/queue 12 13 [celery] 14 CELERY_ALWAYS_EAGER = true 15 CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db" 16 BROKER_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. 3 sql_engine = "sqlite://" 4 run_migrations = true 5 6 [storage:publicstore] 7 base_dir = %(here)s/user_dev/media/public 8 base_url = /mgoblin_media/ 9 10 [storage:queuestore] 11 base_dir = %(here)s/user_dev/media/queue 12 13 [celery] 14 CELERY_ALWAYS_EAGER = true 15 CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db" 16 BROKER_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 14 14 # You should have received a copy of the GNU Affero General Public License 15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 17 ## Optional audio/video stuff 18 19 SKIP_AUDIO = False 20 SKIP_VIDEO = False 21 22 try: 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 30 except ImportError: 31 SKIP_AUDIO = True 32 SKIP_VIDEO = True 33 34 try: 35 import scikits.audiolab 36 except ImportError: 37 SKIP_AUDIO = True 38 17 39 import six 18 40 19 41 if six.PY2: # this hack only work in Python 2 … … if six.PY2: # this hack only work in Python 2 24 46 import os 25 47 import pytest 26 48 import webtest.forms 49 import pkg_resources 27 50 28 51 import six.moves.urllib.parse as urlparse 29 52 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 53 from mediagoblin.tests.tools import ( 54 fixture_add_user, fixture_add_collection, get_app) 38 55 from mediagoblin import mg_globals 39 56 from mediagoblin.db.models import MediaEntry, User, LocalUser, Activity 40 57 from mediagoblin.db.base import Session … … FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form'] 52 69 REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request'] 53 70 54 71 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() 73 def 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() 81 def 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() 89 def 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() 97 def 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 105 class BaseTestSubmission: 71 106 @pytest.fixture(autouse=True) 72 107 def setup(self, test_app): 73 108 self.test_app = test_app … … class TestSubmission: 124 159 comments = request.db.Comment.query.filter_by(target_id=gmr.id) 125 160 assert count == comments.count() 126 161 127 def test_missing_fields(self):128 # Test blank form129 # ---------------130 response, form = self.do_post({}, *FORM_CONTEXT)131 assert form.file.errors == [u'You must provide a file.']132 133 # Test blank file134 # ---------------135 response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)136 assert form.file.errors == [u'You must provide a file.']137 138 162 def check_url(self, response, path): 139 163 assert urlparse.urlsplit(response.location)[2] == path 140 164 … … class TestSubmission: 162 186 our_user.save() 163 187 Session.expunge(our_user) 164 188 189 190 class 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 165 202 def test_normal_jpg(self): 166 203 # User uploaded should be 0 167 204 assert self.our_user().uploaded == 0 … … class TestSubmission: 188 225 def test_normal_png(self): 189 226 self.check_normal_upload(u'Normal upload 2', GOOD_PNG) 190 227 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 context198 199 228 def test_default_upload_limits(self): 200 229 self.user_upload_limits(uploaded=500) 201 230 … … class TestSubmission: 404 433 media = self.check_media(None, {"title": u"With GPS data"}, 1) 405 434 assert media.get_location.position["latitude"] == 59.336666666666666 406 435 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 425 436 def test_processing(self): 426 437 public_store_dir = mg_globals.global_config[ 427 438 'storage:publicstore']['base_dir'] … … class TestSubmission: 507 518 assert MediaEntry.query.filter_by( 508 519 actor=self.our_user().id 509 520 ).count() == 3 521 522 class 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 540 class 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 558 class 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 576 class 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