示例#1
0
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.owner)
     command = SecurityEmailCommand('security', ['yes'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual(True, bug.security_related)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
示例#2
0
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.bugtasks[0].target.owner)
     command = SummaryEmailCommand('summary', ['new title'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual('new title', bug.title)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.bugtasks[0].target.owner)
     command = SummaryEmailCommand('summary', ['new title'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual('new title', bug.title)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.owner)
     command = SecurityEmailCommand('security', ['yes'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual(True, bug.security_related)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
 def initialize(self):
     """Create a notifcation for a linked bug status change."""
     assert IObjectModifiedEvent.providedBy(self.event), (
         "Should only be subscribed for IObjectModifiedEvent.")
     assert IBugTask.providedBy(self.event.object), (
         "Should only be subscribed for IBugTask modification.")
     self.bugtask = self.event.object
     self.old_bugtask = self.event.object_before_modification
示例#6
0
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.owner)
     command = InformationTypeEmailCommand('informationtype',
                                           ['privatesecurity'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual(InformationType.PRIVATESECURITY, bug.information_type)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
 def test_execute_bug(self):
     master_bug = self.factory.makeBug()
     bug = self.factory.makeBug()
     login_person(bug.bugtasks[0].target.owner)
     command = DuplicateEmailCommand('duplicate', [str(master_bug.id)])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(master_bug, exec_bug)
     self.assertEqual(master_bug, bug.duplicateof)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
示例#8
0
 def test_execute_bug(self):
     master_bug = self.factory.makeBug()
     bug = self.factory.makeBug()
     login_person(bug.bugtasks[0].target.owner)
     command = DuplicateEmailCommand('duplicate', [str(master_bug.id)])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(master_bug, exec_bug)
     self.assertEqual(master_bug, bug.duplicateof)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
 def test_execute_bug(self):
     bug = self.factory.makeBug()
     login_person(bug.owner)
     command = InformationTypeEmailCommand(
         'informationtype', ['privatesecurity'])
     exec_bug, event = command.execute(bug, None)
     self.assertEqual(bug, exec_bug)
     self.assertEqual(
         InformationType.PRIVATESECURITY, bug.information_type)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
示例#10
0
 def test_execute_bug_params(self):
     user = self.factory.makePerson()
     login_person(user)
     bug_params = CreateBugParams(title='bug title', owner=user)
     command = InformationTypeEmailCommand('informationtype',
                                           ['publicsecurity'])
     dummy_event = object()
     params, event = command.execute(bug_params, dummy_event)
     self.assertEqual(bug_params, params)
     self.assertEqual(InformationType.PUBLICSECURITY,
                      bug_params.information_type)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
示例#11
0
 def test_execute_bug_params(self):
     user = self.factory.makePerson()
     login_person(user)
     bug_params = CreateBugParams(title='bug title', owner=user)
     command = InformationTypeEmailCommand(
         'informationtype', ['publicsecurity'])
     dummy_event = object()
     params, event = command.execute(bug_params, dummy_event)
     self.assertEqual(bug_params, params)
     self.assertEqual(
         InformationType.PUBLICSECURITY, bug_params.information_type)
     self.assertTrue(IObjectModifiedEvent.providedBy(event))
示例#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
    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))))
示例#14
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.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))))
示例#16
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
def update_bug_date_last_updated(object, event):
    """Update IBug.date_last_updated to the current date."""
    # If no fields on the bug have changed, do nothing.
    if IObjectModifiedEvent.providedBy(event) and not event.edited_fields:
        return
    if IBug.providedBy(object):
        bug = object
    elif IHasBug.providedBy(object):
        bug = object.bug
    else:
        raise AssertionError(
            "Unable to retrieve current bug to update 'date last updated'. "
            "Event handler expects object implementing IBug or IHasBug. "
            "Got: %s" % repr(object))
    removeSecurityProxy(bug).date_last_updated = datetime.now(pytz.UTC)
def update_bug_date_last_updated(object, event):
    """Update IBug.date_last_updated to the current date."""
    # If no fields on the bug have changed, do nothing.
    if IObjectModifiedEvent.providedBy(event) and not event.edited_fields:
        return
    if IBug.providedBy(object):
        bug = object
    elif IHasBug.providedBy(object):
        bug = object.bug
    else:
        raise AssertionError(
            "Unable to retrieve current bug to update 'date last updated'. "
            "Event handler expects object implementing IBug or IHasBug. "
            "Got: %s" % repr(object))
    removeSecurityProxy(bug).date_last_updated = datetime.now(pytz.UTC)
示例#19
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
示例#20
0
 def test_run_object_events(self):
     # While the job runs a single IObjectModifiedEvent is issued when the
     # preview diff has been calculated.
     bmp = self.createExampleBzrMerge()[0]
     job = UpdatePreviewDiffJob.create(bmp)
     self.factory.makeRevisionsForBranch(bmp.source_branch, count=1)
     bmp.source_branch.next_mirror_time = None
     with dbuser("merge-proposal-jobs"):
         with EventRecorder() as event_recorder:
             JobRunner([job]).runAll()
     bmp_object_events = [
         event for event in event_recorder.events
         if (IObjectModifiedEvent.providedBy(event) and event.object == bmp)
     ]
     self.assertEqual(1, len(bmp_object_events),
                      "Expected one event, got: %r" % bmp_object_events)
     self.assertEqual(["preview_diff"], bmp_object_events[0].edited_fields)
 def test_run_object_events(self):
     # While the job runs a single IObjectModifiedEvent is issued when the
     # preview diff has been calculated.
     self.useBzrBranches(direct_database=True)
     bmp = create_example_merge(self)[0]
     job = UpdatePreviewDiffJob.create(bmp)
     self.factory.makeRevisionsForBranch(bmp.source_branch, count=1)
     bmp.source_branch.next_mirror_time = None
     with dbuser("merge-proposal-jobs"):
         with EventRecorder() as event_recorder:
             JobRunner([job]).runAll()
     bmp_object_events = [
         event for event in event_recorder.events
         if (IObjectModifiedEvent.providedBy(event) and
             event.object == bmp)]
     self.assertEqual(
         1, len(bmp_object_events),
         "Expected one event, got: %r" % bmp_object_events)
     self.assertEqual(
         ["preview_diff"], bmp_object_events[0].edited_fields)
示例#22
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
示例#23
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