def send(self): recipients = self.recipients if not recipients: # No email is sent, but don't try to send it again self.mark_as_notified() return sender = "%s <%s>" % (settings.SITE_NAME, settings.EMAIL_FROM) subject = self.subject txt, html = self.message(self.project.html_mail, self.project.custom_email_template) if NotificationDelivery.exists(self.status, subject, txt, html): return # avoid "SMTP: 5.3.4 Message size exceeds fixed limit" _1MB = 1024 * 1024 if len(txt) > _1MB or len(html) > _1MB: logger.error( 'Notification size is greater than 1MB (%i): project %s, build %s' % (len(txt), self.project.full_name, self.build.version)) txt = 'The email got too big (> 1MB), please visit https://%s/api/builds/%i/email/?keep=7' % ( settings.BASE_URL, self.build.id) html = '<html><body>' + txt + '</body></html>' message = Message(subject, txt, sender, recipients) if self.project.html_mail: message.attach_alternative(html, "text/html") message.send() self.mark_as_notified()
def send_admin_notification(status, project): build = status.build failed_test_jobs = build.test_jobs.filter( fetched=True, failure__isnull=False, ) if not failed_test_jobs: return data = { 'project': project, 'build': build, 'build_version': build.version, 'project': project, 'test_jobs': failed_test_jobs, 'count': len(failed_test_jobs), 'settings': settings, } subject = '%(build_version)s: FAILED TEST JOBS (%(count)d) -- %(project)s' % data sender = "%s <%s>" % (settings.SITE_NAME, settings.EMAIL_FROM) recipients = [r.email for r in project.admin_subscriptions.all()] txt = render_to_string('squad/notification/failed_test_jobs.txt', data) message = EmailMultiAlternatives(subject, txt, sender, recipients) html = '' if project.html_mail: html = render_to_string('squad/notification/failed_test_jobs.html', data) message.attach_alternative(html, "text/html") if NotificationDelivery.exists(status, subject, txt, html): return message.send()
def send_admin_notification(status, project): build = status.build failed_test_jobs = build.test_jobs.filter( fetched=True, failure__isnull=False, ) if not failed_test_jobs: return data = { 'project': project, 'build': build, 'build_version': build.version, 'project': project, 'test_jobs': failed_test_jobs, 'count': len(failed_test_jobs), 'settings': settings, } subject = '%(build_version)s: FAILED TEST JOBS (%(count)d) -- %(project)s' % data sender = "%s <%s>" % (settings.SITE_NAME, settings.EMAIL_FROM) recipients = [r.email for r in project.admin_subscriptions.all()] txt = render_to_string('squad/notification/failed_test_jobs.txt.jinja2', data) message = Message(subject, txt, sender, recipients) html = '' if project.html_mail: html = render_to_string('squad/notification/failed_test_jobs.html.jinja2', data) message.attach_alternative(html, "text/html") if NotificationDelivery.exists(status, subject, txt, html): return message.send()
def send(self): recipients = self.recipients if not recipients: return sender = "%s <%s>" % (settings.SITE_NAME, settings.EMAIL_FROM) subject = self.subject txt, html = self.message(self.project.html_mail, self.project.custom_email_template) if NotificationDelivery.exists(self.status, subject, txt, html): return message = Message(subject, txt, sender, recipients) if self.project.html_mail: message.attach_alternative(html, "text/html") message.send() self.mark_as_notified()
def test_pass_modified_notifications(self): args = [self.status, 'my subject', 'text', 'html'] self.assertFalse(NotificationDelivery.exists(*args)) args[2] = 'new text' args[3] = 'new html' self.assertFalse(NotificationDelivery.exists(*args))
def test_avoid_duplicates(self): args = [self.status, 'my subject', 'text', 'html'] self.assertFalse(NotificationDelivery.exists(*args)) self.assertTrue(NotificationDelivery.exists(*args))