Merge branch 'master' into 623_context_hooks

This commit is contained in:
Christopher Allan Webber
2013-05-12 16:17:35 -05:00
12 changed files with 69 additions and 81 deletions

View File

@@ -18,12 +18,10 @@ import os
import shutil
from mediagoblin import mg_globals
from mediagoblin.tests.tools import (
TEST_USER_DEV, suicide_if_bad_celery_environ)
from mediagoblin.tests.tools import TEST_USER_DEV
def setup_package():
suicide_if_bad_celery_environ()
import warnings
from sqlalchemy.exc import SAWarning

View File

@@ -14,7 +14,7 @@
# 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/>.
from mediagoblin.messages import fetch_messages, add_message
from mediagoblin import messages
from mediagoblin.tools import template
@@ -32,11 +32,19 @@ def test_messages(test_app):
# The message queue should be empty
assert request.session.get('messages', []) == []
# First of all, we should clear the messages queue
messages.clear_add_message()
# Adding a message should modify the session accordingly
add_message(request, 'herp_derp', 'First!')
messages.add_message(request, 'herp_derp', 'First!')
test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}]
assert request.session['messages'] == test_msg_queue
# Alternative tests to the following, test divided in two steps:
# assert request.session['messages'] == test_msg_queue
# 1. Tests if add_message worked
assert messages.ADD_MESSAGE_TEST[-1] == test_msg_queue
# 2. Tests if add_message updated session information
assert messages.ADD_MESSAGE_TEST[-1] == request.session['messages']
# fetch_messages should return and empty the queue
assert fetch_messages(request) == test_msg_queue
assert messages.fetch_messages(request) == test_msg_queue
assert request.session.get('messages') == []

View File

@@ -12,10 +12,6 @@ tags_max_length = 50
# So we can start to test attachments:
allow_attachments = True
# Celery shouldn't be set up by the application as it's setup via
# mediagoblin.init.celery.from_celery
celery_setup_elsewhere = true
media_types = mediagoblin.media_types.image, mediagoblin.media_types.pdf
[storage:publicstore]

View File

@@ -1,7 +1,5 @@
#!/usr/bin/env python
from nose.tools import assert_equal
from mediagoblin import processing
class TestProcessing(object):
@@ -10,7 +8,7 @@ class TestProcessing(object):
result = builder.fill(format)
if output is None:
return result
assert_equal(output, result)
assert output == result
def test_easy_filename_fill(self):
self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')

View File

@@ -33,7 +33,6 @@ from mediagoblin.db.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__'
@@ -47,16 +46,6 @@ TEST_USER_DEV = pkg_resources.resource_filename(
USER_DEV_DIRECTORIES_TO_SETUP = ['media/public', 'media/queue']
BAD_CELERY_MESSAGE = """\
Sorry, you *absolutely* must run tests with the
mediagoblin.init.celery.from_tests module. Like so:
$ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests {0}
""".format(sys.argv[0])
class BadCeleryEnviron(Exception): pass
class TestingMeddleware(BaseMeddleware):
"""
@@ -97,12 +86,6 @@ class TestingMeddleware(BaseMeddleware):
return
def suicide_if_bad_celery_environ():
if not os.environ.get('CELERY_CONFIG_MODULE') == \
'mediagoblin.init.celery.from_tests':
raise BadCeleryEnviron(BAD_CELERY_MESSAGE)
def get_app(request, paste_config=None, mgoblin_config=None):
"""Create a MediaGoblin app for testing.
@@ -127,14 +110,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
shutil.copyfile(paste_config, new_paste_config)
shutil.copyfile(mgoblin_config, new_mgoblin_config)
suicide_if_bad_celery_environ()
# Make sure we've turned on testing
testing._activate_testing()
# Leave this imported as it sets up celery.
from mediagoblin.init.celery import from_tests
Session.rollback()
Session.remove()
@@ -154,9 +129,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
test_app = loadapp(
'config:' + new_paste_config)
# 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.