Example #1
0
 def test_BugTaskCommandGroup_add(self):
     # BugEmailCommands can be added to the group.
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup()
     group.add(command_1)
     group.add(command_2)
     self.assertEqual([command_1, command_2], group._commands)
 def test_BugTaskCommandGroup_add(self):
     # BugEmailCommands can be added to the group.
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup()
     group.add(command_1)
     group.add(command_2)
     self.assertEqual([command_1, command_2], group._commands)
Example #3
0
 def test_BugTaskCommandGroup__str__(self):
     # The str of a BugTaskCommandGroup is the ideal order of the
     # text commands in the email.
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup()
     group.add(command_1)
     group.add(command_2)
     self.assertEqual('affects fnord\nstatus triaged', str(group))
Example #4
0
 def getCommands(self, signed_msg):
     """Returns a list of all the commands found in the email."""
     content = get_main_body(signed_msg)
     if content is None:
         return []
     return [
         BugEmailCommands.get(name=name, string_args=args) for
         name, args in parse_commands(
             content, BugEmailCommands.parsingParameters())]
 def test_BugTaskCommandGroup__str__(self):
     # The str of a BugTaskCommandGroup is the ideal order of the
     # text commands in the email.
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup()
     group.add(command_1)
     group.add(command_2)
     self.assertEqual(
         'affects fnord\nstatus triaged', str(group))
Example #6
0
 def test_BugCommandGroup__str__(self):
     # The str of a BugCommandGroup is the ideal order of the
     # text commands in the email.
     bug_group = BugCommandGroup(BugEmailCommands.get('private', ['true']))
     bug_group.add(BugEmailCommands.get('security', ['false']))
     bugtask_group = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     bug_group.add(bugtask_group)
     self.assertEqual('security false\nprivate true\naffects fnord',
                      str(bug_group))
Example #7
0
 def getCommands(self, signed_msg):
     """Returns a list of all the commands found in the email."""
     content = get_main_body(signed_msg)
     if content is None:
         return []
     return [
         BugEmailCommands.get(name=name, string_args=args)
         for name, args in parse_commands(
             content, BugEmailCommands.parsingParameters())
     ]
 def test_BugCommandGroup__str__(self):
     # The str of a BugCommandGroup is the ideal order of the
     # text commands in the email.
     bug_group = BugCommandGroup(
         BugEmailCommands.get('private', ['true']))
     bug_group.add(
         BugEmailCommands.get('security', ['false']))
     bugtask_group = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     bug_group.add(bugtask_group)
     self.assertEqual(
         'security false\nprivate true\naffects fnord', str(bug_group))
Example #9
0
    def extractAndAuthenticateCommands(self, signed_msg, to_addr):
        """Extract commands and handle special destinations.

        NB: The authentication is carried out against the current principal,
        not directly against the message.  authenticateEmail must previously
        have been called on this thread.

        :returns: (final_result, add_comment_to_bug, commands)
            If final_result is non-none, stop processing and return this value
            to indicate whether the message was dealt with or not.
            If add_comment_to_bug, add the contents to the first bug
            selected.
            commands is a list of bug commands.
        """
        CONTEXT = 'bug report'
        commands = self.getCommands(signed_msg)
        to_user, to_host = to_addr.split('@')
        add_comment_to_bug = False
        from_user = getUtility(ILaunchBag).user
        if to_user.lower() == 'help' or from_user is None:
            if from_user is not None and from_user.preferredemail is not None:
                to_address = str(from_user.preferredemail.email)
            else:
                to_address = signed_msg['From']
                address = getUtility(IEmailAddressSet).getByEmail(to_address)
                if address is None:
                    to_address = None
            if to_address is not None:
                self.sendHelpEmail(to_address)
            return True, False, None
        # If there are any commands, we must have strong authentication.
        # We send a different failure message for attempts to create a new
        # bug.
        elif to_user.lower() == 'new':
            ensure_not_weakly_authenticated(signed_msg, CONTEXT)
        elif len(commands) > 0:
            ensure_not_weakly_authenticated(signed_msg, CONTEXT)
        if to_user.lower() == 'new':
            commands.insert(0, BugEmailCommands.get('bug', ['new']))
        elif to_user.isdigit():
            # A comment to a bug. We set add_comment_to_bug to True so
            # that the comment gets added to the bug later. We don't add
            # the comment now, since we want to let the 'bug' command
            # handle the possible errors that can occur while getting
            # the bug.
            add_comment_to_bug = True
            commands.insert(0, BugEmailCommands.get('bug', [to_user]))
        elif to_user.lower() != 'edit':
            # Indicate that we didn't handle the mail.
            return False, False, None
        bug_commands = list(BugCommandGroups(commands))
        return None, add_comment_to_bug, bug_commands
