diff --git a/Changelog.md b/Changelog.md index eb4cc34105655883a45956e83af95d3e14dbc6ae..361c4979afaf8af8e3eca835cccf8a729d18252e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. +## [0.34] - 2023-08-27 +- Fixed bug with "To" address for single email recipient + ## [0.33] - 2023-08-27 - Fixed utf-8 issues with sending emails - Fixed bug with applying migrations disabling all logging diff --git a/compendium_v2/email/__init__.py b/compendium_v2/email/__init__.py index c176f5199346c4b17206bf243ce2dd5aa3d24cd9..9e32a67ebc16e7d852ac840f41713498fde6e4f4 100644 --- a/compendium_v2/email/__init__.py +++ b/compendium_v2/email/__init__.py @@ -54,6 +54,8 @@ def send_mail( if not recipients: recipients = admin_emails + if isinstance(recipients, str): + recipients = [recipients] message = MIMEMultipart('alternative') message['Subject'] = subject diff --git a/setup.py b/setup.py index 4ab1bc289bc3abdbb833fe41d375f7c16cf6ef99..aaef8d475e08ae2ee01e6b6ba2ac0a4721143bda 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='compendium-v2', - version="0.33", + version="0.34", author='GEANT', author_email='swd@geant.org', description='Flask and React project for displaying ' diff --git a/test/test_send_mail.py b/test/test_send_mail.py index 01bb6a755bbf47f25cd111d45685016637eb0373..177b3e73251291808983b4b8339f2cb7fe1a79e6 100644 --- a/test/test_send_mail.py +++ b/test/test_send_mail.py @@ -1,11 +1,20 @@ from typing import List from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText # noqa: F401 +from email.mime.text import MIMEText from contextlib import contextmanager from compendium_v2.db.auth_model import User from compendium_v2.email import send_admin_signup_notification, send_user_signup_notification +class MockedThread(object): + def __init__(self, target, args): + self.target = target + self.args = args + + def start(self): + self.target(*self.args) + + def decode_message(msg: MIMEMultipart): message: List[MIMEText] = msg.get_payload() text: MIMEText = message[0] @@ -30,10 +39,15 @@ def test_signup_email_admin(app, mocked_admin_user, mocker): def _send_mail(*args, **kwargs): _msg = args[-1] decoded = decode_message(_msg) + _from = _msg['From'] + _to = _msg['To'] + assert _from == 'fakesender123@test.local' + assert _to == 'testemail123@email.local' message = 'testname has just signed up with the email testmail321@email.com and provider ID testsub' assert decoded == message mocker.patch('compendium_v2.email._send_mail', _send_mail) + mocker.patch('threading.Thread', MockedThread) with test_user(app) as user: send_admin_signup_notification(user) @@ -42,9 +56,14 @@ def test_signup_email_user(app, mocker): def _send_mail(*args, **kwargs): _msg = args[-1] + _from = _msg['From'] + _to = _msg['To'] + assert _from == 'fakesender123@test.local' + assert _to == 'testmail321@email.com' decoded = decode_message(_msg) assert len(decoded) > 50 # check that there's a message mocker.patch('compendium_v2.email._send_mail', _send_mail) + mocker.patch('threading.Thread', MockedThread) with test_user(app) as user: send_user_signup_notification(user, 'testname')