def testOneLongLine(self):
    msg = ('This is a super long line that just goes on and on '
           'and it seems like it will never stop because it is '
           'super long and it was entered by a user who had no '
           'familiarity with the return key.')
    wrapped_msg = framework_helpers.WordWrapSuperLongLines(msg)
    expected = ('This is a super long line that just goes on and on and it '
                'seems like it will never stop because it\n'
                'is super long and it was entered by a user who had no '
                'familiarity with the return key.')
    self.assertEqual(wrapped_msg, expected)

    msg2 = ('This is a super long line that just goes on and on '
            'and it seems like it will never stop because it is '
            'super long and it was entered by a user who had no '
            'familiarity with the return key. '
            'This is a super long line that just goes on and on '
            'and it seems like it will never stop because it is '
            'super long and it was entered by a user who had no '
            'familiarity with the return key.')
    wrapped_msg2 = framework_helpers.WordWrapSuperLongLines(msg2)
    expected2 = ('This is a super long line that just goes on and on and it '
                 'seems like it will never stop because it\n'
                 'is super long and it was entered by a user who had no '
                 'familiarity with the return key. This is a\n'
                 'super long line that just goes on and on and it seems like '
                 'it will never stop because it is super\n'
                 'long and it was entered by a user who had no familiarity '
                 'with the return key.')
    self.assertEqual(wrapped_msg2, expected2)
 def testMixOfShortAndLong(self):
   msg = ('[Author: mpcomplete]\n'
          '\n'
          # Description on one long line
          'Fix a memory leak in JsArray and JsObject for the IE and NPAPI '
          'ports.  Each time you call GetElement* or GetProperty* to '
          'retrieve string or object token, the token would be leaked.  '
          'I added a JsScopedToken to ensure that the right thing is '
          'done when the object leaves scope, depending on the platform.\n'
          '\n'
          'R=zork\n'
          '[email protected]\n'
          'DELTA=108  (52 added, 36 deleted, 20 changed)\n'
          'OCL=5932446\n'
          'SCL=5933728\n')
   wrapped_msg = framework_helpers.WordWrapSuperLongLines(msg)
   expected = (
       '[Author: mpcomplete]\n'
       '\n'
       'Fix a memory leak in JsArray and JsObject for the IE and NPAPI '
       'ports.  Each time you call\n'
       'GetElement* or GetProperty* to retrieve string or object token, the '
       'token would be leaked.  I added\n'
       'a JsScopedToken to ensure that the right thing is done when the '
       'object leaves scope, depending on\n'
       'the platform.\n'
       '\n'
       'R=zork\n'
       '[email protected]\n'
       'DELTA=108  (52 added, 36 deleted, 20 changed)\n'
       'OCL=5932446\n'
       'SCL=5933728\n')
   self.assertEqual(wrapped_msg, expected)
Пример #3
0
def ParseTemplateRequest(post_data, config):
    """Parse an issue template."""

    name = post_data.get('name', '')
    members_only = (post_data.get('members_only') == 'on')
    summary = post_data.get('summary', '')
    summary_must_be_edited = (post_data.get('summary_must_be_edited') == 'on')
    content = post_data.get('content', '')
    content = framework_helpers.WordWrapSuperLongLines(content, max_cols=75)
    status = post_data.get('status', '')
    owner_str = post_data.get('owner', '')
    labels = post_data.getall('label')
    field_val_strs = collections.defaultdict(list)
    for fd in config.field_defs:
        field_value_key = 'custom_%d' % fd.field_id
        if post_data.get(field_value_key):
            field_val_strs[fd.field_id].append(post_data[field_value_key])

    component_paths = []
    if post_data.get('components'):
        for component_path in post_data.get('components').split(','):
            if component_path.strip() not in component_paths:
                component_paths.append(component_path.strip())
    component_required = post_data.get('component_required') == 'on'

    owner_defaults_to_member = post_data.get(
        'owner_defaults_to_member') == 'on'

    admin_str = post_data.get('admin_names', '')

    add_approvals = post_data.get('add_approvals') == 'on'
    phase_names = [
        post_data.get(phase_input, '') for phase_input in PHASE_INPUTS
    ]

    required_approval_ids = []
    approvals_to_phase_idx = {}

    for approval_def in config.approval_defs:
        phase_num = post_data.get('approval_%d' % approval_def.approval_id, '')
        if phase_num == _NO_PHASE_VALUE:
            approvals_to_phase_idx[approval_def.approval_id] = None
        else:
            try:
                idx = PHASE_INPUTS.index(phase_num)
                approvals_to_phase_idx[approval_def.approval_id] = idx
            except ValueError:
                logging.info('approval %d was omitted' %
                             approval_def.approval_id)
        required_name = 'approval_%d_required' % approval_def.approval_id
        if (post_data.get(required_name) == 'on'):
            required_approval_ids.append(approval_def.approval_id)

    return ParsedTemplate(name, members_only, summary, summary_must_be_edited,
                          content, status, owner_str, labels, field_val_strs,
                          component_paths, component_required,
                          owner_defaults_to_member, admin_str, add_approvals,
                          phase_names, approvals_to_phase_idx,
                          required_approval_ids)
 def testShortLines(self):
   msg = 'one\ntwo\nthree\n'
   wrapped_msg = framework_helpers.WordWrapSuperLongLines(msg)
   expected = 'one\ntwo\nthree\n'
   self.assertEqual(wrapped_msg, expected)
 def testEmptyLogMessage(self):
   msg = ''
   wrapped_msg = framework_helpers.WordWrapSuperLongLines(msg)
   self.assertEqual(wrapped_msg, '')
