From b790109f5799a5615fc833a6a6fe39fc4ea85d92 Mon Sep 17 00:00:00 2001 From: Bjarke Madsen <bjarke@nordu.net> Date: Mon, 21 Aug 2023 14:05:17 +0200 Subject: [PATCH] Add mail config to example config and add test --- config-example.json | 10 +++++++++- test/conftest.py | 4 ++-- test/test_send_mail.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/test_send_mail.py diff --git a/config-example.json b/config-example.json index a04ee059..f712e8b4 100644 --- a/config-example.json +++ b/config-example.json @@ -6,5 +6,13 @@ "client_secret": "<secret>", "server_metadata_url": "https://accounts.google.com/.well-known/openid-configuration" }, - "SECRET_KEY": "changeme" + "SECRET_KEY": "changeme", + "mail": { + "MAIL_SERVER": "mail.geant.net", + "MAIL_PORT": 25, + "MAIL_SENDER_EMAIL": "compendium@geant.org", + "MAIL_EXCLUDED_ADMINS": [ + "bjarke@nordu.net" + ] + } } diff --git a/test/conftest.py b/test/conftest.py index 001aee50..154265bc 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -26,7 +26,7 @@ def dummy_config(): @pytest.fixture -def mocked_admin_user(app, mocker): +def mocked_admin_user(app, test_survey_data, mocker): with app.app_context(): user = User(email='testemail123@email.local', fullname='testfullname', oidc_sub='fakesub', roles=ROLES.admin) @@ -42,7 +42,7 @@ def mocked_admin_user(app, mocker): @pytest.fixture -def mocked_user(app, mocker): +def mocked_user(app, test_survey_data, mocker): with app.app_context(): user = User(email='testemail123@email.local', fullname='testfullname', oidc_sub='fakesub') diff --git a/test/test_send_mail.py b/test/test_send_mail.py new file mode 100644 index 00000000..a1725367 --- /dev/null +++ b/test/test_send_mail.py @@ -0,0 +1,16 @@ +from compendium_v2.email import send_mail + + +def test_email(app, mocked_admin_user, mocker): + + def _send_mail(*args, **kwargs): + pass + + mocker.patch('compendium_v2.email._send_mail', _send_mail) + with app.app_context(): + app.config['MAIL_ENABLE'] = True + app.config['MAIL_SERVER'] = 'localhost' + app.config['MAIL_PORT'] = 54655 + app.config['MAIL_SENDER_EMAIL'] = 'fakesender123@test.local' + app.config['MAIL_EXCLUDED_ADMINS'] = [] + send_mail('testmail321') -- GitLab