Refactor test resources into new resources.py
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 15 Apr 2013 22:33:38 +0000 (00:33 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 16 Apr 2013 23:15:46 +0000 (01:15 +0200)
mediagoblin/tests/resources.py [new file with mode: 0644]
mediagoblin/tests/test_api.py
mediagoblin/tests/test_exif.py
mediagoblin/tests/test_pdf.py
mediagoblin/tests/test_submission.py

diff --git a/mediagoblin/tests/resources.py b/mediagoblin/tests/resources.py
new file mode 100644 (file)
index 0000000..f7b3037
--- /dev/null
@@ -0,0 +1,41 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2013 MediaGoblin contributors.  See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# 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/>.
+
+
+from pkg_resources import resource_filename
+
+
+def resource(filename):
+    return resource_filename('mediagoblin.tests', 'test_submission/' + filename)
+
+
+GOOD_JPG = resource('good.jpg')
+GOOD_PNG = resource('good.png')
+EVIL_FILE = resource('evil')
+EVIL_JPG = resource('evil.jpg')
+EVIL_PNG = resource('evil.png')
+BIG_BLUE = resource('bigblue.png')
+GOOD_PDF = resource('good.pdf')
+
+
+def resource_exif(f):
+    return resource_filename('mediagoblin.tests', 'test_exif/' + f)
+
+
+GOOD_JPG = resource_exif('good.jpg')
+EMPTY_JPG = resource_exif('empty.jpg')
+BAD_JPG = resource_exif('bad.jpg')
+GPS_JPG = resource_exif('has-gps.jpg')
index cff25776851f68ff5d8a756502ce659f5749382c..89cf1026ff400424911bf1f88079c6eb1509ab67 100644 (file)
 import logging
 import base64
 
-from pkg_resources import resource_filename
-
 import pytest
 
 from mediagoblin import mg_globals
 from mediagoblin.tools import template, pluginapi
 from mediagoblin.tests.tools import fixture_add_user
+from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \
+    BIG_BLUE
 
 
 _log = logging.getLogger(__name__)
 
-def resource(filename):
-    '''
-    Borrowed from the submission tests
-    '''
-    return resource_filename('mediagoblin.tests', 'test_submission/' + filename)
-
-
-GOOD_JPG = resource('good.jpg')
-GOOD_PNG = resource('good.png')
-EVIL_FILE = resource('evil')
-EVIL_JPG = resource('evil.jpg')
-EVIL_PNG = resource('evil.png')
-BIG_BLUE = resource('bigblue.png')
-
 
 class TestAPI(object):
     def setup(self):
index 100d17f03f2a32b8c317b5ea880885141f4931f0..5eeaa6763cac6236f2ac415992f8596d1c7285c9 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
-import pkg_resources
 import Image
 
 from mediagoblin.tools.exif import exif_fix_image_orientation, \
     extract_exif, clean_exif, get_gps_data, get_useful
+from .resources import GOOD_JPG, EMPTY_JPG, BAD_JPG, GPS_JPG
 
 
 def assert_in(a, b):
     assert a in b, "%r not in %r" % (a, b)
 
 
-GOOD_JPG = pkg_resources.resource_filename(
-    'mediagoblin.tests',
-    os.path.join(
-        'test_exif',
-        'good.jpg'))
-EMPTY_JPG = pkg_resources.resource_filename(
-    'mediagoblin.tests',
-    os.path.join(
-        'test_exif',
-        'empty.jpg'))
-BAD_JPG = pkg_resources.resource_filename(
-    'mediagoblin.tests',
-    os.path.join(
-        'test_exif',
-        'bad.jpg'))
-GPS_JPG = pkg_resources.resource_filename(
-    'mediagoblin.tests',
-    os.path.join(
-        'test_exif',
-        'has-gps.jpg'))
-
-
 def test_exif_extraction():
     '''
     Test EXIF extraction from a good image
index b8c21bdb5265dbd39774c73e7684ee16f8e8b2db..b4d1940a1a0931c9d97ad26d52980d3cc0ef7fc5 100644 (file)
@@ -21,8 +21,8 @@ import pytest
 
 from mediagoblin.media_types.pdf.processing import (
     pdf_info, check_prerequisites, create_pdf_thumb)
+from .resources import GOOD_PDF as GOOD
 
-GOOD='mediagoblin/tests/test_submission/good.pdf'
 
 @pytest.mark.skipif("not check_prerequisites()")
 def test_pdf():
index 7c9b3115d1cfe6306743160e93d9d45a1d190592..d9c7ca4699d5eefdfc8d104e73e52d8d2c16c4a0 100644 (file)
@@ -22,8 +22,6 @@ import urlparse
 import os
 import pytest
 
-from pkg_resources import resource_filename
-
 from mediagoblin.tests.tools import fixture_add_user
 from mediagoblin import mg_globals
 from mediagoblin.db.models import MediaEntry
@@ -31,19 +29,8 @@ from mediagoblin.tools import template
 from mediagoblin.media_types.image import MEDIA_MANAGER as img_MEDIA_MANAGER
 from mediagoblin.media_types.pdf.processing import check_prerequisites as pdf_check_prerequisites
 
-def resource(filename):
-    return resource_filename('mediagoblin.tests', 'test_submission/' + filename)
-
-
-GOOD_JPG = resource('good.jpg')
-GOOD_PNG = resource('good.png')
-EVIL_FILE = resource('evil')
-EVIL_JPG = resource('evil.jpg')
-EVIL_PNG = resource('evil.png')
-BIG_BLUE = resource('bigblue.png')
-GOOD_PDF = resource('good.pdf')
-
-from .test_exif import GPS_JPG
+from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \
+    BIG_BLUE, GOOD_PDF, GPS_JPG
 
 GOOD_TAG_STRING = u'yin,yang'
 BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26)