aboutsummaryrefslogtreecommitdiff
path: root/budget/tests/tests.py
diff options
context:
space:
mode:
author0livd <0livd@users.noreply.github.com>2017-04-23 17:32:37 +0100
committerAlexis Metaireau <alexis@notmyidea.org>2017-04-23 18:32:37 +0200
commite3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45 (patch)
tree4e43ef013b0800cebbb164cddd5c9bcafe33edb1 /budget/tests/tests.py
parentfb84135fe5892f4321977a48abacf233d3ee0d9c (diff)
downloadihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.zip
ihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.tar.gz
ihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.tar.bz2
Externalize the settings (#193)
Default settings from app's root path are loaded first Settings are then overriden by /etc/ihatemoney/ihatemoney.cfg or by another file which path is set in an env var Fixes #187
Diffstat (limited to 'budget/tests/tests.py')
-rw-r--r--budget/tests/tests.py42
1 files changed, 40 insertions, 2 deletions
diff --git a/budget/tests/tests.py b/budget/tests/tests.py
index 854c07b..d979a29 100644
--- a/budget/tests/tests.py
+++ b/budget/tests/tests.py
@@ -10,14 +10,18 @@ import json
from collections import defaultdict
import six
-os.environ['FLASK_SETTINGS_MODULE'] = 'default_settings'
-
from flask import session
+# Unset configuration file env var if previously set
+if 'IHATEMONEY_SETTINGS_FILE_PATH' in os.environ:
+ del os.environ['IHATEMONEY_SETTINGS_FILE_PATH']
+
import run
import models
import utils
+__HERE__ = os.path.dirname(os.path.abspath(__file__))
+
class TestCase(unittest.TestCase):
@@ -65,6 +69,40 @@ class TestCase(unittest.TestCase):
class BudgetTestCase(TestCase):
+ def test_default_configuration(self):
+ """Test that default settings are loaded when no other configuration file is specified"""
+ run.configure()
+ self.assertFalse(run.app.config['DEBUG'])
+ self.assertEqual(run.app.config['SQLALCHEMY_DATABASE_URI'], 'sqlite:///budget.db')
+ self.assertFalse(run.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'])
+ self.assertEqual(run.app.config['SECRET_KEY'], 'tralala')
+ self.assertEqual(run.app.config['MAIL_DEFAULT_SENDER'],
+ ("Budget manager", "budget@notmyidea.org"))
+
+ def test_env_var_configuration_file(self):
+ """Test that settings are loaded from the specified configuration file"""
+ os.environ['IHATEMONEY_SETTINGS_FILE_PATH'] = os.path.join(__HERE__,
+ "ihatemoney_envvar.cfg")
+ run.configure()
+ self.assertEqual(run.app.config['SECRET_KEY'], 'lalatra')
+
+ # Test that the specified configuration file is loaded
+ # even if the default configuration file ihatemoney.cfg exists
+ os.environ['IHATEMONEY_SETTINGS_FILE_PATH'] = os.path.join(__HERE__,
+ "ihatemoney_envvar.cfg")
+ run.app.config.root_path = __HERE__
+ run.configure()
+ self.assertEqual(run.app.config['SECRET_KEY'], 'lalatra')
+
+ if 'IHATEMONEY_SETTINGS_FILE_PATH' in os.environ:
+ del os.environ['IHATEMONEY_SETTINGS_FILE_PATH']
+
+ def test_default_configuration_file(self):
+ """Test that settings are loaded from the default configuration file"""
+ run.app.config.root_path = __HERE__
+ run.configure()
+ self.assertEqual(run.app.config['SECRET_KEY'], 'supersecret')
+
def test_notifications(self):
"""Test that the notifications are sent, and that email adresses
are checked properly.