Refactor test resources into new resources.py
This commit is contained in:
parent
54b3113abc
commit
b698c94d03
41
mediagoblin/tests/resources.py
Normal file
41
mediagoblin/tests/resources.py
Normal file
@ -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')
|
@ -18,31 +18,17 @@
|
|||||||
import logging
|
import logging
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from pkg_resources import resource_filename
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.tools import template, pluginapi
|
from mediagoblin.tools import template, pluginapi
|
||||||
from mediagoblin.tests.tools import fixture_add_user
|
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__)
|
_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):
|
class TestAPI(object):
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
@ -15,39 +15,17 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
|
||||||
import Image
|
import Image
|
||||||
|
|
||||||
from mediagoblin.tools.exif import exif_fix_image_orientation, \
|
from mediagoblin.tools.exif import exif_fix_image_orientation, \
|
||||||
extract_exif, clean_exif, get_gps_data, get_useful
|
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):
|
def assert_in(a, b):
|
||||||
assert a in b, "%r not in %r" % (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():
|
def test_exif_extraction():
|
||||||
'''
|
'''
|
||||||
Test EXIF extraction from a good image
|
Test EXIF extraction from a good image
|
||||||
|
@ -21,8 +21,8 @@ import pytest
|
|||||||
|
|
||||||
from mediagoblin.media_types.pdf.processing import (
|
from mediagoblin.media_types.pdf.processing import (
|
||||||
pdf_info, check_prerequisites, create_pdf_thumb)
|
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()")
|
@pytest.mark.skipif("not check_prerequisites()")
|
||||||
def test_pdf():
|
def test_pdf():
|
||||||
|
@ -22,8 +22,6 @@ import urlparse
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pkg_resources import resource_filename
|
|
||||||
|
|
||||||
from mediagoblin.tests.tools import fixture_add_user
|
from mediagoblin.tests.tools import fixture_add_user
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.db.models import MediaEntry
|
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.image import MEDIA_MANAGER as img_MEDIA_MANAGER
|
||||||
from mediagoblin.media_types.pdf.processing import check_prerequisites as pdf_check_prerequisites
|
from mediagoblin.media_types.pdf.processing import check_prerequisites as pdf_check_prerequisites
|
||||||
|
|
||||||
def resource(filename):
|
from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \
|
||||||
return resource_filename('mediagoblin.tests', 'test_submission/' + filename)
|
BIG_BLUE, GOOD_PDF, GPS_JPG
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
GOOD_TAG_STRING = u'yin,yang'
|
GOOD_TAG_STRING = u'yin,yang'
|
||||||
BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26)
|
BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user