Nosetests should now be able to run using the new configobj / app init setup

Lots of changes:
 - CELERY_CONFIG_FILE does not need to be set to the from_tests module
   to run tests anymore, in fact it *should not be set at all* and is
   specifically forbidden.
 - moved around the configuration to the new 2-file format
 - and generally adjusting the code appropriately.
This commit is contained in:
Christopher Allan Webber 2011-06-18 20:14:33 -05:00
parent 908d045939
commit 623bee73b1
4 changed files with 42 additions and 68 deletions

View File

@ -1,42 +0,0 @@
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011 Free Software Foundation, Inc
#
# 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 import util
from mediagoblin.celery_setup import setup_celery_from_config
OUR_MODULENAME = __name__
def setup_self():
"""
Set up celery for testing's sake, which just needs to set up
celery and celery only.
"""
mgoblin_conf = util.read_config_file(TEST_APP_CONFIG)
mgoblin_section = mgoblin_conf['app:mediagoblin']
setup_celery_from_config(
mgoblin_section, mgoblin_conf,
settings_module=OUR_MODULENAME,
set_environ=False)
if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
setup_self()

View File

@ -0,0 +1,12 @@
[mediagoblin]
queuestore_base_dir = %(here)s/test_user_dev/media/queue
publicstore_base_dir = %(here)s/test_user_dev/media/public
publicstore_base_url = /mgoblin_media/
direct_remote_path = /mgoblin_static/
email_sender_address = "notice@mediagoblin.example.org"
email_debug_mode = true
db_name = __mediagoblin_tests__
# Celery shouldn't be set up by the paste app factory as it's set up
# elsewhere
celery_setup_elsewhere = true

View File

@ -10,16 +10,7 @@ use = egg:Paste#urlmap
[app:mediagoblin] [app:mediagoblin]
use = egg:mediagoblin#app use = egg:mediagoblin#app
filter-with = beaker filter-with = beaker
queuestore_base_dir = %(here)s/test_user_dev/media/queue config = %(here)s/test_mgoblin_app.ini
publicstore_base_dir = %(here)s/test_user_dev/media/public
publicstore_base_url = /mgoblin_media/
direct_remote_path = /mgoblin_static/
email_sender_address = "notice@mediagoblin.example.org"
email_debug_mode = true
db_name = __mediagoblin_tests__
# Celery shouldn't be set up by the paste app factory as it's set up
# elsewhere
celery_setup_elsewhere = true
[app:publicstore_serve] [app:publicstore_serve]
use = egg:Paste#static use = egg:Paste#static

View File

@ -18,20 +18,25 @@
import pkg_resources import pkg_resources
import os, shutil import os, shutil
from paste.deploy import appconfig, loadapp from paste.deploy import loadapp
from webtest import TestApp from webtest import TestApp
from mediagoblin import util from mediagoblin import util, mg_globals
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
MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblinunittests__' MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblinunittests__'
TEST_SERVER_CONFIG = pkg_resources.resource_filename(
'mediagoblin.tests', 'test_server.ini')
TEST_APP_CONFIG = pkg_resources.resource_filename( TEST_APP_CONFIG = pkg_resources.resource_filename(
'mediagoblin.tests', 'mgoblin_test_app.ini') 'mediagoblin.tests', 'test_mgoblin_app.ini')
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',
@ -42,12 +47,13 @@ class BadCeleryEnviron(Exception): pass
def get_test_app(dump_old_app=True): def get_test_app(dump_old_app=True):
if not os.environ.get('CELERY_CONFIG_MODULE') == \ if os.environ.get('CELERY_CONFIG_MODULE'):
'mediagoblin.celery_setup.from_tests':
raise BadCeleryEnviron( raise BadCeleryEnviron(
u"Sorry, you *absolutely* must run nosetests with the\n" u"Sorry, you *ABSOLUTELY MUST *NOT* run nosetests with the\n"
u"mediagoblin.celery_setup.from_tests module. Like so:\n" u"CELERY_CONFIG_MODULE set to anything.")
u"$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests")
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
@ -63,16 +69,13 @@ def get_test_app(dump_old_app=True):
os.makedirs(full_dir) os.makedirs(full_dir)
# Get app config # Get app config
config = appconfig( global_config, validation_result = read_mediagoblin_config(TEST_APP_CONFIG)
'config:' + os.path.basename(TEST_APP_CONFIG), app_config = global_config['mediagoblin']
relative_to=os.path.dirname(TEST_APP_CONFIG),
name='mediagoblin')
# Wipe database # Wipe database
# @@: For now we're dropping collections, but we could also just # @@: For now we're dropping collections, but we could also just
# collection.remove() ? # collection.remove() ?
connection, db = setup_connection_and_db_from_config( connection, db = setup_connection_and_db_from_config(app_config)
config.local_conf)
collections_to_wipe = [ collections_to_wipe = [
collection collection
@ -90,9 +93,19 @@ def get_test_app(dump_old_app=True):
# setup app and return # setup app and return
test_app = loadapp( test_app = loadapp(
'config:' + TEST_APP_CONFIG) 'config:' + TEST_SERVER_CONFIG)
return TestApp(test_app) app = TestApp(test_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
def setup_fresh_app(func): def setup_fresh_app(func):