def setUpClass(cls):
        req1 = Requirement.create(DEFAULT_PROJ,
                                  "regression",
                                  "regression",
                                  severity="should_have",
                                  reqtype="functional")

        cls.NEW_REQ = req1.work_item_id
        req2 = Requirement.create(DEFAULT_PROJ,
                                  "regression",
                                  "regression",
                                  severity="should_have",
                                  reqtype="functional")
        cls.NEW_REQ2 = req2.work_item_id
Esempio n. 2
0
def requirement(source_code_path, project):
    """Create and/or update requirements in Polarion."""
    requirements = []
    source_testcases = itertools.chain(
        *collector.collect_tests(source_code_path).values())
    for testcase in source_testcases:
        fields = {k.lower(): v for k, v in testcase.fields.items()}
        if ('requirement' in fields
                and fields['requirement'] not in requirements):
            requirement_title = fields['requirement']
            results = Requirement.query(requirement_title,
                                        fields=['status', 'title'])
            requirement = None
            for result in results:
                if result.title == requirement_title:
                    requirement = result
                    break
            if requirement is None:
                click.echo(u'Creating requirement {0}.'.format(
                    fields['requirement']))
                requirement = Requirement.create(project,
                                                 requirement_title,
                                                 '',
                                                 reqtype='functional')
            if requirement.status != 'approved':
                click.echo(u'Approving requirement {0}.'.format(
                    requirement.title))
                requirement.status = 'approved'
                requirement.update()
Esempio n. 3
0
def fetch_requirement(query, project, collect_only=False):
    """Fetch or create a requirement.

    Return the fetched or created requirement object.
    """
    click.echo('Fetching requirement {0}.'.format(query))
    if query in OBJ_CACHE['requirements'].keys():
        return OBJ_CACHE['requirements'][query]
    requirement = None
    if not collect_only:
        results = Requirement.query(query, fields=['title', 'work_item_id'])
        if len(results) > 0:
            # As currently is not possible to get a single
            # match for the title, make sure to not use a
            # not intended Requirement.
            for result in results:
                if result.title == query or result.work_item_id == query:
                    requirement = result
    if requirement is None:
        click.echo('Creating requirement {0}.'.format(query))
        if not collect_only:
            requirement = Requirement.create(project,
                                             query,
                                             '',
                                             reqtype='functional')
            requirement.status = 'approved'
            requirement.update()
    if query not in OBJ_CACHE['requirements'].keys():
        OBJ_CACHE['requirements'][query] = requirement
    return requirement
Esempio n. 4
0
def create_requirements(bz_rfes, bz_connection):
    for bz_rfe in bz_rfes:
        bug_title, bug_product, named_parms, bug_description, bug_link, bug_id, bug_priority, bug_severity, bug_dfg = get_bug_params(bz_rfe)
        bug_title = "BZ_id=%s; %s" % (bug_id, bug_title)
        print "\n%s - start bug %s" % (datetime.datetime.now(), bug_id),
        print '"{}"'.format(bug_link)
        # Convert bugzilla to Polarion product and set
        product = PROJ_DICT[bug_product]
        if isRequirementInPolarion(bug_id, product) == False:
            #convert args, for now leave out Priority
            #named_parms["priority"] = PRIOR_DICT[bug_priority]
            named_parms["severity"] = SEV_DICT[bug_severity]
            # Set Polarion requirement type
            named_parms["reqtype"] = "functional"
            
            #Convert DFG name from bugzilla to dfg_id in Polarion
            named_parms["d_f_g"] = convert_polarion_dfg(bug_dfg)
            #Get bug description from first comment and add to Polarion requirement
            desc = ""
            if bug_description:
                desc = Text(bug_description.encode('ascii', 'ignore').decode('ascii'))
                # decode("utf-8"))
                desc.content_type = "text/plain"

            # Add hyperlink to bugzilla
            link = Hyperlink()
            link.role = "ref_ext"
            link.uri = bug_link

            for i in range(0,10): #WA for Polarion disconnection from time to time
                try:
                    req = Requirement.create(project_id=product, title=bug_title, desc=desc, **named_parms)
                    break
                except Exception as inst:
                    print inst
                    i+=1
                    time.sleep(10)

            req.add_hyperlink(link.uri, link.role)
            req.status = "approved"
            req.customerscenario = True
            req.update()

            #[Anjali] one last step here is 'set 'qe-test-coverage' flag in Bugzilla (to show that the bugzilla has a test coverage)
            bz_connection.add_external_tracker(str(bz_rfe.id), str(req.work_item_id), ext_type_description="Polarion Requirement")
            custflag = {'qe_test_coverage': '-'}
            #doesn't matter if we send bugs as a list or not as the method fixes it anyway  
            #this currently does not work it returns an error, so I am disabling it
            #Fault -32000: 'Not an ARRAY reference at /var/www/html/bugzilla/Bugzilla/WebService/Util.pm line 44.\n
            #bz_connection.update_flags([bug_id], custflag)
            
            print "%s - end bug: %s - %s" % (datetime.datetime.now(), req.work_item_id, link.uri)