Example #10
0
    def extractAndAuthenticateCommands(self, signed_msg, to_addr):
        """Extract commands and handle special destinations.

        NB: The authentication is carried out against the current principal,
        not directly against the message.  authenticateEmail must previously
        have been called on this thread.

        :returns: (final_result, add_comment_to_bug, commands)
            If final_result is non-none, stop processing and return this value
            to indicate whether the message was dealt with or not.
            If add_comment_to_bug, add the contents to the first bug
            selected.
            commands is a list of bug commands.
        """
        CONTEXT = 'bug report'
        commands = self.getCommands(signed_msg)
        to_user, to_host = to_addr.split('@')
        add_comment_to_bug = False
        from_user = getUtility(ILaunchBag).user
        if to_user.lower() == 'help' or from_user is None:
            if from_user is not None and from_user.preferredemail is not None:
                to_address = str(from_user.preferredemail.email)
            else:
                to_address = signed_msg['From']
                address = getUtility(IEmailAddressSet).getByEmail(to_address)
                if address is None:
                    to_address = None
            if to_address is not None:
                self.sendHelpEmail(to_address)
            return True, False, None
        # If there are any commands, we must have strong authentication.
        # We send a different failure message for attempts to create a new
        # bug.
        elif to_user.lower() == 'new':
            ensure_not_weakly_authenticated(signed_msg, CONTEXT)
        elif len(commands) > 0:
            ensure_not_weakly_authenticated(signed_msg, CONTEXT)
        if to_user.lower() == 'new':
            commands.insert(0, BugEmailCommands.get('bug', ['new']))
        elif to_user.isdigit():
            # A comment to a bug. We set add_comment_to_bug to True so
            # that the comment gets added to the bug later. We don't add
            # the comment now, since we want to let the 'bug' command
            # handle the possible errors that can occur while getting
            # the bug.
            add_comment_to_bug = True
            commands.insert(0, BugEmailCommands.get('bug', [to_user]))
        elif to_user.lower() != 'edit':
            # Indicate that we didn't handle the mail.
            return False, False, None
        bug_commands = list(BugCommandGroups(commands))
        return None, add_comment_to_bug, bug_commands
Example #11
0
 def test_BugTaskCommandGroup_sorted_commands(self):
     # Commands are sorted by the Command's Rank.
     command_3 = BugEmailCommands.get('importance', ['low'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     group = BugTaskCommandGroup()
     group.add(command_3)
     group.add(command_2)
     group.add(command_1)
     self.assertEqual(0, command_1.RANK)
     self.assertEqual(4, command_2.RANK)
     self.assertEqual(5, command_3.RANK)
     self.assertEqual([command_1, command_2, command_3], group.commands)
 def test_BugCommandGroup_groups(self):
     # The groups property returns a copy _groups list in the order that
     # that they were added.
     bugtask_group_1 = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     group = BugCommandGroup()
     group.add(bugtask_group_1)
     bugtask_group_2 = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['pting']))
     group.add(bugtask_group_2)
     self.assertEqual(group._groups, group.groups)
     self.assertFalse(group._groups is group.groups)
     self.assertEqual([bugtask_group_1, bugtask_group_2], group.groups)
