예제 #1
0
 def test_execute_bug_params_distribution(self):
     user = self.factory.makePerson()
     login_person(user)
     distribution = self.factory.makeDistribution(name='fnord')
     message = self.factory.makeMessage(
         subject='bug title', content='borked\n affects fnord')
     command = AffectsEmailCommand('affects', ['fnord'])
     bug_params = CreateBugParams(
         title='bug title', msg=message, owner=user)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(distribution, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #2
0
 def test_execute_bug_params_distribution(self):
     user = self.factory.makePerson()
     login_person(user)
     distribution = self.factory.makeDistribution(name='fnord')
     message = self.factory.makeMessage(subject='bug title',
                                        content='borked\n affects fnord')
     command = AffectsEmailCommand('affects', ['fnord'])
     bug_params = CreateBugParams(title='bug title',
                                  msg=message,
                                  owner=user)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(distribution, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #3
0
 def test_execute_bug_params_productseries(self):
     product = self.factory.makeProduct(name='fnord')
     login_person(product.owner)
     series = self.factory.makeProductSeries(name='pting', product=product)
     message = self.factory.makeMessage(
         subject='bug title', content='borked\n affects fnord/pting')
     command = AffectsEmailCommand('affects', ['fnord/pting'])
     bug_params = CreateBugParams(
         title='bug title', msg=message, owner=product.owner)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(series, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertEqual(2, len(bugtask.bug.bugtasks))
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #4
0
 def test_execute_bug_params_productseries(self):
     product = self.factory.makeProduct(name='fnord')
     login_person(product.owner)
     series = self.factory.makeProductSeries(name='pting', product=product)
     message = self.factory.makeMessage(
         subject='bug title', content='borked\n affects fnord/pting')
     command = AffectsEmailCommand('affects', ['fnord/pting'])
     bug_params = CreateBugParams(title='bug title',
                                  msg=message,
                                  owner=product.owner)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(series, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertEqual(2, len(bugtask.bug.bugtasks))
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #5
0
 def test_execute_bug_params_distroseries_sourcepackage(self):
     distribution = self.factory.makeDistribution(name='fnord')
     login_person(distribution.owner)
     series = self.factory.makeDistroSeries(
         name='pting', distribution=distribution)
     package = self.factory.makeSourcePackage(
         sourcepackagename='snarf', distroseries=series, publish=True)
     message = self.factory.makeMessage(
         subject='bug title', content='borked\n affects fnord/pting/snarf')
     command = AffectsEmailCommand('affects', ['fnord/pting/snarf'])
     bug_params = CreateBugParams(
         title='bug title', msg=message, owner=distribution.owner)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(package, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertEqual(2, len(bugtask.bug.bugtasks))
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #6
0
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     product = self.factory.makeProduct(name='fnord')
     login_person(bug.bugtasks[0].target.owner)
     command = AffectsEmailCommand('affects', ['fnord'])
     bugtask, bugtask_event, bug_event = command.execute(bug, None)
     self.assertEqual(bug, bugtask.bug)
     self.assertEqual(product, bugtask.target)
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertEqual(None, bug_event)
예제 #7
0
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     product = self.factory.makeProduct(name='fnord')
     login_person(bug.bugtasks[0].target.owner)
     command = AffectsEmailCommand('affects', ['fnord'])
     bugtask, bugtask_event, bug_event = command.execute(bug, None)
     self.assertEqual(bug, bugtask.bug)
     self.assertEqual(product, bugtask.target)
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertEqual(None, bug_event)
예제 #8
0
 def test_execute_bug_params_distroseries_sourcepackage(self):
     distribution = self.factory.makeDistribution(name='fnord')
     login_person(distribution.owner)
     series = self.factory.makeDistroSeries(name='pting',
                                            distribution=distribution)
     package = self.factory.makeSourcePackage(sourcepackagename='snarf',
                                              distroseries=series,
                                              publish=True)
     message = self.factory.makeMessage(
         subject='bug title', content='borked\n affects fnord/pting/snarf')
     command = AffectsEmailCommand('affects', ['fnord/pting/snarf'])
     bug_params = CreateBugParams(title='bug title',
                                  msg=message,
                                  owner=distribution.owner)
     bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
     self.assertEqual(package, bugtask.target)
     self.assertEqual('bug title', bugtask.bug.title)
     self.assertEqual(2, len(bugtask.bug.bugtasks))
     self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
     self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
예제 #9
0
    def execute(self, context, current_event):
        """See `IEmailCommand`.

        Much of this method was lifted from
        `EditEmailCommand.execute`.
        """
        # Parse args.
        self._ensureNumberOfArguments()
        [security_flag] = self.string_args
        if security_flag == 'yes':
            security_related = True
        elif security_flag == 'no':
            security_related = False
        else:
            raise EmailProcessingError(
                get_error_message(
                    'security-parameter-mismatch.txt',
                    error_templates=error_templates),
                stop_processing=True)

        if isinstance(context, CreateBugParams):
            if security_related:
                context.information_type = InformationType.PRIVATESECURITY
            return context, current_event

        # Take a snapshot.
        edited = False
        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(
                context, providing=providedBy(context))

        # Apply requested changes.
        user = getUtility(ILaunchBag).user
        if security_related:
            if context.setPrivate(True, user):
                edited = True
                edited_fields.add('private')
        if context.security_related != security_related:
            context.setSecurityRelated(security_related, user)
            edited = True
            edited_fields.add('security_related')

        # Update the current event.
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            current_event = ObjectModifiedEvent(
                context, context_snapshot, list(edited_fields))

        return context, current_event
    def checkTransitionEvents(self, message, edited_fields, status_name):
        """Helper method to validate the events triggered from the transition.

        Check that an IObjectCreatedEvent event was sent when the message
        was created and that an IObjectModifiedEvent was also sent.
        The event object and edited_fields attribute are checked.
        """
        def failure_msg(msg):
            return "From status %s: %s" % (status_name, msg)

        self.assertTrue(
            len(self.collected_events) >= 1,
            failure_msg('failed to trigger an IObjectCreatedEvent'))
        created_event = self.collected_events[0]
        created_event_user = IPerson(created_event.user)
        self.assertTrue(
            IObjectCreatedEvent.providedBy(created_event),
            failure_msg("%s doesn't provide IObjectCreatedEvent" %
                        created_event))
        self.assertTrue(
            created_event.object == message,
            failure_msg("IObjectCreatedEvent contains wrong message"))
        self.assertTrue(
            created_event_user == message.owner,
            failure_msg(
                "%s != %s" %
                (created_event_user.displayname, message.owner.displayname)))

        self.assertTrue(
            len(self.collected_events) == 2,
            failure_msg('failed to trigger an IObjectModifiedEvent'))
        modified_event = self.collected_events[1]
        modified_event_user = IPerson(modified_event.user)
        self.assertTrue(
            IObjectModifiedEvent.providedBy(modified_event),
            failure_msg("%s doesn't provide IObjectModifiedEvent" %
                        modified_event))
        self.assertTrue(
            modified_event.object == self.question,
            failure_msg("IObjectModifiedEvent contains wrong question"))
        self.assertTrue(
            modified_event_user == message.owner,
            failure_msg(
                "%s != %s" %
                (modified_event_user.displayname, message.owner.displayname)))
        if edited_fields:
            self.assertTrue(
                set(modified_event.edited_fields) == set(edited_fields),
                failure_msg(
                    "%s != %s" %
                    (set(modified_event.edited_fields), set(edited_fields))))
    def checkTransitionEvents(self, message, edited_fields, status_name):
        """Helper method to validate the events triggered from the transition.

        Check that an IObjectCreatedEvent event was sent when the message
        was created and that an IObjectModifiedEvent was also sent.
        The event object and edited_fields attribute are checked.
        """

        def failure_msg(msg):
            return "From status %s: %s" % (status_name, msg)

        self.failUnless(
            len(self.collected_events) >= 1,
            failure_msg('failed to trigger an IObjectCreatedEvent'))
        created_event = self.collected_events[0]
        created_event_user = IPerson(created_event.user)
        self.failUnless(
            IObjectCreatedEvent.providedBy(created_event),
            failure_msg(
                "%s doesn't provide IObjectCreatedEvent" % created_event))
        self.failUnless(
            created_event.object == message,
            failure_msg("IObjectCreatedEvent contains wrong message"))
        self.failUnless(
            created_event_user == message.owner,
            failure_msg("%s != %s" % (
                created_event_user.displayname, message.owner.displayname)))

        self.failUnless(
            len(self.collected_events) == 2,
            failure_msg('failed to trigger an IObjectModifiedEvent'))
        modified_event = self.collected_events[1]
        modified_event_user = IPerson(modified_event.user)
        self.failUnless(
            IObjectModifiedEvent.providedBy(modified_event),
            failure_msg(
                "%s doesn't provide IObjectModifiedEvent"
                % modified_event))
        self.failUnless(
            modified_event.object == self.question,
            failure_msg("IObjectModifiedEvent contains wrong question"))
        self.failUnless(
            modified_event_user == message.owner,
            failure_msg("%s != %s" % (
                modified_event_user.displayname, message.owner.displayname)))
        if edited_fields:
            self.failUnless(
                set(modified_event.edited_fields) == set(edited_fields),
                failure_msg("%s != %s" % (
                    set(modified_event.edited_fields), set(edited_fields))))
예제 #12
0
    def execute(self, context, current_event):
        """See `IEmailCommand`.

        Much of this method was lifted from
        `EditEmailCommand.execute`.
        """
        # Parse args.
        self._ensureNumberOfArguments()
        [security_flag] = self.string_args
        if security_flag == 'yes':
            security_related = True
        elif security_flag == 'no':
            security_related = False
        else:
            raise EmailProcessingError(get_error_message(
                'security-parameter-mismatch.txt',
                error_templates=error_templates),
                                       stop_processing=True)

        if isinstance(context, CreateBugParams):
            if security_related:
                context.information_type = InformationType.PRIVATESECURITY
            return context, current_event

        # Take a snapshot.
        edited = False
        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(context, providing=providedBy(context))

        # Apply requested changes.
        user = getUtility(ILaunchBag).user
        if security_related:
            if context.setPrivate(True, user):
                edited = True
                edited_fields.add('private')
        if context.security_related != security_related:
            context.setSecurityRelated(security_related, user)
            edited = True
            edited_fields.add('security_related')

        # Update the current event.
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            current_event = ObjectModifiedEvent(context, context_snapshot,
                                                list(edited_fields))

        return context, current_event
예제 #13
0
    def execute(self, context, current_event):
        """See `IEmailCommand`. Much of this method has been lifted from
        `EditEmailCommand.execute`.
        """
        # Parse args.
        self._ensureNumberOfArguments()
        private_arg = self.string_args[0]
        if private_arg == 'yes':
            private = True
        elif private_arg == 'no':
            private = False
        else:
            raise EmailProcessingError(
                get_error_message(
                    'private-parameter-mismatch.txt',
                    error_templates=error_templates),
                stop_processing=True)

        if isinstance(context, CreateBugParams):
            if private:
                # "private yes" forces it to Private if it isn't already.
                if (context.information_type is None
                    or context.information_type in PUBLIC_INFORMATION_TYPES):
                    context.information_type = InformationType.USERDATA
            elif context.information_type != InformationType.PRIVATESECURITY:
                # "private no" forces it to Public, except we always
                # force new security bugs to be private.
                context.information_type = InformationType.PUBLIC
            return context, current_event

        # Snapshot.
        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(
                context, providing=providedBy(context))

        # Apply requested changes.
        edited = context.setPrivate(private, getUtility(ILaunchBag).user)

        # Update the current event.
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            edited_fields.add('private')
            current_event = ObjectModifiedEvent(
                context, context_snapshot, list(edited_fields))

        return context, current_event
예제 #14
0
    def execute(self, context, current_event):
        """See `IEmailCommand`. Much of this method has been lifted from
        `EditEmailCommand.execute`.
        """
        # Parse args.
        self._ensureNumberOfArguments()
        private_arg = self.string_args[0]
        if private_arg == 'yes':
            private = True
        elif private_arg == 'no':
            private = False
        else:
            raise EmailProcessingError(get_error_message(
                'private-parameter-mismatch.txt',
                error_templates=error_templates),
                                       stop_processing=True)

        if isinstance(context, CreateBugParams):
            if private:
                # "private yes" forces it to Private if it isn't already.
                if (context.information_type is None or
                        context.information_type in PUBLIC_INFORMATION_TYPES):
                    context.information_type = InformationType.USERDATA
            elif context.information_type != InformationType.PRIVATESECURITY:
                # "private no" forces it to Public, except we always
                # force new security bugs to be private.
                context.information_type = InformationType.PUBLIC
            return context, current_event

        # Snapshot.
        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(context, providing=providedBy(context))

        # Apply requested changes.
        edited = context.setPrivate(private, getUtility(ILaunchBag).user)

        # Update the current event.
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            edited_fields.add('private')
            current_event = ObjectModifiedEvent(context, context_snapshot,
                                                list(edited_fields))

        return context, current_event
예제 #15
0
    def execute(self, context, current_event):
        """See IEmailCommand."""
        self._ensureNumberOfArguments()
        args = self.convertArguments(context)

        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(context, providing=providedBy(context))

        edited = False
        for attr_name, attr_value in args.items():
            if getattr(context, attr_name) != attr_value:
                self.setAttributeValue(context, attr_name, attr_value)
                edited = True
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            edited_fields.update(args.keys())
            current_event = ObjectModifiedEvent(context, context_snapshot, list(edited_fields))

        return context, current_event
예제 #16
0
    def execute(self, context, current_event):
        """See IEmailCommand."""
        self._ensureNumberOfArguments()
        args = self.convertArguments(context)

        edited_fields = set()
        if IObjectModifiedEvent.providedBy(current_event):
            context_snapshot = current_event.object_before_modification
            edited_fields.update(current_event.edited_fields)
        else:
            context_snapshot = Snapshot(context, providing=providedBy(context))

        edited = False
        for attr_name, attr_value in args.items():
            if getattr(context, attr_name) != attr_value:
                self.setAttributeValue(context, attr_name, attr_value)
                edited = True
        if edited and not IObjectCreatedEvent.providedBy(current_event):
            edited_fields.update(args.keys())
            current_event = ObjectModifiedEvent(context, context_snapshot,
                                                list(edited_fields))

        return context, current_event
예제 #17
0
 def notify_bugtask_event(self, bugtask_event, bug_event):
         if bugtask_event is None:
             return
         if not IObjectCreatedEvent.providedBy(bug_event):
             notify(bugtask_event)
예제 #18
0
 def notify_bugtask_event(self, bugtask_event, bug_event):
     if bugtask_event is None:
         return
     if not IObjectCreatedEvent.providedBy(bug_event):
         notify(bugtask_event)