示例#1
0
    def test_string_to_list(self):
        strings = "Python,Go,,Perl,Ruby"
        strings_list = ["Python", "Go", "Perl", "Ruby"]
        strings_list.sort()
        expected_strings = [u"Python", u"Go", u"Perl", u"Ruby"]
        expected_strings.sort()

        result = string_to_list(strings_list)
        result.sort()
        self.assertEqual(expected_strings, result)

        result = string_to_list(strings)
        result.sort()
        self.assertEqual(expected_strings, result)

        another_strings = strings.replace(",", "#")
        result = string_to_list(another_strings, "#")
        result.sort()
        self.assertEqual(expected_strings, result)

        self.assertEqual([1], string_to_list(1))

        self.assertEqual([], string_to_list(()))

        strings = "abcdefg"
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = u"abcdefg"
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = "abcdefg"
        result = string_to_list(strings, ":")
        self.assertEqual([strings], result)
示例#2
0
    def test_string_to_list(self):
        strings = 'Python,Go,,Perl,Ruby'
        strings_list = ['Python', 'Go', 'Perl', 'Ruby']
        strings_list.sort()
        expected_strings = [u'Python', u'Go', u'Perl', u'Ruby']
        expected_strings.sort()

        result = string_to_list(strings_list)
        result.sort()
        self.assertEqual(expected_strings, result)

        result = string_to_list(strings)
        result.sort()
        self.assertEqual(expected_strings, result)

        another_strings = strings.replace(',', '#')
        result = string_to_list(another_strings, '#')
        result.sort()
        self.assertEqual(expected_strings, result)

        self.assertEqual([1], string_to_list(1))

        self.assertEqual([], string_to_list(()))

        strings = 'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = u'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = 'abcdefg'
        result = string_to_list(strings, ':')
        self.assertEqual([strings], result)
示例#3
0
def add_tag(run_ids, tags):
    """
    Description: Add one or more tags to the selected test runs.

    Params:      $run_ids - Integer/Array/String: An integer representing the ID in the database,
                                                  an arry of run_ids, or a string of
                                                  comma separated run_ids.

                 $tags - String/Array - A single tag, an array of tags,
                                        or a comma separated list of tags.

    Returns:     Array: empty on success or an array of hashes with failure
                        codes if a failure occured.

    Example:
    # Add tag 'foobar' to run 1234
    >>> TestPlan.add_tag(1234, 'foobar')
    # Add tag list ['foo', 'bar'] to run list [12345, 67890]
    >>> TestPlan.add_tag([12345, 67890], ['foo', 'bar'])
    # Add tag list ['foo', 'bar'] to run list [12345, 67890] with String
    >>> TestPlan.add_tag('12345, 67890', 'foo, bar')
    """
    trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids))
    if not isinstance(tags, str) and not isinstance(tags, list):
        raise ValueError('Parameter tags must be a string or list(string)')
    tags = string_to_list(tags)

    for tag in tags:
        t, c = TestTag.objects.get_or_create(name=tag)
        for tr in trs.iterator():
            tr.add_tag(tag=t)

    return
示例#4
0
文件: testcase.py 项目: jetlyb/Kiwi
def remove_tag(case_ids, tags):
    """
    Description: Remove a tag from a case.

    Params: $case_ids - Integer/Array/String: An integer or alias representing the ID
                         in the database, an array of case_ids,
                         or a string of comma separated case_ids.

            $tags - String/Array - A single or multiple tag to be removed.

    Returns: Array: Empty on success.

    Example:
    # Remove tag 'foo' from case 1234
    >>> TestCase.remove_tag(1234, 'foo')
    # Remove tag 'foo' and bar from cases list [56789, 12345]
    >>> TestCase.remove_tag([56789, 12345], ['foo', 'bar'])
    # Remove tag 'foo' and 'bar' from cases list '56789, 12345' with String
    >>> TestCase.remove_tag('56789, 12345', 'foo, bar')
    """
    test_cases = TestCase.objects.filter(case_id__in=pre_process_ids(
        value=case_ids))
    test_tags = TestTag.objects.filter(name__in=string_to_list(tags))

    for test_case in test_cases.iterator():
        for test_tag in test_tags.iterator():
            test_case.remove_tag(test_tag)

    return
