FitTrackee/fittrackee/tests/emails/test_email_template_password_request.py

199 lines
6.4 KiB
Python
Raw Permalink Normal View History

import pytest
2021-01-02 19:28:03 +01:00
from flask import Flask
2021-01-20 16:47:00 +01:00
from fittrackee.emails.email import EmailTemplate
from .template_results.password_reset_request import (
expected_en_html_body,
expected_en_html_body_without_security,
expected_en_text_body,
expected_en_text_body_without_security,
expected_fr_html_body,
expected_fr_html_body_without_security,
expected_fr_text_body,
expected_fr_text_body_without_security,
)
class TestEmailTemplateForPasswordRequest:
@pytest.mark.parametrize(
'lang, expected_subject',
[
('en', 'FitTrackee - Password reset request'),
('fr', 'FitTrackee - Réinitialiser votre mot de passe'),
],
)
2021-01-02 19:28:03 +01:00
def test_it_gets_subject(
self, app: Flask, lang: str, expected_subject: str
) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
subject = email_template.get_content(
'password_reset_request', lang, 'subject.txt', {}
)
assert subject == expected_subject
@pytest.mark.parametrize(
'lang, expected_text_body',
[('en', expected_en_text_body), ('fr', expected_fr_text_body)],
)
2021-01-02 19:28:03 +01:00
def test_it_gets_text_body(
self, app: Flask, lang: str, expected_text_body: str
) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 seconds' if lang == 'en' else '3 secondes',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'operating_system': 'Linux',
'browser_name': 'Firefox',
2022-03-02 10:39:10 +01:00
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', lang, 'body.txt', email_data
)
assert text_body == expected_text_body
2021-01-02 19:28:03 +01:00
def test_it_gets_en_html_body(self, app: Flask) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 seconds',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'operating_system': 'Linux',
'browser_name': 'Firefox',
2022-03-02 10:39:10 +01:00
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', 'en', 'body.html', email_data
)
assert expected_en_html_body in text_body
2021-01-02 19:28:03 +01:00
def test_it_gets_fr_html_body(self, app: Flask) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 secondes',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'operating_system': 'Linux',
'browser_name': 'Firefox',
2022-03-02 10:39:10 +01:00
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', 'fr', 'body.html', email_data
)
assert expected_fr_html_body in text_body
class TestEmailTemplateForPasswordRequestWithoutSecurityInfos:
@pytest.mark.parametrize(
'lang, expected_subject',
[
('en', 'FitTrackee - Password reset request'),
('fr', 'FitTrackee - Réinitialiser votre mot de passe'),
],
)
def test_it_gets_subject(
self, app: Flask, lang: str, expected_subject: str
) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
subject = email_template.get_content(
'password_reset_request', lang, 'subject.txt', {}
)
assert subject == expected_subject
@pytest.mark.parametrize(
'lang, expected_text_body',
[
('en', expected_en_text_body_without_security),
('fr', expected_fr_text_body_without_security),
],
)
def test_it_gets_text_body(
self, app: Flask, lang: str, expected_text_body: str
) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 seconds' if lang == 'en' else '3 secondes',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', lang, 'body.txt', email_data
)
assert text_body == expected_text_body
def test_it_gets_en_html_body(self, app: Flask) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 seconds',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', 'en', 'body.html', email_data
)
assert expected_en_html_body_without_security in text_body
def test_it_gets_fr_html_body(self, app: Flask) -> None:
2022-07-02 19:25:07 +02:00
email_template = EmailTemplate(
app.config['TEMPLATES_FOLDER'],
app.config['TRANSLATIONS_FOLDER'],
app.config['LANGUAGES'],
)
email_data = {
'expiration_delay': '3 secondes',
'username': 'test',
'password_reset_url': 'http://localhost/password-reset?token=xxx',
'fittrackee_url': 'http://localhost',
}
text_body = email_template.get_content(
'password_reset_request', 'fr', 'body.html', email_data
)
assert expected_fr_html_body_without_security in text_body