Exemplo n.º 1
0
def downloadTestartifactById(testartifactId):
    if not isinstance(testartifactId, int):
        r = Response(response=f"Invalid Id: {testartifactId}",
                     status='422',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    testartifact = dbtestartifacts.getTestartifact(testartifactId, False)

    if not testartifact:
        r = Response(response=f"No testartifact with Id: {testartifactId}",
                     status='404',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    project = getProject(testartifact.project_id)

    if not project:
        r = Response(response=f"No project with Id: {testartifact.project_id}",
                     status='404',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    zipFilePath = f"{project.project_path}Artifact"

    shutil.make_archive(zipFilePath, 'zip',
                        f"{project.project_path}testartifacts{os.path.sep}")

    return send_file(f"{zipFilePath}.zip",
                     as_attachment=True,
                     attachment_filename='Artifact.zip')
Exemplo n.º 2
0
def getProjectById(projectId):
    """
    Handler function to return a Project with given Id

    Args:
        -projectId (int) : Id of Project to return
    """

    if not isinstance(projectId, int):
        r = Response(response='{}{}'.format('Invalid Id: ', projectId),
                     status='422',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    project = dbprojects.getProject(projectId)

    if not project:
        r = Response(response='{}{}'.format('No project with Id: ', projectId),
                     status='404',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    r = Response(response=json.dumps(project.to_dict()),
                 status='200',
                 mimetype="text/json")
    r.headers["Content-Type"] = "application/json; charset=utf-8"
    return r
Exemplo n.º 3
0
def createTestartifact(postRequest: POSTTestartifacts):
    """
    Creates Testartifacts for a Project
    """
    r = Response()

    try:
        # --------------------------------------|
        # GET/UPDATE RELATED DATA
        if not isinstance(postRequest.project_id, int):
            r = Response(response=f"Invalid Id: {postRequest.project_id}",
                         status='422',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        project = getProject(postRequest.project_id)

        if not project:
            r = Response(
                response=f"No project with Id: {postRequest.project_id}",
                status='404',
                mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        project.status = 'TAGENERATED'

        updateProject(project)

        # --------------------------------------|
        # OBJECT CREATION
        testartifact = Testartifact(
            status=project.status,
            project_id=project.id,
        )
        databaseSession.add(testartifact)
        databaseSession.flush()
        # --------------------------------------|
        # GENERATE OPERATION
        generate.run(project, testartifact)
        # --------------------------------------|

        newTestartifact = dbtestartifacts.getTestartifactForProject(
            project, True)

        r = Response(response=json.dumps(newTestartifact.to_dict()),
                     status='201',
                     mimetype="application/json")
        r.headers["Content-Type"] = "application/json; charset=utf-8"

        databaseSession.commit()
    except:
        databaseSession.rollback()
        raise
    finally:
        databaseSession.remove()

    return r
Exemplo n.º 4
0
def downloadResultById(resultId):
    """
    Sends the resultfile of a result back to the requester.

    Args:
        - resultId (int) : Id of result to download resultfile from
    """

    if not isinstance(resultId, int):
        r = Response(response=f"Invalid Id: {resultId}",
                     status='422',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    result = dbresults.getResult(resultId)

    if not result:
        r = Response(response=f"No result with Id: {resultId}",
                     status='404',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    project = getProject(result.project_id)

    if not project:
        r = Response(response=f"No project with Id: {result.project_id}",
                     status='404',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    zipTargetDir = f"{project.project_path}results"
    zipResultFile = f"{project.project_path}results.zip"

    shutil.make_archive(zipTargetDir, 'zip', zipTargetDir)

    return send_file(zipResultFile,
                     as_attachment=True,
                     attachment_filename="Results.zip")
Exemplo n.º 5
0
def createDeployment(postRequest: POSTDeployments):
    r = Response()

    try:
        # --------------------------------------|
        # GET/UPDATE RELATED DATA
        if not isinstance(postRequest.testartifact_id, int):
            r = Response(response='{}{}'.format('Invalid Id: ',
                                                postRequest.testartifact_id),
                         status='422',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        testartifact = getTestartifact(postRequest.testartifact_id, True)

        if not testartifact:
            r = Response(response='{}{}'.format('No testartifact with Id: ',
                                                postRequest.testartifact_id),
                         status='404',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        project = getProject(testartifact.project_id)

        if not project:
            r = Response(response='{}{}'.format('No project with Id: ',
                                                testartifact.project_id),
                         status='404',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        testartifact.status = 'DEPLOYED'
        project.status = 'DEPLOYED'

        updateTestartifact(testartifact)
        updateProject(project)

        # --------------------------------------|
        # OBJECT CREATION
        deployment = Deployment(
            status='DEPLOYED',
            project_id=project.id,
            testartifact_id=testartifact.id,
        )

        databaseSession.add(deployment)
        databaseSession.flush()
        # --------------------------------------|
        # DEPLOY OPERATION
        deploy.run(project, testartifact)
        # --------------------------------------|

        r = Response(response=json.dumps(deployment.to_dict()),
                     status='201',
                     mimetype="application/json")
        r.headers["Content-Type"] = "application/json; charset=utf-8"

        databaseSession.commit()
    except:
        databaseSession.rollback()
        raise
    finally:
        databaseSession.remove()

    return r
Exemplo n.º 6
0
def createExecutor(postRequest: POSTExecutors):
    r = Response()

    try:
        # --------------------------------------|
        # GET/UPDATE RELATED DATA
        if not isinstance(postRequest.deployment_id, int):
            r = Response(response='{}{}'.format('Invalid Id: ',
                                                postRequest.deployment_id),
                         status='422',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        deployment = getDeployment(postRequest.deployment_id)

        if not deployment:
            r = Response(response='{}{}'.format('No deployment with Id: ',
                                                postRequest.deployment_id),
                         status='404',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        testartifact = getTestartifact(deployment.testartifact_id, True)

        if not testartifact:
            r = Response(response='{}{}'.format('No testartifact with Id: ',
                                                deployment.testartifact_id),
                         status='404',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        project = getProject(deployment.project_id)

        if not project:
            r = Response(response='{}{}'.format('No project with Id: ',
                                                deployment.project_id),
                         status='404',
                         mimetype="text/xml")
            r.headers["Content-Type"] = "text/xml; charset=utf-8"
            return r

        project.status = 'EXECUTED'
        testartifact.status = 'EXECUTED'
        deployment.status = 'EXECUTED'

        updateProject(project)
        updateTestartifact(testartifact)
        updateDeployment(deployment)

        # --------------------------------------|
        # OBJECT CREATION
        executor = Executor(
            status='EXECUTED',
            project_id=project.id,
            deployment_id=deployment.id,
        )
        databaseSession.add(executor)
        databaseSession.flush()

        result = Result(
            project_id=project.id,
            testartifact_id=testartifact.id,
            result_path=f"{project.project_path}results{os.path.sep}report.csv",
        )
        databaseSession.add(result)
        databaseSession.flush()
        # --------------------------------------|
        # EXECUTE OPERATION
        execute.run(project, deployment, testartifact)
        # --------------------------------------|
        # EVALUATE OPERATION
        evaluate.run(project, testartifact, result)
        # --------------------------------------|

        r = Response(response=json.dumps(result.to_dict()),
                     status='201',
                     mimetype="application/json")
        r.headers["Content-Type"] = "application/json; charset=utf-8"

        databaseSession.commit()
    except:
        databaseSession.rollback()
        raise
    finally:
        databaseSession.remove()

    return r