Esempio n. 5
0
def create_requirement(project_id, title, description="", reqtype="functional", severity="should_have"):

    if True:
        log.warning("No longer creating a requirement automatically")
        return None
    else:
        from pylarion.work_item import Requirement

        req = is_requirement_exists(title)
        if req:
            log.info("Found existing Requirement {}".format(req.title))
            return req
        else:
            log.info("Creating a new Requirement: {}".format(title))
            return Requirement.create(project_id, title, description, severity=severity, reqtype=reqtype)
Esempio n. 6
0
 def setUpClass(cls):
     tc = TestCase.create(DEFAULT_PROJ,
                          "regression",
                          "regression",
                          caseimportance="high",
                          caselevel="component",
                          caseautomation="notautomated",
                          caseposneg="positive",
                          testtype="functional",
                          subtype1="-")
     req = Requirement.create(DEFAULT_PROJ,
                              "regression _link",
                              "regression link",
                              reqtype="functional",
                              severity="should_have")
     cls.work_item_id = tc.work_item_id
     cls.work_item_uri = tc.uri
     cls.work_item_id_2 = req.work_item_id
     cls.work_item_uri_2 = req.uri
Esempio n. 7
0
def fetch_requirement(query, project, collect_only=False):
    """Fetch or create a requirement.

    Return the fetched or created requirement object.
    """
    click.echo(
        'Fetching requirement {0}.'.format(query))
    if query in OBJ_CACHE['requirements'].keys():
        return OBJ_CACHE['requirements'][query]
    requirement = None
    if not collect_only:
        results = Requirement.query(
            query,
            fields=['title', 'work_item_id']
        )
        if len(results) > 0:
            # As currently is not possible to get a single
            # match for the title, make sure to not use a
            # not intended Requirement.
            for result in results:
                if result.title == query or result.work_item_id == query:
                    requirement = result
    if requirement is None:
        click.echo(
            'Creating requirement {0}.'.format(query))
        if not collect_only:
            requirement = Requirement.create(
                project,
                query,
                '',
                reqtype='functional'
            )
            requirement.status = 'approved'
            requirement.update()
    if query not in OBJ_CACHE['requirements'].keys():
        OBJ_CACHE['requirements'][query] = requirement
    return requirement
