def test_buildFinished_mode_problem_ignores_successful_build(self):
        mn = MailNotifier('*****@*****.**', mode="problem")

        build = Mock()

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build,
                                                SUCCESS))
示例#2
0
    def test_buildFinished_mode_problem_ignores_successful_build(self):
        mn = MailNotifier('*****@*****.**', mode=("problem", ))

        build = FakeBuildStatus(name="build")

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build,
                                                SUCCESS))
示例#3
0
    def test_buildFinished_ignores_unspecified_builders(self):
        mn = MailNotifier("*****@*****.**", builders=["a", "b"])

        build = FakeBuildStatus()
        build.builder = Mock()

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, SUCCESS))
示例#4
0
    def buildFinished(self, name, build, results):

        if self.builderGroups:
            currentBuilder = build.getBuilder()
            currentBuilderName = currentBuilder.getName()
            revision = build.getSourceStamp().revision

            for builderGroup in self.builderGroups:
                if builderGroup.containsBuilder(currentBuilderName):
                    if builderGroup.currentBuild == revision:
                        if self.shouldSendMessage(name, build, results):
                            # Append to cache
                            builderGroup.cacheMessage(name, build, results)
                            if self.schedulerGroupsSendFirst:
                                if builderGroup.sent < self.schedulerGroupsSendFirst:
                                    builderGroup.sent += 1
                                    MailNotifier.buildFinished(
                                        self, name, build, results)
                        # Are there any builders left? if not send the grouped message
                        for builder in builderGroup.builderNames:
                            # The current builder will always have a building state,
                            # so do not check state if current builder
                            if builder != currentBuilderName:
                                state = self.status.getBuilder(
                                    builder).getState()[0]
                                if state == "building":  # if any are building we can return
                                    return
                        # Nothing is building - send out the aggregated message
                        if len(builderGroup.cachedMessages
                               ) == builderGroup.sent:
                            # We've already sent out all the messages in the cache
                            # so there is no need to send out the aggregated messages
                            return
                        d = self.sendAggregateMail(builderGroup.cachedMessages)
                        builderGroup.reset()
                        return d

                    elif builderGroup.currentBuild != revision:
                        # new revision - reset BuilderGroup just in case
                        builderGroup.reset()
                        builderGroup.currentBuild = revision
                        if self.shouldSendMessage(name, build, results):
                            # Append to cache
                            builderGroup.cacheMessage(name, build, results)
                            if self.schedulerGroupsSendFirst:
                                builderGroup.sent = 1
                                # send this email out
                                return MailNotifier.buildFinished(
                                    self, name, build, results)
                    break

        else:  # send message like regular MailNotifier
            # this comment copied from MailNotifier:
            # for testing purposes, buildMessage returns a Deferred that fires
            # when the mail has been sent. To help unit tests, we return that
            # Deferred here even though the normal IStatusReceiver.buildFinished
            # signature doesn't do anything with it. If that changes (if
            # .buildFinished's return value becomes significant), we need to
            # rearrange this.
            return MailNotifier.buildFinished(self, name, build, results)
    def test_buildFinished_ignores_unspecified_builders(self):
        mn = MailNotifier('*****@*****.**', builders=['a','b'])

        build = FakeBuildStatus()
        build.builder = Mock()

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#6
0
 def get_mail_notifier_statuses(self, mail_notifiers):
     statuses = []
     for mail_notifier in mail_notifiers:
         notifying_builders = mail_notifier['builders']
         extra_recipients = mail_notifier['extraRecipients']
         send_to_interested_useres = mail_notifier.get(
             'sendToInterestedUsers', False)
         subject = mail_notifier.get('subject')
         if subject:
             statuses.append(
                 MailNotifier(
                     fromaddr=self._active_master.from_address,
                     mode='problem',
                     subject=subject,
                     sendToInterestedUsers=send_to_interested_useres,
                     extraRecipients=extra_recipients,
                     lookup=master_utils.UsersAreEmails(),
                     builders=notifying_builders))
         else:
             statuses.append(
                 MailNotifier(
                     fromaddr=self._active_master.from_address,
                     mode='problem',
                     sendToInterestedUsers=send_to_interested_useres,
                     extraRecipients=extra_recipients,
                     lookup=master_utils.UsersAreEmails(),
                     builders=notifying_builders))
     return statuses
