Exemple #1
0
def get_tps_report(project_name, release_name, testplan_name):
    """Get all summary of all the testruns run against a particular build."""
    project_id, release_id, _ = Project.lookup_project_release_build_ids(project_name, release_name, None)
    testplan = TestPlan.objects(project__id=project_id, name=testplan_name)
    if len(testplan) > 0:
        testplan = testplan[0]
        report = TestrunGroup()
        report.name = "{} Summary for {}".format(testplan_name, release_name)
        report.grouptype = "SERIAL"
        report.testruns = []
        report.testruns.extend(Testrun.objects(project__id=project_id, release__releaseId=release_id, testplanId=testplan.id).order_by('-dateCreated').limit(50))
        report.testruns.reverse()

        return JsonResponse(report)
    else:
        return JsonResponse({})
Exemple #2
0
def update_testplan(testplan_id):
    """Update an existing testplan's properties."""
    orig = TestPlan.objects(id=testplan_id).first()
    deserialize_that(read_request(), orig)
    orig.save()
    return JsonResponse(orig)
Exemple #3
0
def get_testplan_by_id(testplan_id):
    """Get a specific testplan by it's id."""
    return JsonResponse(TestPlan.objects(id=testplan_id).first())
Exemple #4
0
def add_testrun():
    """Create a new testrun."""
    project_name = None
    release_name = None
    build_name = None
    raw = read_request()
    new_tr = deserialize_that(raw, Testrun())
    proj_id = None

    # resolve project, release and build, create if necessary
    if is_provided(new_tr, 'project'):
        project_name = new_tr.project.name
    if is_provided(new_tr, 'release'):
        release_name = new_tr.release.name
    if is_provided(new_tr, 'build'):
        build_name = new_tr.build.name

    if project_name is not None or release_name is not None or build_name is not None:
        # we have something to lookup / create
        proj_id, rel_id, bld_id = Project.lookup_project_release_build_ids(project_name, release_name, build_name,
                                                                           create_if_missing=True)
        if proj_id is not None:
            new_tr.project.id = proj_id
        if rel_id is not None:
            new_tr.release.releaseId = rel_id
        if bld_id is not None:
            new_tr.build.buildId = bld_id

    # if testplanId not provided, but testplan object is, resolve creating if necessary
    if is_not_provided(new_tr, 'testplanId') and 'testplan' in raw:
        tplan = TestPlan()
        tplan = deserialize_that(raw['testplan'], tplan)
        """:type : TestPlan"""

        query = {'name': tplan.name}
        if proj_id is not None:
            query['project__id'] = proj_id
        existing_plan = TestPlan.objects(**query).first()
        if existing_plan is not None:
            new_tr.testplanId = existing_plan.id
        else:
            if proj_id is not None:
                tplan.project = ProjectReference()
                tplan.project.id = proj_id
                tplan.project.name = new_tr.project.name
                tplan.save()
                new_tr.testplanId = tplan.id

    if is_not_provided(new_tr, 'dateCreated'):
        new_tr.dateCreated = datetime.datetime.utcnow()
    if is_not_provided(new_tr, 'info') and is_provided(new_tr, 'build') and \
            is_provided(new_tr, 'project') and is_provided(new_tr, 'release'):
        project = get_project(new_tr.project.name)
        build = None
        if project is None:
            project = get_project(new_tr.project.id)
        if project is not None:
            release = get_release(project, new_tr.release.name)
            if release is None:
                release = get_release(project, new_tr.release.releaseId)
            if release is not None:
                build = get_build(release, new_tr.build.name)
                if build is None:
                    build = get_build(release, new_tr.build.buildId)
        if build is not None and is_provided(build, 'description'):
            new_tr.info = build.description

    new_tr.save()
    # add an event
    events.CreateEvent(new_tr)

    return JsonResponse(new_tr)