From baede9ba5cf1341c15eba08743217f9af4367197 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 9 Mar 2022 10:23:21 +0100 Subject: [PATCH] API - init email template for email and password changes (WIP) --- .../en/body.html | 260 +++++++++++++++++ .../email_update_to_current_email/en/body.txt | 10 + .../en/subject.txt | 1 + .../fr/body.html | 260 +++++++++++++++++ .../email_update_to_current_email/fr/body.txt | 10 + .../fr/subject.txt | 1 + .../email_update_to_new_email/en/body.html | 266 +++++++++++++++++ .../email_update_to_new_email/en/body.txt | 12 + .../email_update_to_new_email/en/subject.txt | 1 + .../email_update_to_new_email/fr/body.html | 268 ++++++++++++++++++ .../email_update_to_new_email/fr/body.txt | 13 + .../email_update_to_new_email/fr/subject.txt | 1 + .../templates/password_change/en/body.html | 247 ++++++++++++++++ .../templates/password_change/en/body.txt | 10 + .../templates/password_change/en/subject.txt | 1 + .../templates/password_change/fr/body.html | 247 ++++++++++++++++ .../templates/password_change/fr/body.txt | 10 + .../templates/password_change/fr/subject.txt | 1 + .../email_update_to_current_email.py | 155 ++++++++++ .../email_update_to_new_email.py | 174 ++++++++++++ .../template_results/password_change.py | 129 +++++++++ .../test_email_template_email_update.py | 145 ++++++++++ .../test_email_template_password_change.py | 74 +++++ 23 files changed, 2296 insertions(+) create mode 100644 fittrackee/emails/templates/email_update_to_current_email/en/body.html create mode 100644 fittrackee/emails/templates/email_update_to_current_email/en/body.txt create mode 100644 fittrackee/emails/templates/email_update_to_current_email/en/subject.txt create mode 100644 fittrackee/emails/templates/email_update_to_current_email/fr/body.html create mode 100644 fittrackee/emails/templates/email_update_to_current_email/fr/body.txt create mode 100644 fittrackee/emails/templates/email_update_to_current_email/fr/subject.txt create mode 100644 fittrackee/emails/templates/email_update_to_new_email/en/body.html create mode 100644 fittrackee/emails/templates/email_update_to_new_email/en/body.txt create mode 100644 fittrackee/emails/templates/email_update_to_new_email/en/subject.txt create mode 100644 fittrackee/emails/templates/email_update_to_new_email/fr/body.html create mode 100644 fittrackee/emails/templates/email_update_to_new_email/fr/body.txt create mode 100644 fittrackee/emails/templates/email_update_to_new_email/fr/subject.txt create mode 100644 fittrackee/emails/templates/password_change/en/body.html create mode 100644 fittrackee/emails/templates/password_change/en/body.txt create mode 100644 fittrackee/emails/templates/password_change/en/subject.txt create mode 100644 fittrackee/emails/templates/password_change/fr/body.html create mode 100644 fittrackee/emails/templates/password_change/fr/body.txt create mode 100644 fittrackee/emails/templates/password_change/fr/subject.txt create mode 100644 fittrackee/tests/emails/template_results/email_update_to_current_email.py create mode 100644 fittrackee/tests/emails/template_results/email_update_to_new_email.py create mode 100644 fittrackee/tests/emails/template_results/password_change.py create mode 100644 fittrackee/tests/emails/test_email_template_email_update.py create mode 100644 fittrackee/tests/emails/test_email_template_password_change.py diff --git a/fittrackee/emails/templates/email_update_to_current_email/en/body.html b/fittrackee/emails/templates/email_update_to_current_email/en/body.html new file mode 100644 index 00000000..b5e782bb --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/en/body.html @@ -0,0 +1,260 @@ + + + + + + + FitTrackee - Email changed + + + + + Your email is being updated. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_current_email/en/body.txt b/fittrackee/emails/templates/email_update_to_current_email/en/body.txt new file mode 100644 index 00000000..4e1f0929 --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/en/body.txt @@ -0,0 +1,10 @@ +Hi {{username}}, + +You recently requested to change your email address for your FitTrackee account to: {{ new_email_address }} + +For security, this request was received from a {{operating_system}} device using {{browser_name}}. +If this email change wasn't initiated by you, please change your password immediately or contact your administrator if your account is locked. + +Thanks, +The FitTrackee Team +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/email_update_to_current_email/en/subject.txt b/fittrackee/emails/templates/email_update_to_current_email/en/subject.txt new file mode 100644 index 00000000..990157cc --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/en/subject.txt @@ -0,0 +1 @@ +FitTrackee - Email changed \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_current_email/fr/body.html b/fittrackee/emails/templates/email_update_to_current_email/fr/body.html new file mode 100644 index 00000000..f9d9d9e5 --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/fr/body.html @@ -0,0 +1,260 @@ + + + + + + + FitTrackee - Adresse email modifiée + + + + + Votre adresse email est en cours de mise à jour. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_current_email/fr/body.txt b/fittrackee/emails/templates/email_update_to_current_email/fr/body.txt new file mode 100644 index 00000000..a9ac9114 --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/fr/body.txt @@ -0,0 +1,10 @@ +Bonjour {{username}}, + +Vous avez récemment demandé la modification de l'adresse email associée à votre compte sur FitTrackee vers : {{ new_email_address }} + +Pour vérification, cette demande a été reçue à partir d'un appareil sous {{operating_system}}, utilisant le navigateur {{browser_name}}. +Si vous n'êtes pas à l'origine de cette modification, veuillez changer votre mot de passe immédiatement ou contacter l'administrateur si votre compte est bloqué. + +Merci, +L'équipe FitTrackee +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/email_update_to_current_email/fr/subject.txt b/fittrackee/emails/templates/email_update_to_current_email/fr/subject.txt new file mode 100644 index 00000000..758affe3 --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_current_email/fr/subject.txt @@ -0,0 +1 @@ +FitTrackee - Adresse email modifiée \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_new_email/en/body.html b/fittrackee/emails/templates/email_update_to_new_email/en/body.html new file mode 100644 index 00000000..5be7206d --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/en/body.html @@ -0,0 +1,266 @@ + + + + + + + Fittrackee - Confirm email change + + + + + Use this link to confirm email change. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_new_email/en/body.txt b/fittrackee/emails/templates/email_update_to_new_email/en/body.txt new file mode 100644 index 00000000..ccb6ba6f --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/en/body.txt @@ -0,0 +1,12 @@ +Hi {{username}}, + +You recently requested to change your email address for your FitTrackee account. Use the link below to confirm this address. + +Verify your email: {{ email_confirmation_url }} + +For security, this request was received from a {{operating_system}} device using {{browser_name}}. +If this email change wasn't initiated by you, please ignore this email. + +Thanks, +The FitTrackee Team +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/email_update_to_new_email/en/subject.txt b/fittrackee/emails/templates/email_update_to_new_email/en/subject.txt new file mode 100644 index 00000000..9b73071c --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/en/subject.txt @@ -0,0 +1 @@ +FitTrackee - Confirm email change \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_new_email/fr/body.html b/fittrackee/emails/templates/email_update_to_new_email/fr/body.html new file mode 100644 index 00000000..a41f27e8 --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/fr/body.html @@ -0,0 +1,268 @@ + + + + + + + FitTrackee - Confirmer le changement d'adresse email + + + + + Utiliser ce lien pour confirmer cette adresse email. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/email_update_to_new_email/fr/body.txt b/fittrackee/emails/templates/email_update_to_new_email/fr/body.txt new file mode 100644 index 00000000..cc82555b --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/fr/body.txt @@ -0,0 +1,13 @@ +Bonjour {{username}}, + +Vous avez récemment demandé la modification de l'adresse email associée à votre compte sur FitTrackee. +Cliquez sur le lien ci-dessous pour confirmer cette adresse email. + +Vérifier l'adresse email : {{ email_confirmation_url }} + +Pour vérification, cette demande a été reçue à partir d'un appareil sous {{operating_system}}, utilisant le navigateur {{browser_name}}. +Si vous n'êtes pas à l'origine de cette modification, vous pouvez ignorer cet e-mail. + +Merci, +L'équipe FitTrackee +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/email_update_to_new_email/fr/subject.txt b/fittrackee/emails/templates/email_update_to_new_email/fr/subject.txt new file mode 100644 index 00000000..3fed649e --- /dev/null +++ b/fittrackee/emails/templates/email_update_to_new_email/fr/subject.txt @@ -0,0 +1 @@ +FitTrackee - Confirmer le changement d'adresse email \ No newline at end of file diff --git a/fittrackee/emails/templates/password_change/en/body.html b/fittrackee/emails/templates/password_change/en/body.html new file mode 100644 index 00000000..33398a65 --- /dev/null +++ b/fittrackee/emails/templates/password_change/en/body.html @@ -0,0 +1,247 @@ + + + + + + + FitTrackee - Password changed + + + + + Your password has been changed. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/password_change/en/body.txt b/fittrackee/emails/templates/password_change/en/body.txt new file mode 100644 index 00000000..a56f9279 --- /dev/null +++ b/fittrackee/emails/templates/password_change/en/body.txt @@ -0,0 +1,10 @@ +Hi {{username}}, + +The password for your FitTrackee account has been changed. + +For security, this request was received from a {{operating_system}} device using {{browser_name}}. +If this password change wasn't initiated by you, please change your password immediately or contact your administrator if your account is locked. + +Thanks, +The FitTrackee Team +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/password_change/en/subject.txt b/fittrackee/emails/templates/password_change/en/subject.txt new file mode 100644 index 00000000..2669367f --- /dev/null +++ b/fittrackee/emails/templates/password_change/en/subject.txt @@ -0,0 +1 @@ +FitTrackee - Password changed \ No newline at end of file diff --git a/fittrackee/emails/templates/password_change/fr/body.html b/fittrackee/emails/templates/password_change/fr/body.html new file mode 100644 index 00000000..3a39e19f --- /dev/null +++ b/fittrackee/emails/templates/password_change/fr/body.html @@ -0,0 +1,247 @@ + + + + + + + FitTrackee - Mot de passe modifié + + + + + Votre mot de passe a été modifié. + + + + + + + \ No newline at end of file diff --git a/fittrackee/emails/templates/password_change/fr/body.txt b/fittrackee/emails/templates/password_change/fr/body.txt new file mode 100644 index 00000000..82b2aed6 --- /dev/null +++ b/fittrackee/emails/templates/password_change/fr/body.txt @@ -0,0 +1,10 @@ +Bonjour {{username}}, + +Le mot de passe de votre compte FitTrackee a été modifié. + +Pour vérification, cette demande a été reçue à partir d'un appareil sous {{operating_system}}, utilisant le navigateur {{browser_name}}. +Si vous n'êtes pas à l'origine de cette modification, veuillez changer votre mot de passe immédiatement ou contacter l'administrateur si votre compte est bloqué. + +Merci, +L'équipe FitTrackee +{{fittrackee_url}} diff --git a/fittrackee/emails/templates/password_change/fr/subject.txt b/fittrackee/emails/templates/password_change/fr/subject.txt new file mode 100644 index 00000000..7ec45c21 --- /dev/null +++ b/fittrackee/emails/templates/password_change/fr/subject.txt @@ -0,0 +1 @@ +FitTrackee - Mot de passe modifié \ No newline at end of file diff --git a/fittrackee/tests/emails/template_results/email_update_to_current_email.py b/fittrackee/tests/emails/template_results/email_update_to_current_email.py new file mode 100644 index 00000000..1d0a3dba --- /dev/null +++ b/fittrackee/tests/emails/template_results/email_update_to_current_email.py @@ -0,0 +1,155 @@ +# flake8: noqa + +expected_en_text_body = """Hi test, + +You recently requested to change your email address for your FitTrackee account to: new.email@example.com + +For security, this request was received from a Linux device using Firefox. +If this email change wasn't initiated by you, please change your password immediately or contact your administrator if your account is locked. + +Thanks, +The FitTrackee Team +http://localhost""" + +expected_fr_text_body = """Bonjour test, + +Vous avez récemment demandé la modification de l'adresse email associée à votre compte sur FitTrackee vers : new.email@example.com + +Pour vérification, cette demande a été reçue à partir d'un appareil sous Linux, utilisant le navigateur Firefox. +Si vous n'êtes pas à l'origine de cette modification, veuillez changer votre mot de passe immédiatement ou contacter l'administrateur si votre compte est bloqué. + +Merci, +L'équipe FitTrackee +http://localhost""" + +expected_en_html_body = """ + Your email is being updated. + + + + + + +""" + +expected_fr_html_body = """ + Votre adresse email est en cours de mise à jour. + + + + + + +""" diff --git a/fittrackee/tests/emails/template_results/email_update_to_new_email.py b/fittrackee/tests/emails/template_results/email_update_to_new_email.py new file mode 100644 index 00000000..39f61e9e --- /dev/null +++ b/fittrackee/tests/emails/template_results/email_update_to_new_email.py @@ -0,0 +1,174 @@ +# flake8: noqa + +expected_en_text_body = """Hi test, + +You recently requested to change your email address for your FitTrackee account. Use the link below to confirm this address. + +Verify your email: http://localhost/email-update?token=xxx + +For security, this request was received from a Linux device using Firefox. +If this email change wasn't initiated by you, please ignore this email. + +Thanks, +The FitTrackee Team +http://localhost""" + +expected_fr_text_body = """Bonjour test, + +Vous avez récemment demandé la modification de l'adresse email associée à votre compte sur FitTrackee. +Cliquez sur le lien ci-dessous pour confirmer cette adresse email. + +Vérifier l'adresse email : http://localhost/email-update?token=xxx + +Pour vérification, cette demande a été reçue à partir d'un appareil sous Linux, utilisant le navigateur Firefox. +Si vous n'êtes pas à l'origine de cette modification, vous pouvez ignorer cet e-mail. + +Merci, +L'équipe FitTrackee +http://localhost""" + +expected_en_html_body = """ + Use this link to confirm email change. + + + + + + +""" + +expected_fr_html_body = """ + Utiliser ce lien pour confirmer cette adresse email. + + + + + + +""" diff --git a/fittrackee/tests/emails/template_results/password_change.py b/fittrackee/tests/emails/template_results/password_change.py new file mode 100644 index 00000000..ab5b0874 --- /dev/null +++ b/fittrackee/tests/emails/template_results/password_change.py @@ -0,0 +1,129 @@ +# flake8: noqa + +expected_en_text_body = """Hi test, + +The password for your FitTrackee account has been changed. + +For security, this request was received from a Linux device using Firefox. +If this password change wasn't initiated by you, please change your password immediately or contact your administrator if your account is locked. + +Thanks, +The FitTrackee Team +http://localhost""" + +expected_fr_text_body = """Bonjour test, + +Le mot de passe de votre compte FitTrackee a été modifié. + +Pour vérification, cette demande a été reçue à partir d'un appareil sous Linux, utilisant le navigateur Firefox. +Si vous n'êtes pas à l'origine de cette modification, veuillez changer votre mot de passe immédiatement ou contacter l'administrateur si votre compte est bloqué. + +Merci, +L'équipe FitTrackee +http://localhost""" + +expected_en_html_body = """ + Your password has been changed. + + + + + + +""" + +expected_fr_html_body = """ + Votre mot de passe a été modifié. + + + + + + +""" diff --git a/fittrackee/tests/emails/test_email_template_email_update.py b/fittrackee/tests/emails/test_email_template_email_update.py new file mode 100644 index 00000000..ea2f3c9d --- /dev/null +++ b/fittrackee/tests/emails/test_email_template_email_update.py @@ -0,0 +1,145 @@ +import pytest +from flask import Flask + +from fittrackee.emails.email import EmailTemplate + +from .template_results.email_update_to_current_email import ( + expected_en_html_body as expected_en_current_email_html_body, + expected_en_text_body as expected_en_current_email_text_body, + expected_fr_html_body as expected_fr_current_email_html_body, + expected_fr_text_body as expected_fr_current_email_text_body, +) +from .template_results.email_update_to_new_email import ( + expected_en_html_body as expected_en_new_email_html_body, + expected_en_text_body as expected_en_new_email_text_body, + expected_fr_html_body as expected_fr_new_email_html_body, + expected_fr_text_body as expected_fr_new_email_text_body, +) + + +class TestEmailTemplateForEmailUpdateToCurrentEmail: + EMAIL_DATA = { + 'username': 'test', + 'new_email_address': 'new.email@example.com', + 'operating_system': 'Linux', + 'browser_name': 'Firefox', + 'fittrackee_url': 'http://localhost', + } + + @pytest.mark.parametrize( + 'lang, expected_subject', + [ + ('en', 'FitTrackee - Email changed'), + ('fr', 'FitTrackee - Adresse email modifiée'), + ], + ) + def test_it_gets_subject( + self, app: Flask, lang: str, expected_subject: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + subject = email_template.get_content( + 'email_update_to_current_email', lang, 'subject.txt', {} + ) + + assert subject == expected_subject + + @pytest.mark.parametrize( + 'lang, expected_text_body', + [ + ('en', expected_en_current_email_text_body), + ('fr', expected_fr_current_email_text_body), + ], + ) + def test_it_gets_text_body( + self, app: Flask, lang: str, expected_text_body: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_current_email', lang, 'body.txt', self.EMAIL_DATA + ) + + assert text_body == expected_text_body + + def test_it_gets_en_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_current_email', 'en', 'body.html', self.EMAIL_DATA + ) + + assert expected_en_current_email_html_body in text_body + + def test_it_gets_fr_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_current_email', 'fr', 'body.html', self.EMAIL_DATA + ) + + assert expected_fr_current_email_html_body in text_body + + +class TestEmailTemplateForEmailUpdateToNewEmail: + EMAIL_DATA = { + 'username': 'test', + 'email_confirmation_url': 'http://localhost/email-update?token=xxx', + 'operating_system': 'Linux', + 'browser_name': 'Firefox', + 'fittrackee_url': 'http://localhost', + } + + @pytest.mark.parametrize( + 'lang, expected_subject', + [ + ('en', 'FitTrackee - Confirm email change'), + ('fr', "FitTrackee - Confirmer le changement d'adresse email"), + ], + ) + def test_it_gets_subject( + self, app: Flask, lang: str, expected_subject: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + subject = email_template.get_content( + 'email_update_to_new_email', lang, 'subject.txt', {} + ) + + assert subject == expected_subject + + @pytest.mark.parametrize( + 'lang, expected_text_body', + [ + ('en', expected_en_new_email_text_body), + ('fr', expected_fr_new_email_text_body), + ], + ) + def test_it_gets_text_body( + self, app: Flask, lang: str, expected_text_body: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_new_email', lang, 'body.txt', self.EMAIL_DATA + ) + + assert text_body == expected_text_body + + def test_it_gets_en_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_new_email', 'en', 'body.html', self.EMAIL_DATA + ) + + assert expected_en_new_email_html_body in text_body + + def test_it_gets_fr_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'email_update_to_new_email', 'fr', 'body.html', self.EMAIL_DATA + ) + + assert expected_fr_new_email_html_body in text_body diff --git a/fittrackee/tests/emails/test_email_template_password_change.py b/fittrackee/tests/emails/test_email_template_password_change.py new file mode 100644 index 00000000..f93be338 --- /dev/null +++ b/fittrackee/tests/emails/test_email_template_password_change.py @@ -0,0 +1,74 @@ +import pytest +from flask import Flask + +from fittrackee.emails.email import EmailTemplate + +from .template_results.password_change import ( + expected_en_html_body, + expected_en_text_body, + expected_fr_html_body, + expected_fr_text_body, +) + + +class TestEmailTemplateForPasswordChange: + EMAIL_DATA = { + 'username': 'test', + 'operating_system': 'Linux', + 'browser_name': 'Firefox', + 'fittrackee_url': 'http://localhost', + } + + @pytest.mark.parametrize( + 'lang, expected_subject', + [ + ('en', 'FitTrackee - Password changed'), + ('fr', 'FitTrackee - Mot de passe modifié'), + ], + ) + def test_it_gets_subject( + self, app: Flask, lang: str, expected_subject: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + subject = email_template.get_content( + 'password_change', lang, 'subject.txt', {} + ) + + assert subject == expected_subject + + @pytest.mark.parametrize( + 'lang, expected_text_body', + [ + ('en', expected_en_text_body), + ('fr', expected_fr_text_body), + ], + ) + def test_it_gets_text_body( + self, app: Flask, lang: str, expected_text_body: str + ) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'password_change', lang, 'body.txt', self.EMAIL_DATA + ) + + assert text_body == expected_text_body + + def test_it_gets_en_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'password_change', 'en', 'body.html', self.EMAIL_DATA + ) + + assert expected_en_html_body in text_body + + def test_it_gets_fr_html_body(self, app: Flask) -> None: + email_template = EmailTemplate(app.config['TEMPLATES_FOLDER']) + + text_body = email_template.get_content( + 'password_change', 'fr', 'body.html', self.EMAIL_DATA + ) + + assert expected_fr_html_body in text_body