Esempio n. 8
0
def add_test_case(args):
    """Task that creates or updates Test Cases and manages their Requirement.

    This task relies on ``OBJ_CACHE`` to get the collect_only and project
    objects.

    :param args: A tuple where the first element is a path and the second is a
        list of ``TestFunction`` objects mapping the tests from that path.
    """
    path, tests = args
    collect_only = OBJ_CACHE['collect_only']
    project = OBJ_CACHE['project']

    # Fetch or create a Requirement
    requirement = None
    requirement_name = parse_requirement_name(path)
    click.echo(
        'Fetching requirement {0}.'.format(requirement_name))
    if not collect_only:
        results = Requirement.query(
            '{0}'.format(requirement_name),
            fields=['title', 'work_item_id']
        )
        if len(results) > 0:
            # As currently is not possible to get a single
            # match for the title, make sure to not use a
            # not intended Requirement.
            for result in results:
                if result.title == requirement_name:
                    requirement = result
    if requirement is None:
        click.echo(
            'Creating requirement {0}.'.format(requirement_name))
        if not collect_only:
            requirement = Requirement.create(
                project,
                requirement_name,
                '',
                reqtype='functional'
            )

    for test in tests:
        # Generate the test_case_id. It could be either path.test_name or
        # path.ClassName.test_name if the test methods is defined within a
        # class.
        test_case_id_parts = [
            path.replace('/', '.').replace('.py', ''),
            test.name
        ]
        if test.parent_class is not None:
            test_case_id_parts.insert(-1, test.parent_class)
        test_case_id = '.'.join(test_case_id_parts)

        if test.docstring:
            if not type(test.docstring) == unicode:
                test.docstring = test.docstring.decode('utf8')
            test.docstring = RST_PARSER.parse(test.docstring)

        # Is the test automated? Acceptable values are:
        # automated, manualonly, and notautomated
        auto_status = 'automated' if test.automated else 'notautomated'
        caseposneg = 'negative' if 'negative' in test.name else 'positive'
        setup = test.setup if test.setup else None

        results = []
        if not collect_only:
            results = TestCase.query(
                test_case_id,
                fields=[
                    'caseautomation',
                    'caseposneg',
                    'description',
                    'work_item_id'
                ]
            )
        if len(results) == 0:
            click.echo(
                'Creating test case {0} for requirement {1}.'
                .format(test.name, requirement_name)
            )
            if not collect_only:
                test_case = TestCase.create(
                    project,
                    test.name,
                    test.docstring if test.docstring else '',
                    caseautomation=auto_status,
                    casecomponent='-',
                    caseimportance='medium',
                    caselevel='component',
                    caseposneg=caseposneg,
                    subtype1='-',
                    test_case_id=test_case_id,
                    testtype='functional',
                    setup=setup,
                )
            click.echo(
                'Linking test case {0} to verify requirement {1}.'
                .format(test.name, requirement_name)
            )
            if not collect_only:
                test_case.add_linked_item(
                    requirement.work_item_id, 'verifies')
        else:
            click.echo(
                'Updating test case {0} for requirement {1}.'
                .format(test.name, requirement_name)
            )
            # Ensure that a single match for the Test Case is
            # returned.
            assert len(results) == 1
            test_case = results[0]
            if (not collect_only and
                (test_case.description != test.docstring or
                    test_case.caseautomation != auto_status or
                    test_case.caseposneg != caseposneg or
                    test_case.setup != setup)):
                test_case.description = (
                    test.docstring if test.docstring else '')
                test_case.caseautomation = auto_status
                test_case.caseposneg = caseposneg
                test_case.setup = setup
                test_case.update()
def test_case(path, collect_only, project):
    """Sync test cases with Polarion."""
    testcases = testimony.get_testcases([path])
    for path, tests in testcases.items():
        requirement = None
        for test in tests:
            # Expect test_case_id to be path.test_name or
            # path.ClassName.test_name.
            test_case_id_parts = [
                path.replace('/', '.').replace('.py', ''), test.name
            ]
            if test.parent_class is not None:
                test_case_id_parts.insert(-1, test.parent_class)
            test_case_id = '.'.join(test_case_id_parts)
            if requirement is None:
                requirement_name = parse_requirement_name(test_case_id)
                results = Requirement.query('{0}'.format(requirement_name),
                                            fields=['title', 'work_item_id'])
                if len(results) > 0:
                    # As currently is not possible to get a single
                    # match for the title, make sure to not use a
                    # not intended Requirement.
                    for result in results:
                        if result.title == requirement_name:
                            requirement = result

                if requirement is None:
                    click.echo(
                        'Creating requirement {0}.'.format(requirement_name))
                    if not collect_only:
                        requirement = Requirement.create(project,
                                                         requirement_name,
                                                         '',
                                                         reqtype='functional')

            results = TestCase.query(test_case_id,
                                     fields=['description', 'work_item_id'])
            if len(results) == 0:
                click.echo(
                    'Creating test case {0} for requirement {1}.'.format(
                        test.name, requirement_name))
                if not collect_only:
                    test_case = TestCase.create(
                        project,
                        test.name,
                        test.docstring if test.docstring else '',
                        caseautomation='automated',
                        casecomponent='-',
                        caseimportance='medium',
                        caselevel='component',
                        caseposneg='positive',
                        subtype1='-',
                        test_case_id=test_case_id,
                        testtype='functional',
                    )
                click.echo(
                    'Liking test case {0} to verify requirement {1}.'.format(
                        test.name, requirement_name))
                if not collect_only:
                    test_case.add_linked_item(requirement.work_item_id,
                                              'verifies')
            else:
                click.echo(
                    'Updating test case {0} for requirement {1}.'.format(
                        test.name, requirement_name))
                # Ensure that a single match for the Test Case is
                # returned.
                assert len(results) == 1
                test_case = results[0]
                if (not collect_only
                        and test_case.description != test.docstring):
                    test_case = TestCase(project, test_case.work_item_id)
                    test_case.description = (test.docstring
                                             if test.docstring else '')
                    test_case.update()