Пример #6
0
    def _ParseTemplate(self, post_data, mr, i, orig_template, config):
        """Parse an issue template.  Return orig_template if cannot edit."""
        if not self._CanEditTemplate(mr, orig_template):
            return orig_template

        name = post_data['name_%s' % i]
        if name == tracker_constants.DELETED_TEMPLATE_NAME:
            return None

        members_only = False
        if ('members_only_%s' % i) in post_data:
            members_only = (post_data['members_only_%s' % i] == 'yes')
        summary = ''
        if ('summary_%s' % i) in post_data:
            summary = post_data['summary_%s' % i]
        summary_must_be_edited = False
        if ('summary_must_be_edited_%s' % i) in post_data:
            summary_must_be_edited = (post_data['summary_must_be_edited_%s' %
                                                i] == 'yes')
        content = ''
        if ('content_%s' % i) in post_data:
            content = post_data['content_%s' % i]
        # wrap="hard" has no effect on the content because we copy it to
        # a hidden form field before submission.  So, server-side word wrap.
        content = framework_helpers.WordWrapSuperLongLines(content,
                                                           max_cols=75)
        status = ''
        if ('status_%s' % i) in post_data:
            status = post_data['status_%s' % i]
        owner_id = 0
        if ('owner_%s' % i) in post_data:
            owner = post_data['owner_%s' % i]
            if owner:
                user_id = self.services.user.LookupUserID(mr.cnxn, owner)
                auth = monorailrequest.AuthData.FromUserID(
                    mr.cnxn, user_id, self.services)
                if framework_bizobj.UserIsInProject(mr.project,
                                                    auth.effective_ids):
                    owner_id = user_id

        labels = post_data.getall('label_%s' % i)
        labels_remove = []

        field_val_strs = collections.defaultdict(list)
        for fd in config.field_defs:
            field_value_key = 'field_value_%d_%d' % (i, fd.field_id)
            if post_data.get(field_value_key):
                field_val_strs[fd.field_id].append(post_data[field_value_key])

        field_helpers.ShiftEnumFieldsIntoLabels(labels, labels_remove,
                                                field_val_strs, {}, config)
        field_values = field_helpers.ParseFieldValues(mr.cnxn,
                                                      self.services.user,
                                                      field_val_strs, config)
        for fv in field_values:
            logging.info('field_value is %r: %r', fv.field_id,
                         tracker_bizobj.GetFieldValue(fv, {}))

        admin_ids = []
        if ('admin_names_%s' % i) in post_data:
            admin_ids, _admin_str = tracker_helpers.ParseAdminUsers(
                mr.cnxn, post_data['admin_names_%s' % i], self.services.user)

        component_ids = []
        if ('components_%s' % i) in post_data:
            component_paths = []
            for component_path in post_data['components_%s' % i].split(','):
                if component_path.strip() not in component_paths:
                    component_paths.append(component_path.strip())
            component_ids = tracker_helpers.LookupComponentIDs(
                component_paths, config, mr.errors)

        owner_defaults_to_member = False
        if ('owner_defaults_to_member_%s' % i) in post_data:
            owner_defaults_to_member = (
                post_data['owner_defaults_to_member_%s' % i] == 'yes')

        component_required = False
        if ('component_required_%s' % i) in post_data:
            component_required = post_data['component_required_%s' %
                                           i] == 'yes'

        template = tracker_bizobj.MakeIssueTemplate(
            name,
            summary,
            status,
            owner_id,
            content,
            labels,
            field_values,
            admin_ids,
            component_ids,
            summary_must_be_edited=summary_must_be_edited,
            owner_defaults_to_member=owner_defaults_to_member,
            component_required=component_required,
            members_only=members_only)
        template_id = int(post_data['template_id_%s' % i])
        if template_id:  # new templates have ID 0, so leave that None in PB.
            template.template_id = template_id
        logging.info('template is %r', template)

        return template