From 08bdef5e71ebc8682e1a8d289498c8cd02486a41 Mon Sep 17 00:00:00 2001 From: Sandro Lutz Date: Sun, 17 Dec 2023 20:04:32 +0100 Subject: [PATCH] Fix accepted mail sending when present in eventsignups POST (#416) * Fix accepted mail sending when present in eventsignups POST * Move test to test_emails.py * Remove hook for notify_signup_accepted_on_inserted * Add comments to email test to clarify its intention --- amivapi/tests/events/test_emails.py | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/amivapi/tests/events/test_emails.py b/amivapi/tests/events/test_emails.py index 33762172..a476e745 100644 --- a/amivapi/tests/events/test_emails.py +++ b/amivapi/tests/events/test_emails.py @@ -231,6 +231,53 @@ def test_no_nones_in_emails(self): for field in mail.values(): self.assertTrue('None' not in field) + def test_signup_added_by_admin_accepted_emails(self): + """Test that an accepted email is sent when an admin has added a + signup manually.""" + event = self.new_object('events', spots=1, selection_strategy='fcfs', + allow_email_signup=True) + + user = self.new_object('users') + + self.api.post('/eventsignups', data={ + 'user': str(user['_id']), + 'event': str(event['_id']), + 'accepted': True + }, token=self.get_root_token(), status_code=201).json + + mail = self.app.test_mails[0] + for field in mail.values(): + # We check whether any field in the email structure contains the + # string 'None' as this is the string representation of the None + # value. This happens when a value inserted into the template + # string was (unexpectedly) None. + self.assertTrue('None' not in field) + + self.assertTrue('accepted' in mail['subject']) + + self.api.post('/eventsignups', data={ + 'email': 'a@example.com', + 'event': str(event['_id']), + 'accepted': True + }, token=self.get_root_token(), status_code=201).json + + # accepted email and confirmation email should be sent. + self.assertIs(len(self.app.test_mails), 3) + for mail in self.app.test_mails[1:]: + for field in mail.values(): + # We check whether any field in the email structure contains the + # string 'None' as this is the string representation of the None + # value. This happens when a value inserted into the template + # string was (unexpectedly) None. + self.assertTrue('None' not in field) + + # We expect that the accepted email and the email to confirm the + # email address were sent. + # We check some unique phrases distinct to each of these messages. + self.assertTrue( + ('accepted' in mail['subject']) != + ('confirm_email' in mail['text'])) + def test_calendar_invite_format(self): """Test that the calendar invite format. Specifically looks for the correct line format and the presence of