aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r--mediagoblin/tests/test_mgoblin_app.ini12
-rw-r--r--mediagoblin/tests/test_server.ini (renamed from mediagoblin/tests/mgoblin_test_app.ini)11
-rw-r--r--mediagoblin/tests/tools.py45
3 files changed, 42 insertions, 26 deletions
diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini
new file mode 100644
index 00000000..94eafb5a
--- /dev/null
+++ b/mediagoblin/tests/test_mgoblin_app.ini
@@ -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
diff --git a/mediagoblin/tests/mgoblin_test_app.ini b/mediagoblin/tests/test_server.ini
index abed2615..929a1ccf 100644
--- a/mediagoblin/tests/mgoblin_test_app.ini
+++ b/mediagoblin/tests/test_server.ini
@@ -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
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 342b54b7..b1fe56a0 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -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)
+
+ 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 TestApp(test_app)
+ return app
def setup_fresh_app(func):