示例#5
0
 def clean_pk__in(self):
     from tcms.core.utils import string_to_list
     results = string_to_list(self.cleaned_data['pk__in'])
     try:
         return [int(r) for r in results]
     except Exception, e:
         raise forms.ValidationError(str(e))
示例#6
0
文件: testcase.py 项目: jetlyb/Kiwi
def add_tag(case_ids, tags):
    """
    Description: Add one or more tags to the selected test cases.

    Params:     $case_ids - Integer/Array/String: An integer representing the ID in the database,
                            an array of case_ids, or a string of comma separated case_ids.

                $tags - String/Array - A single tag, an array of tags,
                        or a comma separated list of tags.

    Returns:    Array: empty on success or an array of hashes with failure
                       codes if a failure occured.

    Example:
    # Add tag 'foobar' to case 1234
    >>> TestCase.add_tag(1234, 'foobar')
    # Add tag list ['foo', 'bar'] to cases list [12345, 67890]
    >>> TestCase.add_tag([12345, 67890], ['foo', 'bar'])
    # Add tag list ['foo', 'bar'] to cases list [12345, 67890] with String
    >>> TestCase.add_tag('12345, 67890', 'foo, bar')
    """
    tcs = TestCase.objects.filter(case_id__in=pre_process_ids(value=case_ids))

    tags = string_to_list(tags)

    for tag in tags:
        t, c = TestTag.objects.get_or_create(name=tag)
        for tc in tcs.iterator():
            tc.add_tag(tag=t)

    return
示例#7
0
文件: forms.py 项目: xltian/nitrate
 def clean_pk__in(self):
     from tcms.core.utils import string_to_list
     results = string_to_list(self.cleaned_data['pk__in'])
     try:
         return [int(r) for r in results]
     except Exception, e:
         raise forms.ValidationError(str(e))
示例#8
0
def remove_tag(run_ids, tags):
    """
    Description: Remove a tag from a run.

    Params:      $run_ids - Integer/Array/String: An integer or alias representing the ID in the
                             database, an array of run_ids, or a string of comma separated run_ids.

                 $tag - String - A single tag to be removed.

    Returns:     Array: Empty on success.

    Example:
    # Remove tag 'foo' from run 1234
    >>> TestRun.remove_tag(1234, 'foo')
    # Remove tag 'foo' and 'bar' from run list [56789, 12345]
    >>> TestRun.remove_tag([56789, 12345], ['foo', 'bar'])
    # Remove tag 'foo' and 'bar' from run list '56789, 12345' with String
    >>> TestRun.remove_tag('56789, 12345', 'foo, bar')
    """
    test_runs = TestRun.objects.filter(run_id__in=pre_process_ids(
        value=run_ids))

    if not isinstance(tags, str) and not isinstance(tags, list):
        raise ValueError('Parameter tags must be a string or list(string)')

    test_tags = TestTag.objects.filter(name__in=string_to_list(tags))

    for test_run in test_runs.iterator():
        for test_tag in test_tags.iterator():
            test_run.remove_tag(tag=test_tag)

    return
示例#9
0
def create(values, **kwargs):
    """
    .. function:: XML-RPC TestCase.create(values)

        Create a new TestCase object and store it in the database.

        :param values: Field values for :class:`tcms.testcases.models.TestCase`
        :type values: dict
        :return: Serialized :class:`tcms.testcases.models.TestCase` object
        :rtype: dict
        :raises: PermissionDenied if missing *testcases.add_testcase* permission

        Minimal test case parameters::

            >>> values = {
                'category': 135,
                'product': 61,
            'summary': 'Testing XML-RPC',
            'priority': 1,
            }
            >>> TestCase.create(values)
    """
    request = kwargs.get(REQUEST_KEY)

    if not (values.get('category') or values.get('summary')):
        raise ValueError()

    if values.get('estimated_time'):
        values['estimated_time'] = parse_duration(values.get('estimated_time'))

    form = NewCaseForm(values)
    form.populate(values.get('product'))

    if form.is_valid():
        # Create the case
        test_case = TestCase.create(author=request.user,
                                    values=form.cleaned_data)

        # Add case text to the case
        test_case.add_text(
            action=form.cleaned_data['action'] or '',
            effect=form.cleaned_data['effect'] or '',
            setup=form.cleaned_data['setup'] or '',
            breakdown=form.cleaned_data['breakdown'] or '',
        )

        # Add tag to the case
        for tag in string_to_list(values.get('tag', [])):
            tag, _ = Tag.objects.get_or_create(name=tag)
            test_case.add_tag(tag=tag)
    else:
        # Print the errors if the form is not passed validation.
        raise ValueError(form_errors_to_list(form))

    result = test_case.serialize()
    result['text'] = test_case.latest_text().serialize()

    return result
