Пример #1
0
    def build_new_issue_args(self, issue_type_id, new_issue_fields, task):
        """
        Build the JSON needed to create the issue defined
        by new_issue_details
        """
        args = {
            'fields': {
                'project': {
                    'key': self.config['alm_project']
                },
                'issuetype': {
                    'id': issue_type_id
                }
            }
        }

        if self.config['alm_parent_issue']:
            args['fields']['parent'] = {'key': self.config['alm_parent_issue']}

        if self.config['alm_project_version']:
            args['fields']['versions'] = [{'name': self.config['alm_project_version']}]

        unsupported_fields = []

        for field_id, mapped_field in self.fields.iteritems():

            if mapped_field['name'] not in new_issue_fields:
                continue

            arg_value = new_issue_fields[mapped_field['name']]

            # Skip fields with missing values
            if not arg_value:
                continue

            schema = mapped_field['schema']
            # Field is an array of string
            if (schema['type'] == 'array' and schema['items'] in ['string', 'option']):

                # Expand on what we already have defined above
                if field_id in args['fields'] and isinstance(args['fields'][field_id], list):
                    field_values = args['fields'][field_id]
                else:
                    field_values = []

                # Accommodate more than one value for this field
                if isinstance(arg_value, list):
                    for list_item in arg_value:
                        # Labels must be sanitized
                        if schema.has_key('system') and schema['system'] == 'labels':
                            list_item = JIRATask.sanitize_label(unicode(list_item))
                            field_values.append(list_item)
                        else:
                            field_values.append({'value': list_item})
                else:
                    # Labels must be sanitized
                    if schema.has_key('system') and schema['system'] == 'labels':
                        arg_value = JIRATask.sanitize_label(unicode(arg_value))
                        field_values.append(arg_value)
                    else:
                        field_values.append({'value': arg_value})
                args['fields'][field_id] = field_values
            # Field is an array of version or component
            elif (schema['type'] == 'array' and schema['items'] in ['version', 'component']):

                # Expand on what we already have defined above
                if field_id in args['fields'] and isinstance(args['fields'][field_id], list):
                    field_values = args['fields'][field_id]
                else:
                    field_values = []

                # Accommodate more than one value for this field
                if isinstance(arg_value, list):
                    for list_item in arg_value:
                        field_values.append({'name': list_item})
                else:
                    field_values.append({'name': arg_value})
                args['fields'][field_id] = field_values
            # Field is a string
            elif schema['type'] in ['string', 'option']:
                arg_value = unicode(arg_value)
                if 'allowedValues' in mapped_field:
                    args['fields'][field_id] = {'value': arg_value}
                else:
                    args['fields'][field_id] = arg_value
            elif schema['type'] == 'priority':
                priority = self._get_priority(arg_value)
                if not priority:
                    raise AlmException('No such priority defined: %s' % arg_value)

                args['fields'][field_id] = {'id': priority['id']}
            elif schema['type'] == 'user':
                args['fields'][field_id] = {'name': arg_value}
            elif schema['type'] == 'any':
                args['fields'][field_id] = arg_value
            elif mapped_field['required']:
                if mapped_field.has_key('hasDefaultValue') and mapped_field['hasDefaultValue']:
                    continue
                else:
                    unsupported_fields.append(mapped_field['name'])

        if len(unsupported_fields) > 0:
            raise AlmException('Unable to add issue due to unsupported fields: %s' % ', '.join(unsupported_fields))

        return args
Пример #2
0
    def test_mixed_case_done_status_in_status_translation(self):
        jira_task1 = JIRATask('T21', 'TEST-21', 7, 'Resolved', 'Fixed', 0, ['RESolvEd'], [], '', '', '')
        self.assertEqual(jira_task1.get_status(), STATUS.DONE)

        jira_task2 = JIRATask('T21', 'TEST-21', 7, 'ResOLVed', 'Fixed', 0, ['RESolVEd'], [], '', '', '')
        self.assertEqual(jira_task2.get_status(), STATUS.DONE)