示例#7
0
    def test_buildFinished_mode_passing_ignores_failed_build(self):
        mn = MailNotifier('*****@*****.**', mode=("passing", ))

        build = FakeBuildStatus(name="build")

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build,
                                                FAILURE))
    def test_buildFinished_mode_all_always_sends_email(self, mock_method):
        mn = MailNotifier('*****@*****.**', mode="all")

        build = Mock()
        mn.buildFinished('dummyBuilder', build, FAILURE)

        mock_method.assert_called_with('dummyBuilder', build, FAILURE)
示例#9
0
    def test_buildFinished_ignores_unspecified_builders(self):
        mn = MailNotifier('*****@*****.**', builders=['a','b'])

        build = FakeBuildStatus()
        build.builder = Mock()

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#10
0
    def test_buildFinished_mode_passing_ignores_failed_build(self):
        mn = MailNotifier('*****@*****.**', mode=("passing",))

        build = FakeBuildStatus(name="build")

        self.assertEqual(
            None, mn.buildFinished('dummyBuilder', build, FAILURE))
示例#11
0
    def test_buildFinished_mode_problem_ignores_successful_build(self):
        mn = MailNotifier('*****@*****.**', mode=("problem",))

        build = FakeBuildStatus(name="build")

        self.assertEqual(
            None, mn.buildFinished('dummyBuilder', build, SUCCESS))
    def test_buildFinished_mode_passing_ignores_failed_build(self):
        mn = MailNotifier('*****@*****.**', mode="passing")

        build = Mock()

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build,
                                                FAILURE))
    def __init__(self,
                 fromaddr,
                 mode="all",
                 categories=None,
                 builders=None,
                 addLogs=False,
                 relayhost="localhost",
                 subject="buildbot %(result)s in %(builder)s",
                 lookup=None,
                 extraRecipients=[],
                 sendToInterestedUsers=True,
                 body="",
                 replytoaddr=""):
        """
        @type  body: string
        @param body: a string to be used as the body of the message.

        @type  replytoaddr: string
        @param replytoaddr: the email address to be used in the 'Reply-To' header.
        """

        self.body = body
        self.replytoaddr = replytoaddr

        # pass the rest of the parameters to our parent.
        MailNotifier.__init__(self, fromaddr, mode, categories, builders,
                              addLogs, relayhost, subject, lookup,
                              extraRecipients, sendToInterestedUsers)
    def test_buildFinished_mode_change_ignores_first_build(self):
        mn = MailNotifier('*****@*****.**', mode=("change",))

        build = FakeBuildStatus(name="build")
        build.getPreviousBuild.return_value = None

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, FAILURE))
        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#15
0
    def test_builderAdded_ignores_unspecified_tags(self):
        mn = MailNotifier('*****@*****.**', tags=['fast'])

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(['slow'])

        self.assertEqual(None, mn.builderAdded('dummyBuilder', builder))
        self.assert_(builder not in mn.watched)
示例#16
0
    def test_builderAdded_ignores_unspecified_tags(self):
        mn = MailNotifier('*****@*****.**', tags=['fast'])

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(['slow'])

        self.assertEqual(None, mn.builderAdded('dummyBuilder', builder))
        self.assert_(builder not in mn.watched)
    def test_buildFinished_mode_change_ignores_first_build(self):
        mn = MailNotifier("*****@*****.**", mode="change")

        build = Mock()
        build.getPreviousBuild.return_value = None

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, FAILURE))
        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, SUCCESS))
示例#18
0
    def test_builderAdded_ignores_unspecified_tags(self):
        mn = MailNotifier("*****@*****.**", tags=["fast"])

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(["slow"])

        self.assertEqual(None, mn.builderAdded("dummyBuilder", builder))
        self.assert_(builder not in mn.watched)
