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:
12
mediagoblin/tests/test_mgoblin_app.ini
Normal file
12
mediagoblin/tests/test_mgoblin_app.ini
Normal 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
|
||||
@@ -10,16 +10,7 @@ use = egg:Paste#urlmap
|
||||
[app:mediagoblin]
|
||||
use = egg:mediagoblin#app
|
||||
filter-with = beaker
|
||||
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
|
||||
config = %(here)s/test_mgoblin_app.ini
|
||||
|
||||
[app:publicstore_serve]
|
||||
use = egg:Paste#static
|
||||
@@ -18,20 +18,25 @@
|
||||
import pkg_resources
|
||||
import os, shutil
|
||||
|
||||
from paste.deploy import appconfig, loadapp
|
||||
from paste.deploy import loadapp
|
||||
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.db.open import setup_connection_and_db_from_config
|
||||
|
||||
|
||||
MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblinunittests__'
|
||||
TEST_SERVER_CONFIG = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'test_server.ini')
|
||||
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(
|
||||
'mediagoblin.tests', 'test_user_dev')
|
||||
MGOBLIN_APP = None
|
||||
CELERY_SETUP = False
|
||||
|
||||
USER_DEV_DIRECTORIES_TO_SETUP = [
|
||||
'media/public', 'media/queue',
|
||||
@@ -42,12 +47,13 @@ class BadCeleryEnviron(Exception): pass
|
||||
|
||||
|
||||
def get_test_app(dump_old_app=True):
|
||||
if not os.environ.get('CELERY_CONFIG_MODULE') == \
|
||||
'mediagoblin.celery_setup.from_tests':
|
||||
if os.environ.get('CELERY_CONFIG_MODULE'):
|
||||
raise BadCeleryEnviron(
|
||||
u"Sorry, you *absolutely* must run nosetests with the\n"
|
||||
u"mediagoblin.celery_setup.from_tests module. Like so:\n"
|
||||
u"$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests")
|
||||
u"Sorry, you *ABSOLUTELY MUST *NOT* run nosetests with the\n"
|
||||
u"CELERY_CONFIG_MODULE set to anything.")
|
||||
|
||||
global MGOBLIN_APP
|
||||
global CELERY_SETUP
|
||||
|
||||
# Just return the old app if that exists and it's okay to set up
|
||||
# and return
|
||||
@@ -63,16 +69,13 @@ def get_test_app(dump_old_app=True):
|
||||
os.makedirs(full_dir)
|
||||
|
||||
# Get app config
|
||||
config = appconfig(
|
||||
'config:' + os.path.basename(TEST_APP_CONFIG),
|
||||
relative_to=os.path.dirname(TEST_APP_CONFIG),
|
||||
name='mediagoblin')
|
||||
global_config, validation_result = read_mediagoblin_config(TEST_APP_CONFIG)
|
||||
app_config = global_config['mediagoblin']
|
||||
|
||||
# Wipe database
|
||||
# @@: For now we're dropping collections, but we could also just
|
||||
# collection.remove() ?
|
||||
connection, db = setup_connection_and_db_from_config(
|
||||
config.local_conf)
|
||||
connection, db = setup_connection_and_db_from_config(app_config)
|
||||
|
||||
collections_to_wipe = [
|
||||
collection
|
||||
@@ -90,9 +93,19 @@ def get_test_app(dump_old_app=True):
|
||||
|
||||
# setup app and return
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user