SQL based tests and refactored Celery setup stuff
- Changed config files of test configs to use SQL - Updated celery initialization tools, factored them to be able to use the "big instance" application stuff
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
direct_remote_path = /test_static/
|
||||
email_sender_address = "notice@mediagoblin.example.org"
|
||||
email_debug_mode = true
|
||||
db_name = __mediagoblin_tests__
|
||||
|
||||
# Use an in-memory database
|
||||
sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db"
|
||||
|
||||
# tag parsing
|
||||
tags_max_length = 50
|
||||
@@ -27,3 +29,5 @@ lock_dir = %(here)s/test_user_dev/beaker/cache/lock
|
||||
|
||||
[celery]
|
||||
CELERY_ALWAYS_EAGER = true
|
||||
CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db"
|
||||
BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db"
|
||||
|
||||
@@ -26,8 +26,11 @@ from mediagoblin.tools import testing
|
||||
from mediagoblin.init.config import read_mediagoblin_config
|
||||
from mediagoblin.decorators import _make_safe
|
||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
||||
from mediagoblin.db.sql.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__'
|
||||
@@ -125,26 +128,19 @@ def get_test_app(dump_old_app=True):
|
||||
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(app_config)
|
||||
assert db.name == MEDIAGOBLIN_TEST_DB_NAME
|
||||
|
||||
collections_to_wipe = [
|
||||
collection
|
||||
for collection in db.collection_names()
|
||||
if not collection.startswith('system.')]
|
||||
|
||||
for collection in collections_to_wipe:
|
||||
db.drop_collection(collection)
|
||||
|
||||
# TODO: Drop and recreate indexes
|
||||
# Run database setup/migrations
|
||||
run_dbupdate(app_config)
|
||||
|
||||
# setup app and return
|
||||
test_app = loadapp(
|
||||
'config:' + TEST_SERVER_CONFIG)
|
||||
|
||||
Session.rollback()
|
||||
Session.remove()
|
||||
|
||||
# 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