Example #13
0
 def test_BugCommandGroup_groups(self):
     # The groups property returns a copy _groups list in the order that
     # that they were added.
     bugtask_group_1 = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     group = BugCommandGroup()
     group.add(bugtask_group_1)
     bugtask_group_2 = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['pting']))
     group.add(bugtask_group_2)
     self.assertEqual(group._groups, group.groups)
     self.assertFalse(group._groups is group.groups)
     self.assertEqual([bugtask_group_1, bugtask_group_2], group.groups)
 def test_BugTaskCommandGroup_sorted_commands(self):
     # Commands are sorted by the Command's Rank.
     command_3 = BugEmailCommands.get('importance', ['low'])
     command_2 = BugEmailCommands.get('status', ['triaged'])
     command_1 = BugEmailCommands.get('affects', ['fnord'])
     group = BugTaskCommandGroup()
     group.add(command_3)
     group.add(command_2)
     group.add(command_1)
     self.assertEqual(0, command_1.RANK)
     self.assertEqual(4, command_2.RANK)
     self.assertEqual(5, command_3.RANK)
     self.assertEqual(
         [command_1, command_2, command_3], group.commands)
Example #15
0
 def test_BugCommandGroup_groups_new_bug_with_fixable_affects(self):
     # A new bug that affects only one target does not require the
     # affects command to be first.
     group = BugCommandGroup(BugEmailCommands.get('bug', ['new']))
     status_command = BugEmailCommands.get('status', ['triaged'])
     bugtask_group_1 = BugTaskCommandGroup(status_command)
     group.add(bugtask_group_1)
     affects_command = BugEmailCommands.get('affects', ['fnord'])
     bugtask_group_2 = BugTaskCommandGroup(affects_command)
     group.add(bugtask_group_2)
     self.assertEqual(1, len(group.groups))
     self.assertIsNot(group._groups, group.groups,
                      "List reference returned instead of copy.")
     self.assertEqual([affects_command, status_command],
                      group.groups[0].commands)
Example #16
0
 def test_BugCommandGroups__init__one_bug_many_bugtask(self):
     # Commands can operate on one bug and one bugtask.
     email_commands = [
         ('bug', 'new'),
         ('affects', 'fnord'),
         ('importance', 'high'),
         ('private', 'true'),
         ('affects', 'pting'),
         ('importance', 'low'),
     ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands
     ]
     ordered_commands = BugCommandGroups(commands)
     expected = '\n'.join([
         'bug new',
         'private true',
         'affects fnord',
         'importance high',
         'affects pting',
         'importance low',
     ])
     self.assertEqual(1, len(ordered_commands.groups))
     self.assertEqual(2, len(ordered_commands.groups[0].commands))
     self.assertEqual(2, len(ordered_commands.groups[0].groups))
     self.assertEqual(2, len(ordered_commands.groups[0].groups[0].commands))
     self.assertEqual(2, len(ordered_commands.groups[0].groups[1].commands))
     self.assertEqual(expected, str(ordered_commands))
 def test_BugCommandGroups__iter_(self):
     email_commands = [
         ('bug', '1234'),
         ('importance', 'high'),
         ('private', 'yes'),
         ('bug', 'new'),
         ('security', 'yes'),
         ('status', 'triaged'),
         ('affects', 'fnord'),
         ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands]
     ordered_commands = list(BugCommandGroups(commands))
     expected = [
         'bug 1234',
         'private yes',
         'importance high',
         'bug new',
         'security yes',
         'affects fnord',
         'status triaged',
         ]
     self.assertEqual(
         expected, [str(command) for command in ordered_commands])
 def test_BugCommandGroups__init__one_bug_many_bugtask(self):
     # Commands can operate on one bug and one bugtask.
     email_commands = [
         ('bug', 'new'),
         ('affects', 'fnord'),
         ('importance', 'high'),
         ('private', 'true'),
         ('affects', 'pting'),
         ('importance', 'low'),
         ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands]
     ordered_commands = BugCommandGroups(commands)
     expected = '\n'.join([
         'bug new',
         'private true',
         'affects fnord',
         'importance high',
         'affects pting',
         'importance low',
         ])
     self.assertEqual(1, len(ordered_commands.groups))
     self.assertEqual(2, len(ordered_commands.groups[0].commands))
     self.assertEqual(2, len(ordered_commands.groups[0].groups))
     self.assertEqual(
         2, len(ordered_commands.groups[0].groups[0].commands))
     self.assertEqual(
         2, len(ordered_commands.groups[0].groups[1].commands))
     self.assertEqual(expected, str(ordered_commands))
 def test_BugCommandGroups_add_bug_email_command(self):
     # BugEmailCommands are ignored.
     group = BugCommandGroups([])
     group.add(
         BugEmailCommands.get('private', ['true']))
     self.assertEqual([], group._commands)
     self.assertEqual([], group._groups)
 def test_BugCommandGroup__nonzero__true_commands(self):
     # A BugCommandGroup is not zero is it has a command.
     group = BugCommandGroup(
         BugEmailCommands.get('private', ['true']))
     self.assertEqual(1, len(group._commands))
     self.assertEqual(0, len(group._groups))
     self.assertTrue(bool(group))
 def test_BugCommandGroup_add_command(self):
     # A BugEmailCommand can be added to a BugCommandGroup.
     command = BugEmailCommands.get('private', ['true'])
     group = BugCommandGroup()
     group.add(command)
     self.assertEqual([], group._groups)
     self.assertEqual([command], group._commands)