示例#10
0
文件: forms.py 项目: hangnhat57/Kiwi
    def clean_pk__in(self):
        results = []
        try:
            for result in string_to_list(self.cleaned_data['pk__in']):
                results.append(int(result))
        except Exception as error:
            raise forms.ValidationError(str(error))

        return results
示例#11
0
 def clean_bug_id(self):
     from tcms.core.utils import string_to_list
     data = self.cleaned_data['bug_id']
     data = string_to_list(data)
     for d in data:
         try:
             int(d)
         except ValueError, error:
             raise forms.ValidationError(error)
示例#12
0
    def clean(self, value):
        """
        Validates that the input matches the regular expression. Returns a
        Unicode object.
        """
        value = super(forms.CharField, self).clean(value)
        if value == u'':
            return value

        return [v for v in string_to_list(strs=value) if self.regex.search(v)]
示例#13
0
    def clean_bug_id(self):
        data = self.cleaned_data['bug_id']
        data = string_to_list(data)
        for data_obj in data:
            try:
                int(data_obj)
            except ValueError as error:
                raise forms.ValidationError(error)

        return data
示例#14
0
文件: fields.py 项目: MrSenko/Nitrate
    def clean(self, value):
        """
        Validates that the input matches the regular expression. Returns a
        Unicode object.
        """
        value = super(forms.CharField, self).clean(value)
        if value == u'':
            return value

        return [v for v in string_to_list(strs=value) if self.regex.search(v)]
示例#15
0
 def validate(self, value):
     super().validate(value)
     issue_key_regex = [
         re.compile(regex) for regex in
         IssueTracker.objects.values_list('validate_regex', flat=True)
     ]
     for issue_key in string_to_list(value):
         if not any(regex.match(issue_key) is not None
                    for regex in issue_key_regex):
             raise forms.ValidationError(
                 '{} is not a valid issue key of configured issue trackers.')
示例#16
0
文件: forms.py 项目: tkdchen/Nitrate
 def validate(self, value):
     super(IssueKeyField, self).validate(value)
     issue_key_regex = [
         re.compile(regex) for regex in
         IssueTracker.objects.values_list('validate_regex', flat=True)
     ]
     for issue_key in string_to_list(value):
         if not any(regex.match(issue_key) is not None
                    for regex in issue_key_regex):
             raise forms.ValidationError(
                 '{} is not a valid issue key of configured issue trackers.')
示例#17
0
    def validate(self, value):
        super(BugField, self).validate(value)
        error = 'Enter a valid Bug ID.'
        bug_ids = string_to_list(value)

        for bug_id in bug_ids:
            try:
                bug_id = int(bug_id)
            except ValueError as error:
                raise forms.ValidationError(error)
            if abs(bug_id) > 8388607:
                raise forms.ValidationError(error)
示例#18
0
    def validate(self, value):
        from tcms.core.utils import string_to_list
        super(BugField, self).validate(value)
        error = 'Enter a valid Bug ID.'
        bug_ids = string_to_list(value)

        for bug_id in bug_ids:
            try:
                bug_id = int(bug_id)
            except ValueError, error:
                raise forms.ValidationError(error)
            if abs(bug_id) > 8388607:
                raise forms.ValidationError(error)
