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.
This commit is contained in:
Baptiste Jonglez 2021-07-12 01:51:37 +02:00 committed by zorun
parent 31a9ed29f6
commit 2e4bb0ec8c
2 changed files with 6 additions and 6 deletions

View file

@ -10,6 +10,9 @@ from ihatemoney.run import create_app, db
class BaseTestCase(TestCase): class BaseTestCase(TestCase):
SECRET_KEY = "TEST SESSION" SECRET_KEY = "TEST SESSION"
SQLALCHEMY_DATABASE_URI = os.environ.get(
"TESTING_SQLALCHEMY_DATABASE_URI", "sqlite://"
)
def create_app(self): def create_app(self):
# Pass the test object as a configuration. # Pass the test object as a configuration.
@ -60,9 +63,6 @@ class BaseTestCase(TestCase):
class IhatemoneyTestCase(BaseTestCase): class IhatemoneyTestCase(BaseTestCase):
SQLALCHEMY_DATABASE_URI = os.environ.get(
"TESTING_SQLALCHEMY_DATABASE_URI", "sqlite://"
)
TESTING = True TESTING = True
WTF_CSRF_ENABLED = False # Simplifies the tests. WTF_CSRF_ENABLED = False # Simplifies the tests.

View file

@ -23,14 +23,14 @@ class ConfigurationTestCase(BaseTestCase):
def test_default_configuration(self): def test_default_configuration(self):
"""Test that default settings are loaded when no other configuration file is specified""" """Test that default settings are loaded when no other configuration file is specified"""
self.assertFalse(self.app.config["DEBUG"]) 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.assertFalse(self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"])
self.assertEqual( self.assertEqual(
self.app.config["MAIL_DEFAULT_SENDER"], self.app.config["MAIL_DEFAULT_SENDER"],
("Budget manager", "budget@notmyidea.org"), ("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): def test_env_var_configuration_file(self):
"""Test that settings are loaded from a configuration file specified """Test that settings are loaded from a configuration file specified