示例#19
0
    def test_buildFinished_mode_change_ignores_first_build(self):
        mn = MailNotifier('*****@*****.**', mode="change")

        build = FakeBuildStatus(name="build")
        build.getPreviousBuild.return_value = None

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, FAILURE))
        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#20
0
    def test_buildFinished_ignores_unspecified_categories(self):
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        build = FakeBuildStatus(name="build")
        build.builder = Mock()
        build.builder.category = 'slow'

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#21
0
    def test_builderAdded_ignores_unspecified_categories(self):
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        builder = Mock()
        builder.category = 'slow'

        self.assertEqual(None, mn.builderAdded('dummyBuilder', builder))
        self.assert_(builder not in mn.watched)
    def test_builderAdded_ignores_unspecified_categories(self):
        mn = MailNotifier("*****@*****.**", categories=["fast"])

        builder = Mock()
        builder.category = "slow"

        self.assertEqual(None, mn.builderAdded("dummyBuilder", builder))
        self.assert_(builder not in mn.watched)
    def test_builderAdded_ignores_unspecified_categories(self):
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        builder = Mock()
        builder.category = 'slow'

        self.assertEqual(None, mn.builderAdded('dummyBuilder', builder))
        self.assert_(builder not in mn.watched)
示例#24
0
    def test_buildFinished_ignores_unspecified_categories(self):
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        build = FakeBuildStatus(name="build")
        build.builder = Mock()
        build.builder.category = 'slow'

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#25
0
 def test_createEmail_extraHeaders_two_builds(self):
     builds = [FakeBuildStatus(name="build1"), FakeBuildStatus(name="build2")]
     msgdict = create_msgdict()
     mn = MailNotifier("*****@*****.**", extraHeaders=dict(hhh="vvv"))
     m = mn.createEmail(msgdict, u"builder-n\u00E5me", u"project-n\u00E5me", SUCCESS, builds)
     txt = m.as_string()
     # note that the headers are *not* rendered
     self.assertIn("hhh: vvv", txt)
示例#26
0
    def test_buildFinished_ignores_unspecified_categories(self):
        mn = MailNotifier("*****@*****.**", categories=["fast"])

        build = FakeBuildStatus(name="build")
        build.builder = Mock()
        build.builder.category = "slow"

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, SUCCESS))
示例#27
0
    def run_simple_test_ignores_email_for_mode(self, mode, result):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier('*****@*****.**', mode=mode)

        build = FakeBuildStatus(name="build")
        mn.buildFinished('dummyBuilder', build, result)

        self.assertFalse(mock_method.called)
示例#28
0
 def test_createEmail_message_with_nonascii_patch(self):
     builds = [FakeBuildStatus(name="build")]
     msgdict = create_msgdict()
     patches = [["", "\x99\xaa", ""]]
     logs = [FakeLog("simple log")]
     mn = MailNotifier("*****@*****.**", addLogs=True)
     m = mn.createEmail(msgdict, u"builder", u"pr", SUCCESS, builds, patches, logs)
     txt = m.as_string()
     self.assertIn("application/octet-stream", txt)
示例#29
0
 def test_createEmail_extraHeaders_one_build(self):
     builds = [FakeBuildStatus(name="build")]
     msgdict = create_msgdict()
     mn = MailNotifier('*****@*****.**', extraHeaders=dict(hhh='vvv'))
     # add some Unicode to detect encoding problems
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds)
     txt = m.as_string()
     self.assertIn('rndr(hhh): rndr(vvv)', txt)
示例#30
0
 def test_createEmail_extraHeaders_one_build(self):
     builds = [ FakeBuildStatus(name="build") ]
     msgdict = create_msgdict()
     mn = MailNotifier('*****@*****.**', extraHeaders=dict(hhh='vvv'))
     # add some Unicode to detect encoding problems
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds)
     txt = m.as_string()
     self.assertIn('rndr(hhh): rndr(vvv)', txt)
 def test_createEmail_message_without_patch_and_log_contains_unicode(self):
     msgdict = dict(body=u'Unicode body with non-ascii (åäö).',
                    type='plain')
     mn = MailNotifier('*****@*****.**')
     m = mn.createEmail(msgdict, u'builder-näme', u'project-näme', SUCCESS)
     try:
         print m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
