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:
@@ -18,12 +18,10 @@ import os
|
||||
import shutil
|
||||
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.tests.tools import (
|
||||
TEST_USER_DEV, suicide_if_bad_celery_environ)
|
||||
from mediagoblin.tests.tools import TEST_USER_DEV
|
||||
|
||||
|
||||
def setup_package():
|
||||
suicide_if_bad_celery_environ()
|
||||
|
||||
import warnings
|
||||
from sqlalchemy.exc import SAWarning
|
||||
|
||||
@@ -12,10 +12,6 @@ tags_max_length = 50
|
||||
# So we can start to test attachments:
|
||||
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
|
||||
|
||||
[storage:publicstore]
|
||||
|
||||
@@ -33,7 +33,6 @@ from mediagoblin.db.base import Session
|
||||
from mediagoblin.meddleware import BaseMeddleware
|
||||
from mediagoblin.auth.lib import bcrypt_gen_password_hash
|
||||
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
|
||||
from mediagoblin.init.celery import setup_celery_app
|
||||
|
||||
|
||||
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']
|
||||
|
||||
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):
|
||||
"""
|
||||
@@ -97,12 +86,6 @@ class TestingMeddleware(BaseMeddleware):
|
||||
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):
|
||||
"""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(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.remove()
|
||||
|
||||
@@ -154,9 +129,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
|
||||
test_app = loadapp(
|
||||
'config:' + new_paste_config)
|
||||
|
||||
# Re-setup celery
|
||||
setup_celery_app(app_config, global_config)
|
||||
|
||||
# Insert the TestingMeddleware, which can do some
|
||||
# sanity checks on every request/response.
|
||||
# Doing it this way is probably not the cleanest way.
|
||||
|
||||
Reference in New Issue
Block a user