From 97b11eabbdd649136035c28f3454e28724122f88 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Mon, 10 Apr 2017 19:28:35 +0100 Subject: [PATCH] Add test for sending emails. Add backup email if there isn't an MIC --- PyRIGS/settings.py | 1 + RIGS/signals.py | 9 ++++++++- RIGS/test_functional.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 2e82807e..1cdbcc19 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -221,3 +221,4 @@ TEMPLATE_DIRS = ( USE_GRAVATAR=True TERMS_OF_HIRE_URL = "http://www.nottinghamtec.co.uk/terms.pdf" +AUTHORISATION_NOTIFICATION_ADDRESS = 'productions@nottinghamtec.co.uk' diff --git a/RIGS/signals.py b/RIGS/signals.py index 869dbdae..deac4ce7 100644 --- a/RIGS/signals.py +++ b/RIGS/signals.py @@ -1,4 +1,5 @@ import reversion +from django.conf import settings from django.core.mail import EmailMessage from django.template.loader import get_template @@ -15,10 +16,16 @@ def send_eventauthorisation_success_email(instance): get_template("RIGS/eventauthorisation_client_success.txt").render(context), to=[instance.email] ) + + if instance.event.mic: + mic_email_address = instance.event.mic.email + else: + mic_email_address = settings.AUTHORISATION_NOTIFICATION_ADDRESS + mic_email = EmailMessage( "N%05d | %s - Event Authorised".format(instance.event.pk, instance.event.name), get_template("RIGS/eventauthorisation_mic_success.txt").render(context), - to=[instance.event.mic.email] + to=[mic_email_address] ) client_email.send() diff --git a/RIGS/test_functional.py b/RIGS/test_functional.py index 13d6871b..87452f11 100644 --- a/RIGS/test_functional.py +++ b/RIGS/test_functional.py @@ -4,6 +4,7 @@ import re from datetime import date, timedelta import reversion +from django.conf import settings from django.core import mail, signing from django.core.urlresolvers import reverse from django.db import transaction @@ -1027,3 +1028,17 @@ class ClientEventAuthorisationTest(TestCase): response = self.client.get(self.url) self.assertContains(response, 'amount has changed') + + def test_email_sent(self): + mail.outbox = [] + + data = self.auth_data + data['amount'] = self.event.total + + response = self.client.post(self.url, data) + self.assertContains(response, "Your event has been authorised.") + self.assertEqual(len(mail.outbox), 2) + + self.assertEqual(mail.outbox[0].to, ['authemail@function.test']) + self.assertEqual(mail.outbox[1].to, [settings.AUTHORISATION_NOTIFICATION_ADDRESS]) +