示例#32
0
    def run_simple_test_ignores_email_for_mode(self, mode, result):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier('*****@*****.**', mode=mode)

        build = FakeBuildStatus(name="build")
        mn.buildFinished('dummyBuilder', build, result)

        self.assertFalse(mock_method.called)
示例#33
0
    def test_builderAdded_ignores_unspecified_categories(self):
        # categories are deprecated, but leave a test for it until we remove it
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(['slow'])

        self.assertEqual(None, mn.builderAdded('dummyBuilder', builder))
        self.assert_(builder not in mn.watched)
示例#34
0
    def run_simple_test_sends_email_for_mode(self, mode, result):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier("*****@*****.**", mode=mode)

        build = FakeBuildStatus(name="build")
        mn.buildFinished("dummyBuilder", build, result)

        mock_method.assert_called_with("dummyBuilder", [build], result)
示例#35
0
    def test_buildFinished_ignores_unspecified_tags(self):
        mn = MailNotifier("*****@*****.**", tags=["fast"])

        build = FakeBuildStatus(name="build")
        build.builder = fakemaster.FakeBuilderStatus(self.master)
        build.builder.setTags(["slow"])
        build.getBuilder = lambda: build.builder

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, SUCCESS))
示例#36
0
    def test_builderAdded_ignores_unspecified_categories(self):
        # categories are deprecated, but leave a test for it until we remove it
        mn = MailNotifier("*****@*****.**", categories=["fast"])

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(["slow"])

        self.assertEqual(None, mn.builderAdded("dummyBuilder", builder))
        self.assert_(builder not in mn.watched)
    def test_buildFinished_ignores_unspecified_categories(self):
        mn = MailNotifier("*****@*****.**", categories=["fast"])

        build = Mock()
        builder = Mock()
        build.getBuilder.return_value = builder
        builder.category = "slow"

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, SUCCESS))
    def test_buildFinished_mode_problem_ignores_two_failed_builds_in_sequence(self):
        mn = MailNotifier('*****@*****.**', mode=("problem",))

        build = FakeBuildStatus(name="build")
        old_build = FakeBuildStatus(name="old_build")
        build.getPreviousBuild.return_value = old_build
        old_build.getResults.return_value = FAILURE

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, FAILURE))
    def test_buildFinished_mode_all_always_sends_email(self):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier("*****@*****.**", mode="all")

        build = Mock()
        mn.buildFinished("dummyBuilder", build, FAILURE)

        mock_method.assert_called_with("dummyBuilder", build, FAILURE)
    def test_buildFinished_mode_all_always_sends_email(self):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier('*****@*****.**', mode=("failing", "passing", "warnings"))

        build = FakeBuildStatus(name="build")
        mn.buildFinished('dummyBuilder', build, FAILURE)

        mock_method.assert_called_with('dummyBuilder', [build], FAILURE)
示例#41
0
    def test_buildFinished_mode_problem_ignores_two_failed_builds_in_sequence(self):
        mn = MailNotifier('*****@*****.**', mode="problem")

        build = FakeBuildStatus(name="build")
        old_build = FakeBuildStatus(name="old_build")
        build.getPreviousBuild.return_value = old_build
        old_build.getResults.return_value = FAILURE

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, FAILURE))
    def test_buildFinished_mode_problem_ignores_two_failed_builds_in_sequence(self):
        mn = MailNotifier("*****@*****.**", mode="problem")

        build = Mock()
        old_build = Mock()
        build.getPreviousBuild.return_value = old_build
        old_build.getResults.return_value = FAILURE

        self.assertEqual(None, mn.buildFinished("dummyBuilder", build, FAILURE))
示例#43
0
    def test_buildFinished_mode_all_always_sends_email(self):
        mock_method = Mock()
        self.patch(MailNotifier, "buildMessage", mock_method)
        mn = MailNotifier('*****@*****.**', mode="all")

        build = FakeBuildStatus(name="build")
        mn.buildFinished('dummyBuilder', build, FAILURE)

        mock_method.assert_called_with('dummyBuilder', [build], FAILURE)
 def test_createEmail_message_without_patch_and_log_contains_unicode(self):
     build = Mock()
     msgdict = create_msgdict()
     mn = MailNotifier("*****@*****.**")
     m = mn.createEmail(msgdict, u"builder-n\u00E5me", u"project-n\u00E5me", SUCCESS, build)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail("Failed to call as_string() on email message.")