Example #22
0
 def test_BugCommandGroup_add_bug_non_empty_group(self):
     # Non-empty BugCommandGroups are added.
     group = BugCommandGroups([])
     bug_group = BugCommandGroup(BugEmailCommands.get('private', ['true']))
     group.add(bug_group)
     self.assertEqual([], group._commands)
     self.assertEqual([bug_group], group._groups)
Example #23
0
 def test_BugCommandGroups__iter_(self):
     email_commands = [
         ('bug', '1234'),
         ('importance', 'high'),
         ('private', 'yes'),
         ('bug', 'new'),
         ('security', 'yes'),
         ('status', 'triaged'),
         ('affects', 'fnord'),
     ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands
     ]
     ordered_commands = list(BugCommandGroups(commands))
     expected = [
         'bug 1234',
         'private yes',
         'importance high',
         'bug new',
         'security yes',
         'affects fnord',
         'status triaged',
     ]
     self.assertEqual(expected,
                      [str(command) for command in ordered_commands])
Example #24
0
 def test_BugCommandGroup_add_command(self):
     # A BugEmailCommand can be added to a BugCommandGroup.
     command = BugEmailCommands.get('private', ['true'])
     group = BugCommandGroup()
     group.add(command)
     self.assertEqual([], group._groups)
     self.assertEqual([command], group._commands)
