mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
Make the tests pass
This commit is contained in:
parent
8229b41bff
commit
62436da755
5 changed files with 297 additions and 289 deletions
|
@ -1,3 +1,4 @@
|
||||||
zest.releaser
|
zest.releaser
|
||||||
tox
|
tox
|
||||||
pytest
|
pytest
|
||||||
|
Flask-Testing
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///budget.db'
|
SQLALCHEMY_DATABASE_URI = 'sqlite://'
|
||||||
SQLACHEMY_ECHO = DEBUG
|
SQLACHEMY_ECHO = DEBUG
|
||||||
# Will likely become the default value in flask-sqlalchemy >=3 ; could be removed
|
# Will likely become the default value in flask-sqlalchemy >=3 ; could be removed
|
||||||
# then:
|
# then:
|
||||||
|
|
|
@ -10,7 +10,7 @@ from raven.contrib.flask import Sentry
|
||||||
|
|
||||||
from ihatemoney.api import api
|
from ihatemoney.api import api
|
||||||
from ihatemoney.models import db
|
from ihatemoney.models import db
|
||||||
from ihatemoney.utils import PrefixedWSGI
|
from ihatemoney.utils import PrefixedWSGI, minimal_round
|
||||||
from ihatemoney.web import main as web_interface
|
from ihatemoney.web import main as web_interface
|
||||||
|
|
||||||
from ihatemoney import default_settings
|
from ihatemoney import default_settings
|
||||||
|
@ -43,22 +43,23 @@ def setup_database(app):
|
||||||
upgrade(migrations_path)
|
upgrade(migrations_path)
|
||||||
|
|
||||||
|
|
||||||
def load_configuration(app):
|
def load_configuration(app, configuration=None):
|
||||||
""" A way to (re)configure the app, specially reset the settings
|
""" Find the right configuration file for the application and load it.
|
||||||
"""
|
|
||||||
default_config_file = os.path.join(app.root_path, 'default_settings.py')
|
|
||||||
config_file = os.environ.get('IHATEMONEY_SETTINGS_FILE_PATH')
|
|
||||||
|
|
||||||
# Load default settings first
|
By order of preference:
|
||||||
# Then load the settings from the path set in IHATEMONEY_SETTINGS_FILE_PATH var
|
- Use the IHATEMONEY_SETTINGS_FILE_PATH env var if defined ;
|
||||||
# If not set, default to /etc/ihatemoney/ihatemoney.cfg
|
- If not, use /etc/ihatemoney/ihatemoney.cfg ;
|
||||||
# If the latter doesn't exist no error is raised and the default settings are used
|
- Otherwise, load the default settings.
|
||||||
app.config.from_pyfile(default_config_file)
|
"""
|
||||||
if config_file:
|
|
||||||
app.config.from_pyfile(config_file)
|
env_var_config = os.environ.get('IHATEMONEY_SETTINGS_FILE_PATH')
|
||||||
|
app.config.from_object('ihatemoney.default_settings')
|
||||||
|
if configuration:
|
||||||
|
app.config.from_object(configuration)
|
||||||
|
elif env_var_config:
|
||||||
|
app.config.from_pyfile(env_var_config)
|
||||||
else:
|
else:
|
||||||
app.config.from_pyfile('ihatemoney.cfg', silent=True)
|
app.config.from_pyfile('ihatemoney.cfg', silent=True)
|
||||||
app.wsgi_app = PrefixedWSGI(app)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_configuration(app):
|
def validate_configuration(app):
|
||||||
|
@ -92,10 +93,17 @@ def validate_configuration(app):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_app(instance_path='/etc/ihatemoney'):
|
def create_app(configuration=None, instance_path='/etc/ihatemoney',
|
||||||
app = Flask(__name__, instance_path=instance_path,
|
instance_relative_config=True):
|
||||||
instance_relative_config=True)
|
app = Flask(
|
||||||
load_configuration(app)
|
__name__,
|
||||||
|
instance_path=instance_path,
|
||||||
|
instance_relative_config=instance_relative_config)
|
||||||
|
|
||||||
|
# If a configuration object is passed, use it. Otherwise try to find one.
|
||||||
|
load_configuration(app, configuration)
|
||||||
|
app.wsgi_app = PrefixedWSGI(app)
|
||||||
|
|
||||||
validate_configuration(app)
|
validate_configuration(app)
|
||||||
app.register_blueprint(web_interface)
|
app.register_blueprint(web_interface)
|
||||||
app.register_blueprint(api)
|
app.register_blueprint(api)
|
||||||
|
@ -110,6 +118,9 @@ def create_app(instance_path='/etc/ihatemoney'):
|
||||||
# Error reporting
|
# Error reporting
|
||||||
Sentry(app)
|
Sentry(app)
|
||||||
|
|
||||||
|
# Jinja filters
|
||||||
|
app.jinja_env.filters['minimal_round'] = minimal_round
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
babel = Babel(app)
|
babel = Babel(app)
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -203,7 +203,7 @@ def create_project():
|
||||||
body=message_body,
|
body=message_body,
|
||||||
recipients=[project.contact_email])
|
recipients=[project.contact_email])
|
||||||
try:
|
try:
|
||||||
mail.send(msg)
|
current_app.mail.send(msg)
|
||||||
except SMTPRecipientsRefused:
|
except SMTPRecipientsRefused:
|
||||||
msg_compl = 'Problem sending mail. '
|
msg_compl = 'Problem sending mail. '
|
||||||
# TODO: destroy the project and cancel instead?
|
# TODO: destroy the project and cancel instead?
|
||||||
|
@ -228,7 +228,7 @@ def remind_password():
|
||||||
|
|
||||||
# send the password reminder
|
# send the password reminder
|
||||||
password_reminder = "password_reminder.%s" % get_locale().language
|
password_reminder = "password_reminder.%s" % get_locale().language
|
||||||
mail.send(Message("password recovery",
|
current_app.mail.send(Message("password recovery",
|
||||||
body=render_template(password_reminder, project=project),
|
body=render_template(password_reminder, project=project),
|
||||||
recipients=[project.contact_email]))
|
recipients=[project.contact_email]))
|
||||||
flash(_("a mail has been sent to you with the password"))
|
flash(_("a mail has been sent to you with the password"))
|
||||||
|
|
Loading…
Reference in a new issue