示例#45
0
   def buildFinished(self, name, build, results):
 
       if self.builderGroups:
           currentBuilder = build.getBuilder()
           currentBuilderName = currentBuilder.getName()
           revision = build.getSourceStamp().revision
           
           for builderGroup in self.builderGroups:
               if builderGroup.containsBuilder(currentBuilderName):
                   if builderGroup.currentBuild == revision:
                       if self.shouldSendMessage(name, build, results):
                           # Append to cache
                           builderGroup.cacheMessage(name, build, results)
                           if self.schedulerGroupsSendFirst:
                               if builderGroup.sent < self.schedulerGroupsSendFirst:
                                   builderGroup.sent += 1
                                   MailNotifier.buildFinished(self, name, build, results)
                       # Are there any builders left? if not send the grouped message
                       for builder in builderGroup.builderNames:
                           # The current builder will always have a building state,
                           # so do not check state if current builder
                           if builder != currentBuilderName:
                               state = self.status.getBuilder(builder).getState()[0]
                               if state == "building":     # if any are building we can return
                                   return
                       # Nothing is building - send out the aggregated message
                       if len(builderGroup.cachedMessages) == builderGroup.sent:
                           # We've already sent out all the messages in the cache
                           # so there is no need to send out the aggregated messages
                           return
                       d = self.sendAggregateMail(builderGroup.cachedMessages)
                       builderGroup.reset()
                       return d
                       
                   elif builderGroup.currentBuild != revision:
                       # new revision - reset BuilderGroup just in case
                       builderGroup.reset()
                       builderGroup.currentBuild = revision
                       if self.shouldSendMessage(name, build, results):
                           # Append to cache
                           builderGroup.cacheMessage(name, build, results)
                           if self.schedulerGroupsSendFirst:
                               builderGroup.sent = 1
                               # send this email out
                               return MailNotifier.buildFinished(self, name, build, results)
                   break
                   
       else:   # send message like regular MailNotifier
           # this comment copied from MailNotifier:
           # for testing purposes, buildMessage returns a Deferred that fires
           # when the mail has been sent. To help unit tests, we return that
           # Deferred here even though the normal IStatusReceiver.buildFinished
           # signature doesn't do anything with it. If that changes (if
           # .buildFinished's return value becomes significant), we need to
           # rearrange this.
           return MailNotifier.buildFinished(self, name, build, results)
 def test_createEmail_message_with_nonascii_patch(self):
     builds = [ FakeBuildStatus(name="build") ]
     msgdict = create_msgdict()
     patches = [ ['', '\x99\xaa', ''] ]
     logs = [ FakeLog('simple log') ]
     mn = MailNotifier('*****@*****.**', addLogs=True)
     m = mn.createEmail(msgdict, u'builder', u'pr', SUCCESS,
                        builds, patches, logs)
     txt = m.as_string()
     self.assertIn('application/octet-stream', txt)
示例#47
0
    def test_buildFinished_ignores_unspecified_tags(self):
        mn = MailNotifier('*****@*****.**', tags=['fast'])

        build = FakeBuildStatus(name="build")
        build.builder = fakemaster.FakeBuilderStatus(self.master)
        build.builder.setTags(['slow'])
        build.getBuilder = lambda: build.builder

        self.assertEqual(
            None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#48
0
 def test_createEmail_message_with_nonascii_patch(self):
     builds = [ FakeBuildStatus(name="build") ]
     msgdict = create_msgdict()
     patches = [ ['', '\x99\xaa', ''] ]
     logs = [ FakeLog('simple log') ]
     mn = MailNotifier('*****@*****.**', addLogs=True)
     m = mn.createEmail(msgdict, u'builder', u'pr', SUCCESS,
                        builds, patches, logs)
     txt = m.as_string()
     self.assertIn('application/octet-stream', txt)
示例#49
0
 def test_createEmail_extraHeaders_two_builds(self):
     builds = [ FakeBuildStatus(name="build1"),
                FakeBuildStatus(name="build2") ]
     msgdict = create_msgdict()
     mn = MailNotifier('*****@*****.**', extraHeaders=dict(hhh='vvv'))
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds)
     txt = m.as_string()
     # note that the headers are *not* rendered
     self.assertIn('hhh: vvv', txt)
