From 2e4bb0ec8c0deb40d0c8ab7007b0b980991547c8 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Mon, 12 Jul 2021 01:51:37 +0200 Subject: [PATCH] tests: ensure that /tmp/ihatemoney.db does not get overwritten Most of the tests are using a separate database, but we have a few tests that are loading default values and are writing to /tmp/ihatemoney.db. This is annoying because it's also the database used for development: running the test suite breaks the dev database. To fix this, always use a separate testing database to avoid interference. --- ihatemoney/tests/common/ihatemoney_testcase.py | 6 +++--- ihatemoney/tests/main_test.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ihatemoney/tests/common/ihatemoney_testcase.py b/ihatemoney/tests/common/ihatemoney_testcase.py index b57fe3da..067d86ee 100644 --- a/ihatemoney/tests/common/ihatemoney_testcase.py +++ b/ihatemoney/tests/common/ihatemoney_testcase.py @@ -10,6 +10,9 @@ from ihatemoney.run import create_app, db class BaseTestCase(TestCase): SECRET_KEY = "TEST SESSION" + SQLALCHEMY_DATABASE_URI = os.environ.get( + "TESTING_SQLALCHEMY_DATABASE_URI", "sqlite://" + ) def create_app(self): # Pass the test object as a configuration. @@ -60,9 +63,6 @@ class BaseTestCase(TestCase): class IhatemoneyTestCase(BaseTestCase): - SQLALCHEMY_DATABASE_URI = os.environ.get( - "TESTING_SQLALCHEMY_DATABASE_URI", "sqlite://" - ) TESTING = True WTF_CSRF_ENABLED = False # Simplifies the tests. diff --git a/ihatemoney/tests/main_test.py b/ihatemoney/tests/main_test.py index 58475d36..eaf6a01f 100644 --- a/ihatemoney/tests/main_test.py +++ b/ihatemoney/tests/main_test.py @@ -23,14 +23,14 @@ class ConfigurationTestCase(BaseTestCase): def test_default_configuration(self): """Test that default settings are loaded when no other configuration file is specified""" self.assertFalse(self.app.config["DEBUG"]) - self.assertEqual( - self.app.config["SQLALCHEMY_DATABASE_URI"], "sqlite:////tmp/ihatemoney.db" - ) self.assertFalse(self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]) self.assertEqual( self.app.config["MAIL_DEFAULT_SENDER"], ("Budget manager", "budget@notmyidea.org"), ) + self.assertTrue(self.app.config["ACTIVATE_DEMO_PROJECT"]) + self.assertTrue(self.app.config["ALLOW_PUBLIC_PROJECT_CREATION"]) + self.assertFalse(self.app.config["ACTIVATE_ADMIN_DASHBOARD"]) def test_env_var_configuration_file(self): """Test that settings are loaded from a configuration file specified