def revert_svn():
    proj = Project(Project.default_project)
    proj_grp = proj.project_group.name
    svn_url = "%s/%s/%s" % (proj.repo, proj_grp, proj.project_id)
    LOCAL_DIR = "/tmp/%s" % proj.project_id
    USER = proj.logged_in_user_id
    PASS = proj.session.password
    svn = pysvn.Client()
    svn.set_default_username(USER)
    svn.set_default_password(PASS)
    svn.set_store_passwords(False)
    svn.checkout(svn_url, LOCAL_DIR)
    svn_log = svn.log(LOCAL_DIR)
    #    first_revision = svn_log[-1].revision
    for log in svn_log:
        if log.revision.number == REVERT_TO:
            break
    first_revision = log.revision
    last_revision = svn_log[0].revision
    svn.merge(LOCAL_DIR, last_revision, LOCAL_DIR, first_revision, LOCAL_DIR)
    svn.checkin(LOCAL_DIR, "revert to original version")
    # The original Example template query has an extra colon.
    # After revert, must fix that.
    tmpl = TestRun(project_id=proj.project_id, test_run_id="Example")
    tmpl.query = tmpl.query.replace("::", ":")
    tmpl.update()
Beispiel #2
0
    def update_status_for_run(self,
                              run,
                              status):

        tr = TestRun(run.strip(), None, TestRun.default_project)
        tr.status = status
        tr.update()
        print 'Updated %s status -> %s' % (run, status)
    def update_run(self,
                   run,
                   template=None,
                   plannedin=None,
                   assignee=None,
                   status=None,
                   description=None,
                   is_template=False):

        run = run.strip()
        query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project, run)

        fields = [
            'query', 'created', 'test_run_id', 'select_test_cases_by',
            'status', 'plannedin', 'assignee', 'author'
        ]
        st = TestRun.search(query_ful, fields, 'created', -1, is_template)

        # Update run if exists, otherwise create it.
        if st:
            print('Update the existing run: %s' % run)
            tr = TestRun(run, None, TestRun.default_project)

            # set fields
            if assignee != 'None':
                tr.assignee = assignee
                print('%4sSet Assignee to %s' % ('', assignee))
            if plannedin is not None:
                tr.plannedin = plannedin
                print('%4sSet Plannedin to %s' % ('', plannedin))
            if status is not None:
                tr.status = status
                print('%4sSet Status to %s' % ('', status))
            if description is not None:
                tr.description = description
                print('%4sSet Description to %s' % ('', description))
            tr.update()

        else:
            tr = TestRun.create(TestRun.default_project,
                                run,
                                template,
                                assignee=assignee,
                                plannedin=plannedin,
                                status=status,
                                description=description)
            # display fields
            if assignee != 'None':
                print('%4sSet Assignee to %s' % ('', assignee))
            if plannedin is not None:
                print('%4sSet Plannedin to %s' % ('', plannedin))
            if status is not None:
                print('%4sSet Status to %s' % ('', status))
            if description is not None:
                print('%4sSet Description to %s' % ('', description))
            print('Created %s:' % run)
Beispiel #4
0
 def test_011_customfield_object(self):
     """This test does the following:
     * gets a TestRun
     * Adds a Plan to it
     * Verifies that the plan was added
     * Verifies that a non valid plan cant be added
     """
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     with self.assertRaises(PylarionLibException):
         tr.plannedin = "not_valid"
     tr.plannedin = self.NEW_PLAN
     self.assertEquals(tr.plannedin, self.NEW_PLAN)
     tr.update()
Beispiel #5
0
 def test_008_update(self):
     """This test does the following:
     * gets a TestRun
     * modifies an attribute
     * updates the TestRun
     * reloads the TestRun
     * verifies that the TestRun attribute has changed
     """
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     tr.type = "featureverification"
     tr.update()
     tr.reload()
     self.assertEqual(tr.type, "featureverification")
Beispiel #6
0
    def update_run(self,
                   run,
                   template=None,
                   plannedin=None,
                   assignee=None,
                   is_template=False):

        qrun = run.replace('-', '\-')
        query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project,
                                                 qrun.strip())

        fields = ['query',
                  'created',
                  'test_run_id',
                  'select_test_cases_by',
                  'status',
                  'plannedin',
                  'assignee',
                  'author']
        st = TestRun.search(query_ful,
                            fields,
                            'created',
                            -1,
                            is_template)

        # Update run if exists, otherwise create it.
        if st:
            print 'Update the existing run: %s' % run
            tr = TestRun(run.strip(),
                         None,
                         TestRun.default_project)
        else:
            tr = TestRun.create(TestRun.default_project,
                                run.strip(),
                                template)
            print '\nCreated %s:' % run

        # set customer filed of plannedin
        if plannedin:
            tr.plannedin = plannedin
            print '%4sSet Plannedin to %s' % ('', plannedin)

        if assignee == 'None':
            tr.assignee = TestRun.logged_in_user_id
        else:
            tr.assignee = assignee

        print '%4sSet Assignee to %s' % ('', tr.assignee)
        tr.update()
Beispiel #7
0
def test_run(
        context, path, source_code_path, test_run_id, test_run_type,
        test_template_id, user, custom_fields, project):
    """Execute a test run based on jUnit XML file."""
    custom_fields = load_custom_fields(custom_fields)
    test_run_id = re.sub(INVALID_CHARS_REGEX, '', test_run_id)
    testcases = {
        generate_test_id(test): test.tokens.get('id')
        for test in itertools.chain(
                *testimony.get_testcases([source_code_path]).values()
        )
    }
    results = parse_junit(path)
    try:
        test_run = TestRun(test_run_id, project_id=project)
        click.echo('Test run {0} found.'.format(test_run_id))
    except PylarionLibException as err:
        click.echo(err, err=True)
        click.echo('Creating test run {0}.'.format(test_run_id))
        test_run = TestRun.create(
            project, test_run_id, test_template_id, type=test_run_type,
            **custom_fields)

    update = False
    if test_run.type != test_run_type:
        test_run.type = test_run_type
        update = True
    for field, value in custom_fields.items():
        if getattr(test_run, field) != value:
            setattr(test_run, field, value)
            click.echo(
                'Test Run {0} updated with {1}={2}.'.format(
                    test_run_id, field, value)
            )
            update = True
    if update:
        test_run.update()

    OBJ_CACHE['test_run'] = test_run
    OBJ_CACHE['user'] = user
    OBJ_CACHE['testcases'] = testcases

    TestRun.session.tx_begin()
    pool = multiprocessing.Pool(context.obj['jobs'])
    pool.map(add_test_record, results)
    pool.close()
    pool.join()
    TestRun.session.tx_commit()