示例#50
0
 def test_createEmail_message_without_patch_and_log_contains_unicode(self):
     builds = [ FakeBuildStatus(name="build") ]
     msgdict = create_msgdict()
     mn = MailNotifier('*****@*****.**')
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
 def test_createEmail_message_without_patch_and_log_contains_unicode(self):
     builds = [ FakeBuildStatus(name="build") ]
     msgdict = create_msgdict()
     mn = MailNotifier('*****@*****.**')
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
示例#52
0
    def test_buildFinished_ignores_unspecified_categories(self):
        mn = MailNotifier('*****@*****.**', categories=['fast'])


        build = Mock()
        builder = Mock()
        build.getBuilder.return_value = builder
        builder.category = 'slow'

        self.assertEqual(None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#53
0
    def __init__(self,
                 watch_mode,
                 interesting_steps,
                 boring_steps=None,
                 **kwargs):
        """
    @type  watch_mode: either BUILDERS or CATEGORIES
    @param watch_mode: A singleton object denoting whether this class is
                       watching steps keyed by builder name or by category.

    @type  interesting_steps: mapping of strings to lists of strings.
    @param interesting_steps: Keys are either builder names or categories;
                              values are lists of steps which we care about.
                              The key '*' (wildcard) means 'all builders'.
                              The value ['*'] (wildcard) means 'all steps'.
                              All keys (other than wildcard) must be present in
                              either |builders| or |categories| (in kwargs).
                              Required since otherwise this class has no point.

    @type  boring_steps: mapping of strings to lists of strings.
    @param boring_steps: Keys are either builder names or categories;
                         values are lists of steps which we do not care about.
                         The key '*' (wildcard) means 'all builders'.
                         The value ['*'] (wildcard) means 'all steps'.
                         All keys (other than wildcard) must be present in
                         either |builders| or |categories| (in kwargs).
                         Boring steps override interesting steps.
    """
        self.watch_mode = watch_mode
        self.interesting_steps = interesting_steps
        self.boring_steps = boring_steps or {}

        # Pass through the keys in interesting/boring steps to the appropriate list
        # in the parent class.
        if any((arg in ('builders', 'categores') for arg in kwargs)):
            raise interfaces.ParameterError(
                'Please do not specify |builders| or |categories| in StepNotifier.'
            )
        keys = set(self.interesting_steps) | set(self.boring_steps)
        keys.discard('*')
        if self.watch_mode is BUILDERS:
            kwargs['builders'] = list(keys)
        elif self.watch_mode is CATEGORIES:
            kwargs['categories'] = list(keys)
        else:
            raise interfaces.ParameterError(
                'Please specify either BUILDERS or CATEGORIES for |watch_mode|.'
            )

        self.log('Interesting steps: %s' % self.interesting_steps)
        self.log('Boring steps: %s' % self.boring_steps)
        self.log('Instantiating MailNotifier with: %s' % kwargs)

        # Don't use super because MailNotifier is an old-style class.
        MailNotifier.__init__(self, **kwargs)
 def test_createEmail_message_without_patch_and_log_contains_unicode(self):
     msgdict = dict(
         body=u'Unicode body with non-ascii (\u00E5\u00E4\u00F6).',
         type='plain')
     mn = MailNotifier('*****@*****.**')
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
示例#55
0
    def test_buildFinished_ignores_unspecified_categories(self):
        # categories are deprecated, but test them until they're removed
        mn = MailNotifier('*****@*****.**', categories=['fast'])

        build = FakeBuildStatus(name="build")
        build.builder = fakemaster.FakeBuilderStatus(self.master)
        build.builder.setTags(['slow'])
        build.getBuilder = lambda: build.builder

        self.assertEqual(
            None, mn.buildFinished('dummyBuilder', build, SUCCESS))
示例#56
0
    def test_buildsetComplete_doesnt_send_email(self):
        fakeBuildMessage = Mock()
        mn = MailNotifier('*****@*****.**',
                          buildSetSummary=True,
                          mode=("failing", "warnings"),
                          builders=["Builder"])
        mn.buildMessage = fakeBuildMessage

        def fakeGetBuild(number):
            return build

        def fakeGetBuilder(buildername):
            if buildername == builder.name:
                return builder
            return None

        def fakeGetBuildRequests(self, bsid):
            return defer.succeed([{"buildername": "Builder", "brid": 1}])

        builder = Mock()
        builder.getBuild = fakeGetBuild
        builder.name = "Builder"

        build = FakeBuildStatus()
        build.results = SUCCESS
        build.finished = True
        build.reason = "testReason"
        build.getBuilder.return_value = builder
        build.getResults.return_value = build.results

        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Buildslave(id=13, name='sl'),
            fakedb.Buildset(id=99, results=SUCCESS, reason="testReason"),
            fakedb.Builder(id=80, name='Builder'),
            fakedb.BuildRequest(id=11, buildsetid=99, builderid=80),
            fakedb.Build(number=0, buildrequestid=11, buildslaveid=13,
                         masterid=92),
        ])
        self.setupMailNotifier(mn)
        mn.master_status.getBuilder = fakeGetBuilder
        mn.buildMessageDict = Mock()
        mn.buildMessageDict.return_value = {"body": "body", "type": "text",
                                            "subject": "subject"}

        d = mn._buildsetComplete('buildset.99.complete',
                                 dict(bsid=99, result=FAILURE))

        @d.addCallback
        def check(_):
            self.assertFalse(fakeBuildMessage.called)
        return d
