From 5f8b4ae895ecb228c5f5d615818ffe0a06a30473 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 4 Dec 2012 09:57:56 +0100 Subject: make media_manager a property of MediaEntry in mixin.py In all cases where get_media_manager(_media_type_as_string) was called in our code base we ultimately passed in a "MediaEntry().media_type" to get the matching MEDIA_MANAGER. It so makes sense to make this a function of the MediaEntry rather than a global function in mediagoblin.media_types and passing around media_entry.media_type as arguments all the time. It saves a few import statements and arguments. I also made it so the Media_manager property is cached for subsequent calls, although I am not too sure that this is needed (there are other cases for which this would make more sense) Also add a get_media_manager test to the media submission tests. It submits an image and checks that both media.media_type and media.media_manager return the right thing. Not sure if these tests could not be merged with an existing submission test, but it can't hurt to have things explicit. TODO: Right now we iterate through all existing media_managers to find the right one based on the string of its module name. This should be made a simple dict lookup to avoid all the extra work. Signed-off-by: Sebastian Spaeth --- mediagoblin/tests/test_submission.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index b7b0e574..b6fe0015 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -28,7 +28,7 @@ from mediagoblin.tests.tools import get_test_app, \ fixture_add_user from mediagoblin import mg_globals from mediagoblin.tools import template - +from mediagoblin.media_types.image import MEDIA_MANAGER as img_MEDIA_MANAGER def resource(filename): return resource_filename('mediagoblin.tests', 'test_submission/' + filename) @@ -197,6 +197,19 @@ class TestSubmission: assert 'Sorry, I don\'t support that file type :(' == \ str(form.file.errors[0]) + + def test_get_media_manager(self): + """Test if the get_media_manger function returns sensible things + """ + response, request = self.do_post({'title': u'Balanced Goblin'}, + *REQUEST_CONTEXT, do_follow=True, + **self.upload_data(GOOD_JPG)) + media = self.check_media(request, {'title': u'Balanced Goblin'}, 1) + + assert_equal(media.media_type, u'mediagoblin.media_types.image') + assert_equal(media.media_manager, img_MEDIA_MANAGER) + + def test_sniffing(self): ''' Test sniffing mechanism to assert that regular uploads work as intended -- cgit v1.2.3