예제 #1
0
파일: notification.py 프로젝트: chaws/squad
    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()
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
    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()
예제 #5
0
    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()
예제 #6
0
 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))
예제 #7
0
 def test_avoid_duplicates(self):
     args = [self.status, 'my subject', 'text', 'html']
     self.assertFalse(NotificationDelivery.exists(*args))
     self.assertTrue(NotificationDelivery.exists(*args))
예제 #8
0
 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))
예제 #9
0
 def test_avoid_duplicates(self):
     args = [self.status, 'my subject', 'text', 'html']
     self.assertFalse(NotificationDelivery.exists(*args))
     self.assertTrue(NotificationDelivery.exists(*args))