From 49285baf2755e4cead741dd5c615a65736a5dc08 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 12 Jun 2011 17:36:49 +0200 Subject: [PATCH] Let setup_globals check for known globals To avoid typos in calling setup_globals(), only allow globals, which are already known to the system. Plugins should have their own globals. --- mediagoblin/globals.py | 11 +++++++++++ mediagoblin/tests/test_globals.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/mediagoblin/globals.py b/mediagoblin/globals.py index 80d1f01d..49a513a2 100644 --- a/mediagoblin/globals.py +++ b/mediagoblin/globals.py @@ -19,6 +19,15 @@ database = None public_store = None queue_store = None +# Dump mail to stdout instead of sending it: +email_debug_mode = False + +# Address for sending out mails +email_sender_address = None + +# A WorkBenchManager +workbench_manager = None + # gettext translations = gettext.find( 'mediagoblin', @@ -30,4 +39,6 @@ def setup_globals(**kwargs): from mediagoblin import globals as mg_globals for key, value in kwargs.iteritems(): + if not hasattr(mg_globals, key): + raise AssertionError("Global %s not known" % key) setattr(mg_globals, key, value) diff --git a/mediagoblin/tests/test_globals.py b/mediagoblin/tests/test_globals.py index 6d2e01da..b285cdf5 100644 --- a/mediagoblin/tests/test_globals.py +++ b/mediagoblin/tests/test_globals.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from nose.tools import assert_raises + from mediagoblin import globals as mg_globals def test_setup_globals(): @@ -27,3 +29,8 @@ def test_setup_globals(): assert mg_globals.database == 'my favorite database!' assert mg_globals.public_store == 'my favorite public_store!' assert mg_globals.queue_store == 'my favorite queue_store!' + + assert_raises( + AssertionError, + mg_globals.setup_globals, + no_such_global_foo = "Dummy") -- 2.25.1