示例#57
0
    def test_builderAdded_subscribes_to_all_builders_by_default(self):
        mn = MailNotifier('*****@*****.**')

        builder = Mock()
        builder.category = 'slow'
        builder2 = Mock()
        builder2.category = None

        self.assertEqual(mn, mn.builderAdded('dummyBuilder', builder))
        self.assertEqual(mn, mn.builderAdded('dummyBuilder2', builder2))
        self.assertTrue(builder in mn.watched)
        self.assertTrue(builder2 in mn.watched)
示例#58
0
 def test_createEmail_message_with_patch_and_log_contains_unicode(self):
     builds = [FakeBuildStatus(name="build")]
     msgdict = create_msgdict()
     patches = [['', u'\u00E5\u00E4\u00F6', '']]
     logs = [FakeLog(u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).')]
     mn = MailNotifier('*****@*****.**', addLogs=True)
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, builds, patches, logs)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
 def test_createEmail_message_with_patch_and_log_contains_unicode(self):
     msgdict = dict(
         body=u'Unicode body with non-ascii (\u00E5\u00E4\u00F6).',
         type='plain')
     patch = ['', u'\u00E5\u00E4\u00F6', '']
     logs = [FakeLog(u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).')]
     mn = MailNotifier('*****@*****.**', addLogs=True)
     m = mn.createEmail(msgdict, u'builder-n\u00E5me', u'project-n\u00E5me',
                        SUCCESS, patch, logs)
     try:
         m.as_string()
     except UnicodeEncodeError:
         self.fail('Failed to call as_string() on email message.')
示例#60
0
    def test_builderAdded_subscribes_to_all_builders_by_default(self):
        mn = MailNotifier('*****@*****.**')

        builder = fakemaster.FakeBuilderStatus(self.master)
        builder.setTags(['slow'])

        builder2 = fakemaster.FakeBuilderStatus(self.master)
        # No tags set.

        self.assertEqual(mn, mn.builderAdded('dummyBuilder', builder))
        self.assertEqual(mn, mn.builderAdded('dummyBuilder2', builder2))
        self.assertTrue(builder in mn.watched)
        self.assertTrue(builder2 in mn.watched)