Tests should no longer use the environment-variable-related-setup and set up in app instead
This should remove a bunch of confusing cruft. I hate using that environment variable! Also that old code was fragile. This commit sponsored by Stephen Milton. Thanks!
This commit is contained in:
parent
8145547437
commit
a98c95b41d
@ -1,33 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 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/>.
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from mediagoblin.tests.tools import TEST_APP_CONFIG
|
|
||||||
from mediagoblin.init.celery.from_celery import setup_self
|
|
||||||
|
|
||||||
|
|
||||||
OUR_MODULENAME = __name__
|
|
||||||
CELERY_SETUP = False
|
|
||||||
|
|
||||||
|
|
||||||
if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
|
|
||||||
if CELERY_SETUP:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME,
|
|
||||||
default_conf_file=TEST_APP_CONFIG)
|
|
||||||
CELERY_SETUP = True
|
|
@ -18,12 +18,10 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.tests.tools import (
|
from mediagoblin.tests.tools import TEST_USER_DEV
|
||||||
TEST_USER_DEV, suicide_if_bad_celery_environ)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_package():
|
def setup_package():
|
||||||
suicide_if_bad_celery_environ()
|
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from sqlalchemy.exc import SAWarning
|
from sqlalchemy.exc import SAWarning
|
||||||
|
@ -12,10 +12,6 @@ tags_max_length = 50
|
|||||||
# So we can start to test attachments:
|
# So we can start to test attachments:
|
||||||
allow_attachments = True
|
allow_attachments = True
|
||||||
|
|
||||||
# Celery shouldn't be set up by the application as it's setup via
|
|
||||||
# mediagoblin.init.celery.from_celery
|
|
||||||
celery_setup_elsewhere = true
|
|
||||||
|
|
||||||
media_types = mediagoblin.media_types.image, mediagoblin.media_types.pdf
|
media_types = mediagoblin.media_types.image, mediagoblin.media_types.pdf
|
||||||
|
|
||||||
[storage:publicstore]
|
[storage:publicstore]
|
||||||
|
@ -33,7 +33,6 @@ from mediagoblin.db.base import Session
|
|||||||
from mediagoblin.meddleware import BaseMeddleware
|
from mediagoblin.meddleware import BaseMeddleware
|
||||||
from mediagoblin.auth.lib import bcrypt_gen_password_hash
|
from mediagoblin.auth.lib import bcrypt_gen_password_hash
|
||||||
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
|
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
|
||||||
from mediagoblin.init.celery import setup_celery_app
|
|
||||||
|
|
||||||
|
|
||||||
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
|
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
|
||||||
@ -47,16 +46,6 @@ TEST_USER_DEV = pkg_resources.resource_filename(
|
|||||||
|
|
||||||
USER_DEV_DIRECTORIES_TO_SETUP = ['media/public', 'media/queue']
|
USER_DEV_DIRECTORIES_TO_SETUP = ['media/public', 'media/queue']
|
||||||
|
|
||||||
BAD_CELERY_MESSAGE = """\
|
|
||||||
Sorry, you *absolutely* must run tests with the
|
|
||||||
mediagoblin.init.celery.from_tests module. Like so:
|
|
||||||
|
|
||||||
$ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests {0}
|
|
||||||
""".format(sys.argv[0])
|
|
||||||
|
|
||||||
|
|
||||||
class BadCeleryEnviron(Exception): pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestingMeddleware(BaseMeddleware):
|
class TestingMeddleware(BaseMeddleware):
|
||||||
"""
|
"""
|
||||||
@ -97,12 +86,6 @@ class TestingMeddleware(BaseMeddleware):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def suicide_if_bad_celery_environ():
|
|
||||||
if not os.environ.get('CELERY_CONFIG_MODULE') == \
|
|
||||||
'mediagoblin.init.celery.from_tests':
|
|
||||||
raise BadCeleryEnviron(BAD_CELERY_MESSAGE)
|
|
||||||
|
|
||||||
|
|
||||||
def get_app(request, paste_config=None, mgoblin_config=None):
|
def get_app(request, paste_config=None, mgoblin_config=None):
|
||||||
"""Create a MediaGoblin app for testing.
|
"""Create a MediaGoblin app for testing.
|
||||||
|
|
||||||
@ -127,14 +110,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
|
|||||||
shutil.copyfile(paste_config, new_paste_config)
|
shutil.copyfile(paste_config, new_paste_config)
|
||||||
shutil.copyfile(mgoblin_config, new_mgoblin_config)
|
shutil.copyfile(mgoblin_config, new_mgoblin_config)
|
||||||
|
|
||||||
suicide_if_bad_celery_environ()
|
|
||||||
|
|
||||||
# Make sure we've turned on testing
|
|
||||||
testing._activate_testing()
|
|
||||||
|
|
||||||
# Leave this imported as it sets up celery.
|
|
||||||
from mediagoblin.init.celery import from_tests
|
|
||||||
|
|
||||||
Session.rollback()
|
Session.rollback()
|
||||||
Session.remove()
|
Session.remove()
|
||||||
|
|
||||||
@ -154,9 +129,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
|
|||||||
test_app = loadapp(
|
test_app = loadapp(
|
||||||
'config:' + new_paste_config)
|
'config:' + new_paste_config)
|
||||||
|
|
||||||
# Re-setup celery
|
|
||||||
setup_celery_app(app_config, global_config)
|
|
||||||
|
|
||||||
# Insert the TestingMeddleware, which can do some
|
# Insert the TestingMeddleware, which can do some
|
||||||
# sanity checks on every request/response.
|
# sanity checks on every request/response.
|
||||||
# Doing it this way is probably not the cleanest way.
|
# Doing it this way is probably not the cleanest way.
|
||||||
|
@ -39,10 +39,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests
|
|
||||||
export CELERY_CONFIG_MODULE
|
|
||||||
echo "+ CELERY_CONFIG_MODULE=$CELERY_CONFIG_MODULE"
|
|
||||||
|
|
||||||
# Look to see if the user has specified a specific directory/file to
|
# Look to see if the user has specified a specific directory/file to
|
||||||
# run tests out of. If not we'll need to pass along
|
# run tests out of. If not we'll need to pass along
|
||||||
# mediagoblin/tests/ later very specifically. Otherwise py.test
|
# mediagoblin/tests/ later very specifically. Otherwise py.test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user