Merge branch 'configobj'
This commit is contained in:
@@ -21,6 +21,7 @@ def setup_package():
|
||||
pass
|
||||
|
||||
def teardown_package():
|
||||
print "Killing db ..."
|
||||
mg_globals.db_connection.drop_database(mg_globals.database.name)
|
||||
print "... done"
|
||||
if mg_globals.db_connection:
|
||||
print "Killing db ..."
|
||||
mg_globals.db_connection.drop_database(mg_globals.database.name)
|
||||
print "... done"
|
||||
|
||||
14
mediagoblin/tests/fake_carrot_conf_bad.ini
Normal file
14
mediagoblin/tests/fake_carrot_conf_bad.ini
Normal file
@@ -0,0 +1,14 @@
|
||||
[carrotapp]
|
||||
# Whether or not our carrots are going to be turned into cake.
|
||||
## These should throw errors
|
||||
carrotcake = slobber
|
||||
num_carrots = GROSS
|
||||
|
||||
# A message encouraging our users to eat their carrots.
|
||||
encouragement_phrase = 586956856856 # shouldn't throw error
|
||||
|
||||
# Something extra!
|
||||
blah_blah = "blah!" # shouldn't throw error either
|
||||
|
||||
[celery]
|
||||
eat_celery_with_carrots = pants # yeah that's def an error right there.
|
||||
0
mediagoblin/tests/fake_carrot_conf_empty.ini
Normal file
0
mediagoblin/tests/fake_carrot_conf_empty.ini
Normal file
13
mediagoblin/tests/fake_carrot_conf_good.ini
Normal file
13
mediagoblin/tests/fake_carrot_conf_good.ini
Normal file
@@ -0,0 +1,13 @@
|
||||
[carrotapp]
|
||||
# Whether or not our carrots are going to be turned into cake.
|
||||
carrotcake = true
|
||||
num_carrots = 88
|
||||
|
||||
# A message encouraging our users to eat their carrots.
|
||||
encouragement_phrase = "I'd love it if you eat your carrots!"
|
||||
|
||||
# Something extra!
|
||||
blah_blah = "blah!"
|
||||
|
||||
[celery]
|
||||
eat_celery_with_carrots = False
|
||||
9
mediagoblin/tests/fake_celery_conf.ini
Normal file
9
mediagoblin/tests/fake_celery_conf.ini
Normal file
@@ -0,0 +1,9 @@
|
||||
['mediagoblin']
|
||||
# I got nothin' in this file!
|
||||
|
||||
['celery']
|
||||
some_variable = floop
|
||||
mail_port = 2000
|
||||
celeryd_eta_scheduler_precision = 1.3
|
||||
celery_result_persistent = true
|
||||
celery_imports = foo.bar.baz, this.is.an.import
|
||||
14
mediagoblin/tests/fake_celery_conf_mgdb.ini
Normal file
14
mediagoblin/tests/fake_celery_conf_mgdb.ini
Normal file
@@ -0,0 +1,14 @@
|
||||
['mediagoblin']
|
||||
db_host = mongodb.example.org
|
||||
db_port = 8080
|
||||
db_name = captain_lollerskates
|
||||
|
||||
['something']
|
||||
or = other
|
||||
|
||||
['celery']
|
||||
some_variable = poolf
|
||||
mail_port = 2020
|
||||
celeryd_eta_scheduler_precision = 3.1
|
||||
celery_result_persistent = false
|
||||
celery_imports = baz.bar.foo, import.is.a.this
|
||||
10
mediagoblin/tests/fake_config_spec.ini
Normal file
10
mediagoblin/tests/fake_config_spec.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[carrotapp]
|
||||
# Whether or not our carrots are going to be turned into cake.
|
||||
carrotcake = boolean(default=False)
|
||||
num_carrots = integer(default=1)
|
||||
|
||||
# A message encouraging our users to eat their carrots.
|
||||
encouragement_phrase = string()
|
||||
|
||||
[celery]
|
||||
eat_celery_with_carrots = boolean(default=True)
|
||||
@@ -15,6 +15,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from mediagoblin import celery_setup
|
||||
from mediagoblin.config import read_mediagoblin_config
|
||||
|
||||
|
||||
TEST_CELERY_CONF_NOSPECIALDB = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_celery_conf.ini')
|
||||
TEST_CELERY_CONF_MGSPECIALDB = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_celery_conf_mgdb.ini')
|
||||
|
||||
|
||||
def test_setup_celery_from_config():
|
||||
@@ -25,14 +32,12 @@ def test_setup_celery_from_config():
|
||||
for var in vars_to_wipe:
|
||||
delattr(module, var)
|
||||
|
||||
global_config, validation_result = read_mediagoblin_config(
|
||||
TEST_CELERY_CONF_NOSPECIALDB)
|
||||
app_config = global_config['mediagoblin']
|
||||
|
||||
celery_setup.setup_celery_from_config(
|
||||
{},
|
||||
{'something': {'or': 'other'},
|
||||
'celery': {'some_variable': 'floop',
|
||||
'mail_port': '2000',
|
||||
'CELERYD_ETA_SCHEDULER_PRECISION': '1.3',
|
||||
'celery_result_persistent': 'true',
|
||||
'celery_imports': 'foo.bar.baz this.is.an.import'}},
|
||||
app_config, global_config,
|
||||
'mediagoblin.tests.fake_celery_module', set_environ=False)
|
||||
|
||||
from mediagoblin.tests import fake_celery_module
|
||||
@@ -51,17 +56,12 @@ def test_setup_celery_from_config():
|
||||
|
||||
_wipe_testmodule_clean(fake_celery_module)
|
||||
|
||||
global_config, validation_result = read_mediagoblin_config(
|
||||
TEST_CELERY_CONF_MGSPECIALDB)
|
||||
app_config = global_config['mediagoblin']
|
||||
|
||||
celery_setup.setup_celery_from_config(
|
||||
{'db_host': 'mongodb.example.org',
|
||||
'db_port': '8080',
|
||||
'db_name': 'captain_lollerskates',
|
||||
'celery_section': 'vegetable'},
|
||||
{'something': {'or': 'other'},
|
||||
'vegetable': {'some_variable': 'poolf',
|
||||
'mail_port': '2020',
|
||||
'CELERYD_ETA_SCHEDULER_PRECISION': '3.1',
|
||||
'celery_result_persistent': 'false',
|
||||
'celery_imports': 'baz.bar.foo import.is.a.this'}},
|
||||
app_config, global_config,
|
||||
'mediagoblin.tests.fake_celery_module', set_environ=False)
|
||||
|
||||
from mediagoblin.tests import fake_celery_module
|
||||
|
||||
97
mediagoblin/tests/test_config.py
Normal file
97
mediagoblin/tests/test_config.py
Normal file
@@ -0,0 +1,97 @@
|
||||
# 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 pkg_resources
|
||||
|
||||
from mediagoblin import config
|
||||
|
||||
|
||||
CARROT_CONF_GOOD = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_carrot_conf_good.ini')
|
||||
CARROT_CONF_EMPTY = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_carrot_conf_empty.ini')
|
||||
CARROT_CONF_BAD = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_carrot_conf_bad.ini')
|
||||
FAKE_CONFIG_SPEC = pkg_resources.resource_filename(
|
||||
'mediagoblin.tests', 'fake_config_spec.ini')
|
||||
|
||||
|
||||
def test_read_mediagoblin_config():
|
||||
# An empty file
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_EMPTY, FAKE_CONFIG_SPEC)
|
||||
|
||||
assert this_conf['carrotapp']['carrotcake'] == False
|
||||
assert this_conf['carrotapp']['num_carrots'] == 1
|
||||
assert not this_conf['carrotapp'].has_key('encouragement_phrase')
|
||||
assert this_conf['celery']['eat_celery_with_carrots'] == True
|
||||
|
||||
# A good file
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_GOOD, FAKE_CONFIG_SPEC)
|
||||
|
||||
assert this_conf['carrotapp']['carrotcake'] == True
|
||||
assert this_conf['carrotapp']['num_carrots'] == 88
|
||||
assert this_conf['carrotapp']['encouragement_phrase'] == \
|
||||
"I'd love it if you eat your carrots!"
|
||||
assert this_conf['carrotapp']['blah_blah'] == "blah!"
|
||||
assert this_conf['celery']['eat_celery_with_carrots'] == False
|
||||
|
||||
# A bad file
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_BAD, FAKE_CONFIG_SPEC)
|
||||
|
||||
# These should still open but will have errors that we'll test for
|
||||
# in test_generate_validation_report()
|
||||
assert this_conf['carrotapp']['carrotcake'] == 'slobber'
|
||||
assert this_conf['carrotapp']['num_carrots'] == 'GROSS'
|
||||
assert this_conf['carrotapp']['encouragement_phrase'] == \
|
||||
"586956856856"
|
||||
assert this_conf['carrotapp']['blah_blah'] == "blah!"
|
||||
assert this_conf['celery']['eat_celery_with_carrots'] == "pants"
|
||||
|
||||
|
||||
def test_generate_validation_report():
|
||||
# Empty
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_EMPTY, FAKE_CONFIG_SPEC)
|
||||
report = config.generate_validation_report(this_conf, validation_results)
|
||||
assert report is None
|
||||
|
||||
# Good
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_GOOD, FAKE_CONFIG_SPEC)
|
||||
report = config.generate_validation_report(this_conf, validation_results)
|
||||
assert report is None
|
||||
|
||||
# Bad
|
||||
this_conf, validation_results = config.read_mediagoblin_config(
|
||||
CARROT_CONF_BAD, FAKE_CONFIG_SPEC)
|
||||
report = config.generate_validation_report(this_conf, validation_results)
|
||||
|
||||
assert report.startswith("""\
|
||||
There were validation problems loading this config file:
|
||||
--------------------------------------------------------""")
|
||||
|
||||
expected_warnings = [
|
||||
'carrotapp:carrotcake = the value "slobber" is of the wrong type.',
|
||||
'carrotapp:num_carrots = the value "GROSS" is of the wrong type.',
|
||||
'celery:eat_celery_with_carrots = the value "pants" is of the wrong type.']
|
||||
warnings = report.splitlines()[2:]
|
||||
|
||||
assert len(warnings) == 3
|
||||
for warning in expected_warnings:
|
||||
assert warning in warnings
|
||||
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
|
||||
@@ -58,8 +58,8 @@ class FakeRemoteStorage(storage.BasicFileStorage):
|
||||
local_storage = False
|
||||
|
||||
|
||||
def test_storage_system_from_paste_config():
|
||||
this_storage = storage.storage_system_from_paste_config(
|
||||
def test_storage_system_from_config():
|
||||
this_storage = storage.storage_system_from_config(
|
||||
{'somestorage_base_url': 'http://example.org/moodia/',
|
||||
'somestorage_base_dir': '/tmp/',
|
||||
'somestorage_garbage_arg': 'garbage_arg',
|
||||
@@ -69,7 +69,7 @@ def test_storage_system_from_paste_config():
|
||||
assert this_storage.base_dir == '/tmp/'
|
||||
assert this_storage.__class__ is storage.BasicFileStorage
|
||||
|
||||
this_storage = storage.storage_system_from_paste_config(
|
||||
this_storage = storage.storage_system_from_config(
|
||||
{'somestorage_foobie': 'eiboof',
|
||||
'somestorage_blech': 'hcelb',
|
||||
'somestorage_garbage_arg': 'garbage_arg',
|
||||
|
||||
@@ -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