示例#19
0
文件: testplan.py 项目: jetlyb/Kiwi
def add_tag(plan_ids, tags):
    """
    Description: Add one or more tags to the selected test plans.

    Params:      $plan_ids - Integer/Array/String: An integer representing the ID of the plan
                      in the database,
                      an arry of plan_ids, or a string of comma separated plan_ids.

                  $tags - String/Array - A single tag, an array of tags,
                      or a comma separated list of tags.

    Returns:     Array: empty on success or an array of hashes with failure
                  codes if a failure occured.

    Example:
    # Add tag 'foobar' to plan 1234
    >>> TestPlan.add_tag(1234, 'foobar')
    # Add tag list ['foo', 'bar'] to plan list [12345, 67890]
    >>> TestPlan.add_tag([12345, 67890], ['foo', 'bar'])
    # Add tag list ['foo', 'bar'] to plan list [12345, 67890] with String
    >>> TestPlan.add_tag('12345, 67890', 'foo, bar')
    """
    # FIXME: this could be optimized to reduce possible huge number of SQLs

    tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids))

    if not isinstance(tags, (str, list)):
        raise ValueError('Parameter tags must be a string or list(string)')

    tags = string_to_list(tags)

    for tag in tags:
        t, c = TestTag.objects.get_or_create(name=tag)
        for tp in tps.iterator():
            tp.add_tag(tag=t)

    return
示例#20
0
    def test_string_to_list(self):
        strings = 'Python,Go,,Perl,Ruby'
        strings_list = ['Python', 'Go', 'Perl', 'Ruby']
        strings_list.sort()
        expected_strings = ['Python', 'Go', 'Perl', 'Ruby']
        expected_strings.sort()

        result = string_to_list(strings_list)
        result.sort()
        self.assertEqual(expected_strings, result)

        result = string_to_list(strings)
        result.sort()
        self.assertEqual(expected_strings, result)

        another_strings = strings.replace(',', '#')
        result = string_to_list(another_strings, '#')
        result.sort()
        self.assertEqual(expected_strings, result)

        strings = 1
        self.assertRaises(AttributeError, string_to_list, strings)

        strings = ()
        self.assertRaises(AttributeError, string_to_list, strings)

        strings = 'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = 'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = 'abcdefg'
        result = string_to_list(strings, ':')
        self.assertEqual([strings], result)
示例#21
0
文件: tests.py 项目: Aaln1986/Nitrate
    def test_string_to_list(self):
        strings = 'Python,Go,,Perl,Ruby'
        strings_list = ['Python', 'Go', 'Perl', 'Ruby']
        strings_list.sort()
        expected_strings = [u'Python', u'Go', u'Perl', u'Ruby']
        expected_strings.sort()

        result = string_to_list(strings_list)
        result.sort()
        self.assertEqual(expected_strings, result)

        result = string_to_list(strings)
        result.sort()
        self.assertEqual(expected_strings, result)

        another_strings = strings.replace(',', '#')
        result = string_to_list(another_strings, '#')
        result.sort()
        self.assertEqual(expected_strings, result)

        strings = 1
        self.assertRaises(AttributeError, string_to_list, strings)

        strings = ()
        self.assertRaises(AttributeError, string_to_list, strings)

        strings = 'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = u'abcdefg'
        result = string_to_list(strings)
        self.assertEqual([strings], result)

        strings = 'abcdefg'
        result = string_to_list(strings, ':')
        self.assertEqual([strings], result)
示例#22
0
 def clean_tag__name__in(self):
     return string_to_list(self.cleaned_data['tag__name__in'])
示例#23
0
 def string_to_list(cls, string):
     from tcms.core.utils import string_to_list
     return string_to_list(string)