Example #25
0
 def test_BugCommandGroups_init_many_bugs(self):
     # Commands can operate on many bugs.
     email_commands = [
         ('bug', '1234'),
         ('importance', 'high'),
         ('bug', '5678'),
         ('importance', 'low'),
         ('bug', '4321'),
         ('importance', 'medium'),
     ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands
     ]
     ordered_commands = BugCommandGroups(commands)
     expected = '\n'.join([
         'bug 1234',
         'importance high',
         'bug 5678',
         'importance low',
         'bug 4321',
         'importance medium',
     ])
     self.assertEqual(3, len(ordered_commands.groups))
     self.assertEqual(expected, str(ordered_commands))
 def test_BugCommandGroup__nonzero__true_groups(self):
     # A BugCommandGroup is not zero is it has a group.
     group = BugCommandGroup()
     group.add(BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord'])))
     self.assertEqual(0, len(group._commands))
     self.assertEqual(1, len(group._groups))
     self.assertTrue(bool(group))
Example #27
0
 def test_BugCommandGroup__nonzero__true_groups(self):
     # A BugCommandGroup is not zero is it has a group.
     group = BugCommandGroup()
     group.add(
         BugTaskCommandGroup(BugEmailCommands.get('affects', ['fnord'])))
     self.assertEqual(0, len(group._commands))
     self.assertEqual(1, len(group._groups))
     self.assertTrue(bool(group))
 def test_BugCommandGroup_add_bugtask_non_empty_group(self):
     # Non-empty BugTaskCommandGroups are added.
     bugtask_group = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     group = BugCommandGroup()
     group.add(bugtask_group)
     self.assertEqual([], group._commands)
     self.assertEqual([bugtask_group], group._groups)
 def test_BugCommandGroup_add_bug_non_empty_group(self):
     # Non-empty BugCommandGroups are added.
     group = BugCommandGroups([])
     bug_group = BugCommandGroup(
         BugEmailCommands.get('private', ['true']))
     group.add(bug_group)
     self.assertEqual([], group._commands)
     self.assertEqual([bug_group], group._groups)
Example #30
0
 def test_BugCommandGroup_add_bugtask_non_empty_group(self):
     # Non-empty BugTaskCommandGroups are added.
     bugtask_group = BugTaskCommandGroup(
         BugEmailCommands.get('affects', ['fnord']))
     group = BugCommandGroup()
     group.add(bugtask_group)
     self.assertEqual([], group._commands)
     self.assertEqual([bugtask_group], group._groups)
 def test_BugCommandGroup_groups_new_bug_with_fixable_affects(self):
     # A new bug that affects only one target does not require the
     # affects command to be first.
     group = BugCommandGroup(
         BugEmailCommands.get('bug', ['new']))
     status_command = BugEmailCommands.get('status', ['triaged'])
     bugtask_group_1 = BugTaskCommandGroup(status_command)
     group.add(bugtask_group_1)
     affects_command = BugEmailCommands.get('affects', ['fnord'])
     bugtask_group_2 = BugTaskCommandGroup(affects_command)
     group.add(bugtask_group_2)
     self.assertEqual(1, len(group.groups))
     self.assertIsNot(
         group._groups, group.groups,
         "List reference returned instead of copy.")
     self.assertEqual(
         [affects_command, status_command], group.groups[0].commands)
 def test_BugCommandGroups__init__one_bug_no_bugtasks(self):
     # Commands can operate on one bug.
     email_commands = [
         ('bug', '1234'),
         ('private', 'true'),
         ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands]
     ordered_commands = BugCommandGroups(commands)
     expected = '\n'.join([
         'bug 1234',
         'private true',
         ])
     self.assertEqual(1, len(ordered_commands.groups))
     self.assertEqual(2, len(ordered_commands.groups[0].commands))
     self.assertEqual(0, len(ordered_commands.groups[0].groups))
     self.assertEqual(expected, str(ordered_commands))
 def test_BugCommandGroups_init_many_bugs(self):
     # Commands can operate on many bugs.
     email_commands = [
         ('bug', '1234'),
         ('importance', 'high'),
         ('bug', '5678'),
         ('importance', 'low'),
         ('bug', '4321'),
         ('importance', 'medium'),
         ]
     commands = [
         BugEmailCommands.get(name=name, string_args=[args])
         for name, args in email_commands]
     ordered_commands = BugCommandGroups(commands)
     expected = '\n'.join([
         'bug 1234',
         'importance high',
         'bug 5678',
         'importance low',
         'bug 4321',
         'importance medium',
         ])
     self.assertEqual(3, len(ordered_commands.groups))
     self.assertEqual(expected, str(ordered_commands))
 def test_BugCommandGroup_init_with_command(self):
     # A BugCommandGroup can be inited with a BugEmailCommand.
     command = BugEmailCommands.get('private', ['true'])
     group = BugCommandGroup(command)
     self.assertEqual([command], group._commands)
     self.assertEqual([], group._groups)
Example #35
0
 def test_BugTaskCommandGroup_init_with_command(self):
     # BugTaskCommandGroup can be inited with a BugEmailCommands.
     command = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup(command)
     self.assertEqual([command], group._commands)
 def test_BugTaskCommandGroup_init_with_command(self):
     # BugTaskCommandGroup can be inited with a BugEmailCommands.
     command = BugEmailCommands.get('status', ['triaged'])
     group = BugTaskCommandGroup(command)
     self.assertEqual([command], group._commands)
Example #37
0
 def test_BugCommandGroup_init_with_command(self):
     # A BugCommandGroup can be inited with a BugEmailCommand.
     command = BugEmailCommands.get('private', ['true'])
     group = BugCommandGroup(command)
     self.assertEqual([command], group._commands)
     self.assertEqual([], group._groups)