def create_requirements(bz_rfes, bz_connection):
    idx = 0

    plan = Plan(project_id=POLARION_PRODUCT, plan_id=POLARION_VERSION)
    req_ids = list()

    # bz_rfe = bz_rfes[0]
    #for x in range(103,127):
    for bz_rfe in bz_rfes:
        #bz_rfe = bz_rfes[x]

        bug_title, named_parms, bug_description, bug_link, bug_id, bug_priority, bug_severity, bug_dfg = get_bug_params(
            bz_rfe)
        print "\n%s - start bug %s" % (datetime.datetime.now(), idx),
        idx += 1
        print '"{}"'.format(bug_link)

        if isRequirementInPolarion(bug_link) == False:

            #TODO Convert bugzilla to Polarion priority and set
            #named_parms["priority"] = convert_polarion_priority(bug_priority)

            # Convert bugzilla to Polarion severity and set
            named_parms["severity"] = convert_polarion_severity(bug_severity)

            # Set Polarion requirement type
            named_parms["reqtype"] = "functional"

            #Cenvert DFG name from bugzilla to dfg_id in Polarion
            named_parms["d_f_g"] = convert_polarion_dfg(bug_dfg)

            #Get bug description from first comment and add to Polarion requirement
            desc = ""
            if bug_description:
                desc = Text(
                    bug_description.encode('ascii', 'ignore').decode('ascii'))
                # decode("utf-8"))
                desc.content_type = "text/plain"

            # Add hyperlink to bugzilla
            link = Hyperlink()
            link.role = "ref_ext"
            link.uri = bug_link

            req = Requirement.create(project_id=POLARION_PRODUCT,
                                     title=bug_title,
                                     desc=desc,
                                     **named_parms)

            req.add_hyperlink(link.uri, link.role)
            req.status = "approved"
            req.update()

            #Get requirement ID and update bugzilla extrenal link tracker
            bz_connection.add_external_tracker(
                str(bz_rfe.id),
                str(req.work_item_id),
                ext_type_description="Polarion Requirement")
            req_ids.append(req.work_item_id)

        print "%s - end bug: %s" % (datetime.datetime.now(), bug_link)

    plan.add_plan_items(req_ids)
Esempio n. 11
0
def test_case(path, collect_only, project):
    """Sync test cases with Polarion."""
    testcases = testimony.get_testcases([path])
    for path, tests in testcases.items():
        requirement = None
        for test in tests:
            # Expect test_case_id to be path.test_name or
            # path.ClassName.test_name.
            test_case_id_parts = [
                path.replace('/', '.').replace('.py', ''),
                test.name
            ]
            if test.parent_class is not None:
                test_case_id_parts.insert(-1, test.parent_class)
            test_case_id = '.'.join(test_case_id_parts)
            if requirement is None:
                requirement_name = parse_requirement_name(test_case_id)
                results = Requirement.query(
                    '{0}'.format(requirement_name),
                    fields=['title', 'work_item_id']
                )
                if len(results) > 0:
                    # As currently is not possible to get a single
                    # match for the title, make sure to not use a
                    # not intended Requirement.
                    for result in results:
                        if result.title == requirement_name:
                            requirement = result

                if requirement is None:
                    click.echo(
                        'Creating requirement {0}.'.format(requirement_name))
                    if not collect_only:
                        requirement = Requirement.create(
                            project,
                            requirement_name,
                            '',
                            reqtype='functional'
                        )

            results = TestCase.query(
                test_case_id, fields=['description', 'work_item_id'])
            if len(results) == 0:
                click.echo(
                    'Creating test case {0} for requirement {1}.'
                    .format(test.name, requirement_name)
                )
                if not collect_only:
                    test_case = TestCase.create(
                        project,
                        test.name,
                        test.docstring if test.docstring else '',
                        caseautomation='automated',
                        casecomponent='-',
                        caseimportance='medium',
                        caselevel='component',
                        caseposneg='positive',
                        subtype1='-',
                        test_case_id=test_case_id,
                        testtype='functional',
                    )
                click.echo(
                    'Liking test case {0} to verify requirement {1}.'
                    .format(test.name, requirement_name)
                )
                if not collect_only:
                    test_case.add_linked_item(
                        requirement.work_item_id, 'verifies')
            else:
                click.echo(
                    'Updating test case {0} for requirement {1}.'
                    .format(test.name, requirement_name)
                )
                # Ensure that a single match for the Test Case is
                # returned.
                assert len(results) == 1
                test_case = results[0]
                if (not collect_only and
                        test_case.description != test.docstring):
                    test_case = TestCase(project, test_case.work_item_id)
                    test_case.description = (
                        test.docstring if test.docstring else '')
                    test_case.update()