From 3b2e11ab6369dfa853383840dc28915b60c2d062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 5 Jan 2018 22:06:11 +0100 Subject: Include all .j2 files in the packaged version. I've also renamed the templates to *.j2 in order to make things clearer to others. Having extensions with the name of the locale doesn't seem to be a good practice, and would need us to add the locales in the MANIFEST file each time we add one. Fix #305 --- MANIFEST.in | 2 +- ihatemoney/templates/invitation_mail.en | 12 ------------ ihatemoney/templates/invitation_mail.en.j2 | 12 ++++++++++++ ihatemoney/templates/invitation_mail.fr | 11 ----------- ihatemoney/templates/invitation_mail.fr.j2 | 11 +++++++++++ ihatemoney/templates/password_reminder.en | 8 -------- ihatemoney/templates/password_reminder.en.j2 | 8 ++++++++ ihatemoney/templates/password_reminder.fr | 7 ------- ihatemoney/templates/password_reminder.fr.j2 | 7 +++++++ ihatemoney/templates/reminder_mail.en | 10 ---------- ihatemoney/templates/reminder_mail.en.j2 | 10 ++++++++++ ihatemoney/templates/reminder_mail.fr | 9 --------- ihatemoney/templates/reminder_mail.fr.j2 | 9 +++++++++ ihatemoney/web.py | 6 +++--- 14 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 ihatemoney/templates/invitation_mail.en create mode 100644 ihatemoney/templates/invitation_mail.en.j2 delete mode 100644 ihatemoney/templates/invitation_mail.fr create mode 100644 ihatemoney/templates/invitation_mail.fr.j2 delete mode 100644 ihatemoney/templates/password_reminder.en create mode 100644 ihatemoney/templates/password_reminder.en.j2 delete mode 100644 ihatemoney/templates/password_reminder.fr create mode 100644 ihatemoney/templates/password_reminder.fr.j2 delete mode 100644 ihatemoney/templates/reminder_mail.en create mode 100644 ihatemoney/templates/reminder_mail.en.j2 delete mode 100644 ihatemoney/templates/reminder_mail.fr create mode 100644 ihatemoney/templates/reminder_mail.fr.j2 diff --git a/MANIFEST.in b/MANIFEST.in index 91d0edb..74ea23b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include *.rst -recursive-include ihatemoney *.rst *.py *.yaml *.po *.mo *.html *.css *.js *.eot *.svg *.woff *.txt *.png *.ini *.cfg +recursive-include ihatemoney *.rst *.py *.yaml *.po *.mo *.html *.css *.js *.eot *.svg *.woff *.txt *.png *.ini *.cfg *.j2 include LICENSE CONTRIBUTORS CHANGELOG.rst requirements.txt diff --git a/ihatemoney/templates/invitation_mail.en b/ihatemoney/templates/invitation_mail.en deleted file mode 100644 index eeaafdb..0000000 --- a/ihatemoney/templates/invitation_mail.en +++ /dev/null @@ -1,12 +0,0 @@ -Hi, - -Someone using the email address {{ g.project.contact_email }} invited you to share your expenses for "{{ g.project.name }}". - -It's as simple as saying what did you paid for, for who, and how much did it cost you, we are caring about the rest. - -You can log in using this link: {{ url_for(".authenticate", _external=True, token=g.project.generate_token()) }}. -Once logged in you can use the following link which is easier to remember: {{ url_for(".list_bills", _external=True) }} -If your cookie gets deleted or if you log out, you will need to log back in using the first link. - -Enjoy, -Some weird guys (with beards) diff --git a/ihatemoney/templates/invitation_mail.en.j2 b/ihatemoney/templates/invitation_mail.en.j2 new file mode 100644 index 0000000..42be0d2 --- /dev/null +++ b/ihatemoney/templates/invitation_mail.en.j2 @@ -0,0 +1,12 @@ +Hi, + +Someone using the email address {{ g.project.contact_email }} invited you to share your expenses for "{{ g.project.name }}". + +It's as simple as saying what did you pay for, for whom, and how much did it cost you, we are caring about the rest. + +You can log in using this link: {{ url_for(".authenticate", _external=True, token=g.project.generate_token()) }}. +Once logged-in, you can use the following link which is easier to remember: {{ url_for(".list_bills", _external=True) }} +If your cookie gets deleted or if you log out, you will need to log back in using the first link. + +Enjoy, +Some weird guys (with beards) diff --git a/ihatemoney/templates/invitation_mail.fr b/ihatemoney/templates/invitation_mail.fr deleted file mode 100644 index a95f9e9..0000000 --- a/ihatemoney/templates/invitation_mail.fr +++ /dev/null @@ -1,11 +0,0 @@ -Salut, - -Quelqu'un avec l'addresse email "{{ g.project.contact_email }}" vous à invité à partager vos dépenses pour "{{ g.project.name }}". - -C'est aussi simple que de dire qui à payé pour quoi, pour qui, et combien celà à coûté, on s'occuppe du reste. - -Vous pouvez vous authentifier avec le lien suivant: {{ url_for(".authenticate", _external=True, token=g.project.generate_token()) }}. -Une fois authentifié, vous pouvez utiliser le lien suivant qui est plus facile à mémoriser: {{ url_for(".list_bills", _external=True) }} -Si votre cookie est supprimé ou si vous vous déconnectez, voous devrez vous réauthentifier en utilisant le premier lien. - -Have fun, diff --git a/ihatemoney/templates/invitation_mail.fr.j2 b/ihatemoney/templates/invitation_mail.fr.j2 new file mode 100644 index 0000000..197edcc --- /dev/null +++ b/ihatemoney/templates/invitation_mail.fr.j2 @@ -0,0 +1,11 @@ +Salut, + +Quelqu'un avec l'adresse "{{ g.project.contact_email }}" vous à invité à partager vos dépenses pour "{{ g.project.name }}". + +C'est aussi simple que de dire qui à payé pour quoi, pour qui, et combien celà à coûté, on s’occupe du reste. + +Vous pouvez vous authentifier avec le lien suivant: {{ url_for(".authenticate", _external=True, token=g.project.generate_token()) }}. +Une fois authentifié, vous pouvez utiliser le lien suivant qui est plus facile à mémoriser: {{ url_for(".list_bills", _external=True) }} +Si votre cookie est supprimé ou si vous vous déconnectez, vous devrez vous authentifier à nouveau en utilisant le premier lien. + +Have fun, diff --git a/ihatemoney/templates/password_reminder.en b/ihatemoney/templates/password_reminder.en deleted file mode 100644 index bc7e609..0000000 --- a/ihatemoney/templates/password_reminder.en +++ /dev/null @@ -1,8 +0,0 @@ -Hi, - -You requested to reset the password of the following project: "{{ project.name }}". -You can reset it here: {{ url_for(".reset_password", _external=True, token=project.generate_token(expiration=3600)) }}. -This link is only valid for 1 hour. - -Hope this helps, -Some weird guys (with beards) diff --git a/ihatemoney/templates/password_reminder.en.j2 b/ihatemoney/templates/password_reminder.en.j2 new file mode 100644 index 0000000..c654354 --- /dev/null +++ b/ihatemoney/templates/password_reminder.en.j2 @@ -0,0 +1,8 @@ +Hi, + +You requested to reset the password of the following project: "{{ project.name }}". +You can reset it here: {{ url_for(".reset_password", _external=True, token=project.generate_token(expiration=3600)) }}. +This link is only valid for one hour. + +Hope this helps, +Some weird guys (with beards) diff --git a/ihatemoney/templates/password_reminder.fr b/ihatemoney/templates/password_reminder.fr deleted file mode 100644 index d4fbc2d..0000000 --- a/ihatemoney/templates/password_reminder.fr +++ /dev/null @@ -1,7 +0,0 @@ -Salut, - -Vous avez demandé à réinitialiser le mot de passe du projet suivant : "{{ project.name }}". -Vous pouvez le réinitialiser ici : {{ url_for(".reset_password", _external=True, token=project.generate_token(expiration=3600)) }}. -Ce lien est seulement valide pendant 1 heure. - -Faites en bon usage ! diff --git a/ihatemoney/templates/password_reminder.fr.j2 b/ihatemoney/templates/password_reminder.fr.j2 new file mode 100644 index 0000000..d4fbc2d --- /dev/null +++ b/ihatemoney/templates/password_reminder.fr.j2 @@ -0,0 +1,7 @@ +Salut, + +Vous avez demandé à réinitialiser le mot de passe du projet suivant : "{{ project.name }}". +Vous pouvez le réinitialiser ici : {{ url_for(".reset_password", _external=True, token=project.generate_token(expiration=3600)) }}. +Ce lien est seulement valide pendant 1 heure. + +Faites en bon usage ! diff --git a/ihatemoney/templates/reminder_mail.en b/ihatemoney/templates/reminder_mail.en deleted file mode 100644 index 8784d2a..0000000 --- a/ihatemoney/templates/reminder_mail.en +++ /dev/null @@ -1,10 +0,0 @@ -Hi, - -You have just (or someone else using your email address) created the project "{{ g.project.name }}" to share your expenses. - -You can access it here: {{ url_for(".list_bills", _external=True) }} (the identifier is {{ g.project.id }}). -If you want to share this project with your friends, you can share the identifier and the shared password with them or send them invitations with the following link: -{{ url_for(".invite", _external=True) }} - -Enjoy, -Some weird guys (with beards) diff --git a/ihatemoney/templates/reminder_mail.en.j2 b/ihatemoney/templates/reminder_mail.en.j2 new file mode 100644 index 0000000..8784d2a --- /dev/null +++ b/ihatemoney/templates/reminder_mail.en.j2 @@ -0,0 +1,10 @@ +Hi, + +You have just (or someone else using your email address) created the project "{{ g.project.name }}" to share your expenses. + +You can access it here: {{ url_for(".list_bills", _external=True) }} (the identifier is {{ g.project.id }}). +If you want to share this project with your friends, you can share the identifier and the shared password with them or send them invitations with the following link: +{{ url_for(".invite", _external=True) }} + +Enjoy, +Some weird guys (with beards) diff --git a/ihatemoney/templates/reminder_mail.fr b/ihatemoney/templates/reminder_mail.fr deleted file mode 100644 index e73938a..0000000 --- a/ihatemoney/templates/reminder_mail.fr +++ /dev/null @@ -1,9 +0,0 @@ -Hey, - -Vous venez de créer le projet "{{ g.project.name }}" pour partager vos dépenses. - -Vous pouvez y accéder ici: {{ url_for(".list_bills", _external=True) }} (l'identifieur est {{ g.project.id }}). -Si vous voulez partager ce projet avec vos amis, vous pouvez partager son identifiant et son code d'accès avec eux ou leur envoyer une invitation avec le lien suivant : -{{ url_for(".invite", _external=True) }} - -Faites en bon usage ! diff --git a/ihatemoney/templates/reminder_mail.fr.j2 b/ihatemoney/templates/reminder_mail.fr.j2 new file mode 100644 index 0000000..e73938a --- /dev/null +++ b/ihatemoney/templates/reminder_mail.fr.j2 @@ -0,0 +1,9 @@ +Hey, + +Vous venez de créer le projet "{{ g.project.name }}" pour partager vos dépenses. + +Vous pouvez y accéder ici: {{ url_for(".list_bills", _external=True) }} (l'identifieur est {{ g.project.id }}). +Si vous voulez partager ce projet avec vos amis, vous pouvez partager son identifiant et son code d'accès avec eux ou leur envoyer une invitation avec le lien suivant : +{{ url_for(".invite", _external=True) }} + +Faites en bon usage ! diff --git a/ihatemoney/web.py b/ihatemoney/web.py index e6df385..6b1b358 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -242,7 +242,7 @@ def create_project(): message_title = _("You have just created '%(project)s' " "to share your expenses", project=g.project.name) - message_body = render_template("reminder_mail.%s" % + message_body = render_template("reminder_mail.%s.j2" % get_locale().language) msg = Message(message_title, @@ -273,7 +273,7 @@ def remind_password(): project = Project.query.get(form.id.data) # send a link to reset the password - password_reminder = "password_reminder.%s" % get_locale().language + password_reminder = "password_reminder.%s.j2" % get_locale().language current_app.mail.send(Message( "password recovery", body=render_template(password_reminder, project=project), @@ -395,7 +395,7 @@ def invite(): if form.validate(): # send the email - message_body = render_template("invitation_mail.%s" % + message_body = render_template("invitation_mail.%s.j2" % get_locale().language) message_title = _("You have been invited to share your " -- cgit v1.1 From 2019b398f164aa3f7edb8af439c92f1a32d2e920 Mon Sep 17 00:00:00 2001 From: JocelynDelalande Date: Sun, 7 Jan 2018 00:27:42 +0100 Subject: manage commands testing (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename manage.ConfigTemplate → manage.GenerateConfig To be consistent with the CLI name: `generate-config`. * Add tests for manage.py commands * Run tests from pip-installed package To be able to detect packaging-related issues on test runs. refs #305 --- dev-requirements.txt | 1 + ihatemoney/manage.py | 8 ++++---- ihatemoney/tests/tests.py | 27 +++++++++++++++++++++++++++ tox.ini | 13 +++++++++++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 04358ae..28116fa 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -3,3 +3,4 @@ tox pytest Flask-Testing Flake8 +mock; python_version < '3.3' diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 797e6c4..315cfac 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -4,7 +4,7 @@ import os import pkgutil import random import sys -from getpass import getpass +import getpass from flask_script import Manager, Command, Option from flask_migrate import Migrate, MigrateCommand @@ -20,11 +20,11 @@ class GeneratePasswordHash(Command): """Get password from user and hash it without printing it in clear text.""" def run(self): - password = getpass(prompt='Password: ') + password = getpass.getpass(prompt='Password: ') print(generate_password_hash(password)) -class ConfigTemplate(Command): +class GenerateConfig(Command): def get_options(self): return [ Option('config_file', choices=[ @@ -74,7 +74,7 @@ def main(): manager = Manager(app) manager.add_command('db', MigrateCommand) manager.add_command('generate_password_hash', GeneratePasswordHash) - manager.add_command('generate-config', ConfigTemplate) + manager.add_command('generate-config', GenerateConfig) manager.run() diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index de53c58..d4b6d7a 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -4,6 +4,10 @@ try: import unittest2 as unittest except ImportError: import unittest # NOQA +try: + from unittest.mock import patch +except ImportError: + from mock import patch import os import json @@ -16,6 +20,7 @@ from flask import session from flask_testing import TestCase from ihatemoney.run import create_app, db, load_configuration +from ihatemoney.manage import GenerateConfig, GeneratePasswordHash from ihatemoney import models from ihatemoney import utils @@ -1406,5 +1411,27 @@ class ServerTestCase(IhatemoneyTestCase): self.assertStatus(200, req) +class CommandTestCase(BaseTestCase): + def test_generate_config(self): + """ Simply checks that all config file generation + - raise no exception + - produce something non-empty + """ + cmd = GenerateConfig() + for config_file in cmd.get_options()[0].kwargs['choices']: + with patch('sys.stdout', new=six.StringIO()) as stdout: + cmd.run(config_file) + print(stdout.getvalue()) + self.assertNotEqual(len(stdout.getvalue().strip()), 0) + + def test_generate_password_hash(self): + cmd = GeneratePasswordHash() + with patch('sys.stdout', new=six.StringIO()) as stdout, \ + patch('getpass.getpass', new=lambda prompt: 'secret'): # NOQA + cmd.run() + print(stdout.getvalue()) + self.assertEqual(len(stdout.getvalue().strip()), 187) + + if __name__ == "__main__": unittest.main() diff --git a/tox.ini b/tox.ini index ddef0a1..15c2b40 100644 --- a/tox.ini +++ b/tox.ini @@ -6,22 +6,31 @@ skip_missing_interpreters = True commands = python --version - py.test ihatemoney/tests/tests.py + py.test --pyargs ihatemoney.tests.tests + deps = -rdev-requirements.txt -rrequirements.txt -install_command = pip install --pre {opts} {packages} +# To be sure we are importing ihatemoney pkg from pip-installed version +changedir = /tmp + +install_command = + pip install --pre {opts} {packages} + pip install . + [testenv:docs] commands = sphinx-build -a -n -b html -d docs/_build/doctrees docs docs/_build/html deps = -rdocs/requirements.txt +changedir = {toxinidir} [testenv:lint] commands = flake8 ihatemoney deps = -rdev-requirements.txt +changedir = {toxinidir} [flake8] exclude = migrations -- cgit v1.1 From f1e2a2d84ceb13951c2547c6548eb823b60ce77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sun, 7 Jan 2018 21:43:35 +0100 Subject: Add a changelog entry --- CHANGELOG.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de1356e..bc1024d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,10 @@ This document describes changes between each past release. 2.1 (unreleased) ---------------- -- Nothing changed yet. +Fixed +===== + +- Include all .j2 files in the packaged version (#308) 2.0 (2017-12-27) -- cgit v1.1 From c24ee6f1c4e1c1090f0833f65b795512fc03de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sun, 7 Jan 2018 22:46:07 +0100 Subject: Update the CHANGELOG. --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bc1024d..9aa61be 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,7 @@ This document describes changes between each past release. Fixed ===== -- Include all .j2 files in the packaged version (#308) +- Fix the "IOError" crash when running `ihatemoney generate-config` (#308) 2.0 (2017-12-27) -- cgit v1.1