Celery wasn't really being properly connected during tests.
Lots of fixes to do this. - setup_celery_from_config no longer responsible for checking 'celery_setup_elsewhere'; that's the app's job. (This was a problem because more than the app was relying on using this function) - Allow us to specifically set the config file we're setting up celery from with setup_self - Set up celery_always_eager. This is something we strongly want while doing tests. - Instead of setting up the app in the get_test_app method, let's set that up simply by importing from_tests, which should itself up via from_celery being the environment variable being set.
This commit is contained in:
parent
426685e088
commit
9ea5c28b7a
@ -40,10 +40,6 @@ def setup_celery_from_config(app_config, global_config,
|
|||||||
- set_environ: if set, this will CELERY_CONFIG_MODULE to the
|
- set_environ: if set, this will CELERY_CONFIG_MODULE to the
|
||||||
settings_module
|
settings_module
|
||||||
"""
|
"""
|
||||||
if app_config.get('celery_setup_elsewhere') == True:
|
|
||||||
# Don't setup celery based on our config file.
|
|
||||||
return
|
|
||||||
|
|
||||||
if global_config.has_key('celery'):
|
if global_config.has_key('celery'):
|
||||||
celery_conf = global_config['celery']
|
celery_conf = global_config['celery']
|
||||||
else:
|
else:
|
||||||
|
@ -23,7 +23,8 @@ from mediagoblin.celery_setup import setup_celery_from_config
|
|||||||
OUR_MODULENAME = __name__
|
OUR_MODULENAME = __name__
|
||||||
|
|
||||||
|
|
||||||
def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME):
|
def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME,
|
||||||
|
default_conf_file='mediagoblin.ini'):
|
||||||
"""
|
"""
|
||||||
Transform this module into a celery config module by reading the
|
Transform this module into a celery config module by reading the
|
||||||
mediagoblin config file. Set the environment variable
|
mediagoblin config file. Set the environment variable
|
||||||
@ -36,9 +37,9 @@ def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME):
|
|||||||
"""
|
"""
|
||||||
if check_environ_for_conf:
|
if check_environ_for_conf:
|
||||||
mgoblin_conf_file = os.path.abspath(
|
mgoblin_conf_file = os.path.abspath(
|
||||||
os.environ.get('MEDIAGOBLIN_CONFIG', 'mediagoblin.ini'))
|
os.environ.get('MEDIAGOBLIN_CONFIG', default_conf_file))
|
||||||
else:
|
else:
|
||||||
mgoblin_conf_file = 'mediagoblin.ini'
|
mgoblin_conf_file = default_conf_file
|
||||||
|
|
||||||
if not os.path.exists(mgoblin_conf_file):
|
if not os.path.exists(mgoblin_conf_file):
|
||||||
raise IOError(
|
raise IOError(
|
||||||
@ -48,6 +49,7 @@ def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME):
|
|||||||
# this is the module that gets set up.
|
# this is the module that gets set up.
|
||||||
os.environ['CELERY_CONFIG_MODULE'] = module_name
|
os.environ['CELERY_CONFIG_MODULE'] = module_name
|
||||||
app.MediaGoblinApp(mgoblin_conf_file, setup_celery=False)
|
app.MediaGoblinApp(mgoblin_conf_file, setup_celery=False)
|
||||||
|
|
||||||
setup_celery_from_config(
|
setup_celery_from_config(
|
||||||
mg_globals.app_config, mg_globals.global_config,
|
mg_globals.app_config, mg_globals.global_config,
|
||||||
settings_module=module_name,
|
settings_module=module_name,
|
||||||
|
@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from mediagoblin.tests.tools import TEST_APP_CONFIG
|
||||||
from mediagoblin.celery_setup.from_celery import setup_self
|
from mediagoblin.celery_setup.from_celery import setup_self
|
||||||
|
|
||||||
|
|
||||||
OUR_MODULENAME = __name__
|
OUR_MODULENAME = __name__
|
||||||
|
CELERY_SETUP = False
|
||||||
|
|
||||||
|
|
||||||
if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
|
if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
|
||||||
setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME)
|
setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME,
|
||||||
|
default_conf_file=TEST_APP_CONFIG)
|
||||||
|
CELERY_SETUP = True
|
||||||
|
@ -7,6 +7,9 @@ email_sender_address = "notice@mediagoblin.example.org"
|
|||||||
email_debug_mode = true
|
email_debug_mode = true
|
||||||
db_name = __mediagoblin_tests__
|
db_name = __mediagoblin_tests__
|
||||||
|
|
||||||
# Celery shouldn't be set up by the paste app factory as it's set up
|
# Celery shouldn't be set up by the application as it's setup via
|
||||||
# elsewhere
|
# mediagoblin.celery_setup.from_celery
|
||||||
celery_setup_elsewhere = true
|
celery_setup_elsewhere = true
|
||||||
|
|
||||||
|
[celery]
|
||||||
|
celery_always_eager = true
|
||||||
|
@ -21,9 +21,8 @@ import os, shutil
|
|||||||
from paste.deploy import loadapp
|
from paste.deploy import loadapp
|
||||||
from webtest import TestApp
|
from webtest import TestApp
|
||||||
|
|
||||||
from mediagoblin import util, mg_globals
|
from mediagoblin import util
|
||||||
from mediagoblin.config import read_mediagoblin_config
|
from mediagoblin.config import read_mediagoblin_config
|
||||||
from mediagoblin.celery_setup import setup_celery_from_config
|
|
||||||
from mediagoblin.decorators import _make_safe
|
from mediagoblin.decorators import _make_safe
|
||||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
from mediagoblin.db.open import setup_connection_and_db_from_config
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ TEST_APP_CONFIG = pkg_resources.resource_filename(
|
|||||||
TEST_USER_DEV = pkg_resources.resource_filename(
|
TEST_USER_DEV = pkg_resources.resource_filename(
|
||||||
'mediagoblin.tests', 'test_user_dev')
|
'mediagoblin.tests', 'test_user_dev')
|
||||||
MGOBLIN_APP = None
|
MGOBLIN_APP = None
|
||||||
CELERY_SETUP = False
|
|
||||||
|
|
||||||
USER_DEV_DIRECTORIES_TO_SETUP = [
|
USER_DEV_DIRECTORIES_TO_SETUP = [
|
||||||
'media/public', 'media/queue',
|
'media/public', 'media/queue',
|
||||||
@ -60,8 +58,10 @@ def suicide_if_bad_celery_environ():
|
|||||||
def get_test_app(dump_old_app=True):
|
def get_test_app(dump_old_app=True):
|
||||||
suicide_if_bad_celery_environ()
|
suicide_if_bad_celery_environ()
|
||||||
|
|
||||||
|
# Leave this imported as it sets up celery.
|
||||||
|
from mediagoblin.celery_setup import from_tests
|
||||||
|
|
||||||
global MGOBLIN_APP
|
global MGOBLIN_APP
|
||||||
global CELERY_SETUP
|
|
||||||
|
|
||||||
# Just return the old app if that exists and it's okay to set up
|
# Just return the old app if that exists and it's okay to set up
|
||||||
# and return
|
# and return
|
||||||
@ -103,13 +103,6 @@ def get_test_app(dump_old_app=True):
|
|||||||
app = TestApp(test_app)
|
app = TestApp(test_app)
|
||||||
MGOBLIN_APP = app
|
MGOBLIN_APP = app
|
||||||
|
|
||||||
# setup celery
|
|
||||||
if not CELERY_SETUP:
|
|
||||||
setup_celery_from_config(
|
|
||||||
mg_globals.app_config, mg_globals.global_config,
|
|
||||||
set_environ=True)
|
|
||||||
CELERY_SETUP = True
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user