Files
dtf-system/tests/test_mail_html.py
Cauê Faleiros 3879754397
All checks were successful
Build and deploy / Validate source (push) Successful in 49s
Build and deploy / Integration suite on a real stack (push) Successful in 3m23s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m17s
feat: customer e-mails in the Site's look, and an order confirmation
The account e-mails (signup and e-mail change codes, new password, an
address that already has an account, the changed-e-mail notice) gain an
HTML version beside their plain text: the DROPSTAR header, a white card,
orange buttons, the customer greeted by first name. Built with tables and
inline styles only, so Gmail, Outlook and phone apps show it the same.

A paid order now also e-mails the customer "Recebemos seu pedido #N": the
items, delivery and total, the stages to come, and a link to the order in
the account. Not for an operator's test order. A code's or a recovery
link's HTML is erased with its text once sent. The team's alerts stay plain
text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 09:18:20 -03:00

37 lines
1.8 KiB
Python

"""The customer e-mails' HTML: escaped values, the name in the greeting, and a
layout mail clients render (tables and inline styles only)."""
import re
import unittest
from app import mail_html
class MailHtmlTest(unittest.TestCase):
def test_values_are_escaped_and_the_first_name_greets(self):
html = mail_html.email_changed('<b>Ana</b> Souza', 'a@x.test', 'b"<script>@x.test')
self.assertNotIn('<script>', html)
self.assertNotIn('<b>Ana</b>', html)
self.assertIn('Olá, &lt;b&gt;Ana&lt;/b&gt;!', html)
self.assertEqual(mail_html.greeting(''), 'Olá!')
self.assertEqual(mail_html.greeting(' Maria da Silva'), 'Olá, Maria!')
def test_every_message_is_tables_and_inline_styles(self):
messages = [mail_html.code('Maria', 'Confirme seu e-mail', 'criar a sua conta', '216561', 15, 'nada muda.'),
mail_html.reset('Maria', 'https://dtf.test/conta/redefinir#abc', 60),
mail_html.account_exists('Maria', 'https://dtf.test/conta/entrar'),
mail_html.email_changed('Maria', 'a@x.test', 'b@x.test'),
mail_html.order_paid('Maria', 12, [('Itens', 'DTF Têxtil · 2,8 m\nDTF UV · 1 m'),
('Total', 'R$ 70,00')], 'https://dtf.test/conta/pedidos?order=1')]
for html in messages:
with self.subTest(html=html[:80]):
self.assertNotIn('<style', html)
self.assertNotIn('display:flex', html.replace(' ', ''))
self.assertIn('role="presentation"', html)
self.assertIn('2&nbsp;1&nbsp;6&nbsp;5&nbsp;6&nbsp;1', messages[0])
self.assertIn('href="https://dtf.test/conta/redefinir#abc"', messages[1])
self.assertTrue(re.search(r'Recebemos seu pedido #12', messages[4]))
if __name__ == '__main__':
unittest.main()