def test_staff_new_admin_mail(self): mail = Mail(self.app) with mail.record_messages() as outbox: self.create_staff() self.assertEqual(1, len(outbox)) with mail.record_messages() as outbox: self.create_staff({'is_admin': '1'}) self.assertEqual(len(outbox), 1)
def test_participant_reg_mail_to_admin_category(self): """Certify 'Participation category' is shown as string not as dict key""" mail = Mail(self.app) with mail.record_messages() as outbox: data = dict(self.PERSON_DATA) data.pop('personal_fee', None) self.client.post('/meeting/1/participant/form', data=data) import xml.dom.minidom from xml.parsers.expat import ExpatError for message in outbox: try: dom = xml.dom.minidom.parseString(message.html) matching_rows = [item.parentNode for item in dom.getElementsByTagName('th') if item.firstChild.data == 'Participation category'] if matching_rows: category_value = matching_rows[0].childNodes[3].firstChild.nodeValue.strip() if str(category_value) == 'Member': break except ExpatError: continue else: self.fail('Participant category is not displayed correctly!')
def test_send_mail(self): from flaskext.mail import Mail from flaskext.mail.signals import email_dispatched self._create_participant(u"10") # 10: "Member" mail = Mail(self.app) with mail.record_messages() as outbox: resp = self.client.post("/meeting/1/participant/1/send_mail", data=dict( to="*****@*****.**", subject="SC61 registration -- Acknowledgment", message="Hello world" )) self.assertEqual(len(outbox), 1) self.assertEqual(outbox[0].subject, "SC61 registration -- Acknowledgment") self.assertEqual(outbox[0].recipients, ["*****@*****.**"]) self.assertEqual(outbox[0].body, u"Hello world") self.assertEqual(outbox[0].sender, "*****@*****.**") self.assertEqual(outbox[0].attachments[0].content_type, "application/pdf") self.assertEqual(outbox[0].attachments[0].filename, "credentials.pdf")
def test_participant_registration_form_confirmation_mail(self): mail = Mail(self.app) with mail.record_messages() as outbox: data = dict(self.PERSON_DATA) data.pop('personal_fee', None) resp = self.client.post('/meeting/1/participant/form', data=data) for message in outbox: if message.recipients == [data['personal_email']]: break else: self.fail("No message was sent to participant.") self.assertEqual('*****@*****.**', message.sender) self.assertIn(self.MEETING_FORM_DATA['info_description_E'], message.subject) self.assertIn('Thank you for registering on line', message.html)
def test_participant_registration_form_mail_to_admin(self): mail = Mail(self.app) with mail.record_messages() as outbox: data = dict(self.PERSON_DATA) data.pop('personal_fee', None) resp = self.client.post('/meeting/1/participant/form', data=data) for message in outbox: if message.recipients == ['*****@*****.**']: break else: self.fail('No message was sent to meeting admin.') ok_subject = '%s registration for %s.%s %s' % ( 'Some meeting For the Test', self.PERSON_DATA['personal_name_title'], self.PERSON_DATA['personal_first_name'], self.PERSON_DATA['personal_last_name']) self.assertEqual(message.subject, ok_subject) self.assertEqual(message.sender, '*****@*****.**')