示例#24
0
文件: testcase.py 项目: jetlyb/Kiwi
def create(values, **kwargs):
    """
    Description: Creates a new Test Case object and stores it in the database.

    Params:      $values - Array/Hash: A reference to a hash or array of hashes with keys and values
                 matching the fields of the test case to be created.
      +----------------------------+----------------+-----------+----------------------------+
      | Field                      | Type           | Null      | Description                |
      +----------------------------+----------------+-----------+----------------------------+
      | product                    | Integer        | Required  | ID of Product              |
      | category                   | Integer        | Required  | ID of Category             |
      | priority                   | Integer        | Required  | ID of Priority             |
      | summary                    | String         | Required  |                            |
      | case_status                | Integer        | Optional  | ID of case status          |
      | plan                       | Array/Str/Int  | Optional  | ID or List of plan_ids     |
      | component                  | Integer/String | Optional  | ID of Priority             |
      | default_tester             | String         | Optional  | Login of tester            |
      | estimated_time             | String         | Optional  | 2h30m30s(recommend)        |
      |                            |                |           |  or HH:MM:SS Format        |
      | is_automated               | Integer        | Optional  | 0: Manual, 1: Auto, 2: Both|
      | is_automated_proposed      | Boolean        | Optional  | Default 0                  |
      | script                     | String         | Optional  |                            |
      | arguments                  | String         | Optional  |                            |
      | requirement                | String         | Optional  |                            |
      | alias                      | String         | Optional  | Must be unique             |
      | action                     | String         | Optional  |                            |
      | effect                     | String         | Optional  | Expected Result            |
      | setup                      | String         | Optional  |                            |
      | breakdown                  | String         | Optional  |                            |
      | tag                        | Array/String   | Optional  | String Comma separated     |
      | bug                        | Array/String   | Optional  | String Comma separated     |
      | extra_link                 | String         | Optional  | reference link             |
      +----------------------------+----------------+-----------+----------------------------+

    Returns: Array/Hash: The newly created object hash if a single case was created, or
             an array of objects if more than one was created. If any single case
             threw an error during creation, a hash with an ERROR key will be set in its place.

    Example:
    # Minimal test case parameters
    >>> values = {
        'category': 135,
        'product': 61,
        'summary': 'Testing XML-RPC',
        'priority': 1,
    }
    >>> TestCase.create(values)
    """
    from tcms.xmlrpc.forms import NewCaseForm

    request = kwargs.get(REQUEST_KEY)

    if not (values.get('category') or values.get('summary')):
        raise ValueError()

    values['component'] = pre_process_ids(values.get('component', []))
    values['plan'] = pre_process_ids(values.get('plan', []))
    values['bug'] = pre_process_ids(values.get('bug', []))
    if values.get('estimated_time'):
        values['estimated_time'] = pre_process_estimated_time(
            values.get('estimated_time'))

    form = NewCaseForm(values)
    form.populate(values.get('product'))

    if form.is_valid():
        # Create the case
        tc = TestCase.create(author=request.user, values=form.cleaned_data)

        # Add case text to the case
        tc.add_text(
            action=form.cleaned_data['action'] or '',
            effect=form.cleaned_data['effect'] or '',
            setup=form.cleaned_data['setup'] or '',
            breakdown=form.cleaned_data['breakdown'] or '',
        )

        # Add the case to specific plans
        for p in form.cleaned_data['plan']:
            tc.add_to_plan(plan=p)
            del p

        # Add components to the case
        for c in form.cleaned_data['component']:
            tc.add_component(component=c)
            del c

        # Add tag to the case
        for tag in string_to_list(values.get('tag', [])):
            t, c = TestTag.objects.get_or_create(name=tag)
            tc.add_tag(tag=t)
    else:
        # Print the errors if the form is not passed validation.
        raise ValueError(form_errors_to_list(form))

    return get(tc.case_id)
示例#25
0
 def clean_tag(self):
     tags = []
     if self.cleaned_data['tag']:
         tag_names = string_to_list(self.cleaned_data['tag'])
         tags = TestTag.get_or_create_many_by_name(tag_names)
     return tags
示例#26
0
文件: forms.py 项目: hangnhat57/Kiwi
 def clean_tag(self):
     return Tag.objects.filter(
         name__in=string_to_list(self.cleaned_data['tag']))
示例#27
0
文件: ajax.py 项目: rmoorman/Kiwi
 def __init__(self, obj, tag):
     self.obj = obj
     self.tag = string_to_list(tag)
     self.request = request
示例#28
0
文件: models.py 项目: tkdchen/Nitrate
 def string_to_list(cls, string):
     from tcms.core.utils import string_to_list
     return string_to_list(string)
示例#29
0
文件: forms.py 项目: jetlyb/Kiwi
 def clean_pk__in(self):
     results = string_to_list(self.cleaned_data['pk__in'])
     try:
         return [int(r) for r in results]
     except Exception as e:
         raise forms.ValidationError(str(e))
示例#30
0
 def clean_env_value__value__in(self):
     return string_to_list(self.cleaned_data['env_value__value__in'])