Browse Source

Run TestRun on Local system functionality.

Akash 3 years ago
parent
commit
6ff770a214
3 changed files with 923 additions and 841 deletions
  1. 45 3
      api/app/api.py
  2. 128 128
      files/app/routes.py
  3. 750 710
      ui/app/views.py

+ 45 - 3
api/app/api.py

@@ -9,7 +9,10 @@ from rq.job import Job
 #from baangt.base.DataBaseORM import TestrunLog, DATABASE_URL
 from baangt.base.DataBaseORM import engine, TestrunLog
 from sqlalchemy.orm import sessionmaker
-
+import datetime
+import pickle
+from baangt.base.ExportResults.ExportResults import ExportResults
+from baangt.base.PathManagement import ManagedPaths
 #db_session = init_db()
 
 @app.route('/')
@@ -105,8 +108,8 @@ def get_testrun(uuid_str):
 			return jsonify(jsonResponse), 400	
 	except Exception as e:
 		app.logger.error(f'{e}')
-		jsonResponse['error'] = 'Testrun does not exist.'
-		return jsonify(jsonResponse), 404
+		jsonResponse['error'] = 'Testrun does not exist! If you are running it on your local system then please wait for completion of the run.'
+		return jsonify(jsonResponse), 202
 
 	return jsonify(jsonResponse), 202
 	
@@ -129,10 +132,49 @@ def uploads(filename):
 			'/'.join((app.config['UPLOAD_FOLDER'], filename)),
 			attachment_filename=filename,
 			as_attachment=True,
+			mimetype='application/vnd.ms-excel',
 		)
 
 	return send_file(
 			'/'.join((app.config['UPLOAD_FOLDER'], filename)),
 			attachment_filename=f'{filename}.xlsx',
 			as_attachment=True,
+			mimetype='application/vnd.ms-excel',
 		)
+
+@app.route(f'/{app.config["API_BASE"]}/results/update/<string:testRunId>', methods=["POST"])
+def update_testRunResult(testRunId):
+	data = request.get_json(testRunId)
+	ordt = data.copy()
+	try:
+		session = sessionmaker(bind=engine)()
+		#data["id"] = uuid.UUID(data["id"]).bytes
+		tr = TestrunLog(
+			id = uuid.UUID(data["id"]).bytes,
+			testrunName = data["testrunName"],
+			logfileName = data["logfileName"],
+			startTime = datetime.datetime.now(),
+			endTime = datetime.datetime.now(),
+			dataFile = data["dataFile"],
+			statusOk = data["statusOk"],
+			statusFailed = data["statusFailed"],
+			statusPaused = data["statusPaused"],
+			RLPJson = data["RLPJson"],
+		)
+		session.add(tr)
+		session.commit()
+		return jsonify({"update": "success"}), 200
+	except Exception as ex:
+		dat = {"ex": str(ex), "data": ordt}
+		return jsonify(dat), 200
+
+@app.route(f"/exportresults", methods=["POST"])
+def export_result():
+	try:
+		data = pickle.loads(request.data)
+		data["TESTRUNINSTANCE"].managedPaths = ManagedPaths() 
+		results = ExportResults(**data)
+		return send_file(results.fileName, attachment_filename=results.fileName, mimetype='application/vnd.ms-excel', as_attachment=True), 200
+	except Exception as ex:
+		data = {"results": str(ex)}
+		return jsonify(data), 200

+ 128 - 128
files/app/routes.py

@@ -1,128 +1,128 @@
-from flask import request, render_template, send_from_directory, jsonify, send_file, abort
-from app import app, forms
-from uuid import uuid4
-import os
-
-
-@app.route('/', methods=['GET', 'POST'])
-def index():
-	#
-	# web view to upload data files
-	#
-	
-	form = forms.UploadForm()
-	
-	# get validated form
-	if form.validate_on_submit():
-		# save file
-		uuid = str(uuid4())
-		form.file.data.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
-		app.logger.info(f'Uploaded file {uuid}')
-
-		return render_template('upload.html', form=form, uuid=uuid, filename=form.file.data.filename)
-
-	return render_template('upload.html', form=form)
-
-@app.route('/save', methods=['POST'])
-def save_file():
-	#
-	# save uploaded file and return corresponding UUID
-	#
-
-	# check for file in request
-	file = request.files.get('dataFile')
-
-	if file is None:
-		app.logger.error('Request does not contain dataFile')
-		return jsonify({'error': 'Request does not contain dataFile'}), 400
-
-	# save file
-	uuid = str(uuid4())
-	file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
-	app.logger.info(f'Uploaded file {uuid}')
-
-	return jsonify({'uuid': uuid}), 200
-
-@app.route('/update/<string:uuid>', methods=['POST'])
-def update_file(uuid):
-	#
-	# update UUID file by uploaded one and return corresponding UUID
-	#
-
-	# check for file in request
-	file = request.files.get('dataFile')
-
-	if file is None:
-		app.logger.error('Request does not contain dataFile')
-		return jsonify({'error': 'Request does not contain dataFile'}), 400
-
-	# update file
-	file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
-	app.logger.info(f'Updated file {uuid}')
-
-	return jsonify({'uuid': uuid}), 200
-
-@app.route('/upload/<string:uuid>', methods=['POST'])
-def upload_files(uuid):
-	#
-	# save uploaded files to directory 'UUID'
-	#
-
-	if not request.files:
-		app.logger.error('Request does not contain files to upload')
-		return jsonify({'error': 'Request does not contain files to upload'}), 400
-
-	# create upload dir
-	upload_dir = os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid)
-	os.makedirs(upload_dir, exist_ok=True)
-	app.logger.info(f'Created directory: {upload_dir}')
-
-	# save files
-	upload_response = {}
-	for filename, file in request.files.items():
-		file.save(os.path.join(upload_dir, filename))
-		upload_response['filename'] = 'OK'
-		app.logger.info(f'Uploaded file {filename} to {upload_dir}')
-
-	return jsonify({'uuid': uuid, 'files': upload_response}), 200
-
-@app.route('/get/<string:uuid>/<string:file>')
-def get_logfile(uuid, file):
-	#
-	# retrieve files from folder UUID
-	#
-	
-	# log file
-	if file == app.config['TESTRUN_LOGFILE']:
-		app.logger.info(f'Requested logfile from {uuid}')
-		return send_file(
-			'/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_LOGFILE'])),
-			mimetype='text/plain',
-			attachment_filename=f'{uuid}.log',
-		)
-
-	# redults file
-	elif file == app.config['TESTRUN_RESULTS']:
-		app.logger.info(f'Requested output file from {uuid}')
-		return send_file(
-			'/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_RESULTS'])),
-			attachment_filename=f'{uuid}.xlsx',
-			as_attachment=True,
-		)
-
-	abort(404)
-
-
-@app.route('/get/<string:uuid>')
-def get_file(uuid):
-	#
-	# retrieve a file by UUID
-	#
-
-	app.logger.info(f'Requested file {uuid}')
-	#return send_from_directory(app.config['UPLOAD_FOLDER'], uuid)
-	return send_file(
-		'/'.join((app.config['UPLOAD_FOLDER'], uuid)),
-		attachment_filename=f'{uuid}.xlsx',
-		as_attachment=True,
-	)
+from flask import request, render_template, send_from_directory, jsonify, send_file, abort
+from app import app, forms
+from uuid import uuid4
+import os
+
+
+@app.route('/', methods=['GET', 'POST'])
+def index():
+	#
+	# web view to upload data files
+	#
+	
+	form = forms.UploadForm()
+	
+	# get validated form
+	if form.validate_on_submit():
+		# save file
+		uuid = str(uuid4())
+		form.file.data.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
+		app.logger.info(f'Uploaded file {uuid}')
+
+		return render_template('upload.html', form=form, uuid=uuid, filename=form.file.data.filename)
+
+	return render_template('upload.html', form=form)
+
+@app.route('/save', methods=['POST'])
+def save_file():
+	#
+	# save uploaded file and return corresponding UUID
+	#
+
+	# check for file in request
+	file = request.files.get('dataFile')
+
+	if file is None:
+		app.logger.error('Request does not contain dataFile')
+		return jsonify({'error': 'Request does not contain dataFile'}), 400
+
+	# save file
+	uuid = str(uuid4())
+	file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
+	app.logger.info(f'Uploaded file {uuid}')
+
+	return jsonify({'uuid': uuid}), 200
+
+@app.route('/update/<string:uuid>', methods=['POST'])
+def update_file(uuid):
+	#
+	# update UUID file by uploaded one and return corresponding UUID
+	#
+
+	# check for file in request
+	file = request.files.get('dataFile')
+
+	if file is None:
+		app.logger.error('Request does not contain dataFile')
+		return jsonify({'error': 'Request does not contain dataFile'}), 400
+
+	# update file
+	file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
+	app.logger.info(f'Updated file {uuid}')
+
+	return jsonify({'uuid': uuid}), 200
+
+@app.route('/upload/<string:uuid>', methods=['POST'])
+def upload_files(uuid):
+	#
+	# save uploaded files to directory 'UUID'
+	#
+
+	if not request.files:
+		app.logger.error('Request does not contain files to upload')
+		return jsonify({'error': 'Request does not contain files to upload'}), 400
+
+	# create upload dir
+	upload_dir = os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid)
+	os.makedirs(upload_dir, exist_ok=True)
+	app.logger.info(f'Created directory: {upload_dir}')
+
+	# save files
+	upload_response = {}
+	for filename, file in request.files.items():
+		file.save(os.path.join(upload_dir, filename))
+		upload_response['filename'] = 'OK'
+		app.logger.info(f'Uploaded file {filename} to {upload_dir}')
+
+	return jsonify({'uuid': uuid, 'files': upload_response}), 200
+
+@app.route('/get/<string:uuid>/<string:file>')
+def get_logfile(uuid, file):
+	#
+	# retrieve files from folder UUID
+	#
+	
+	# log file
+	if file == app.config['TESTRUN_LOGFILE']:
+		app.logger.info(f'Requested logfile from {uuid}')
+		return send_file(
+			'/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_LOGFILE'])),
+			mimetype='text/plain',
+			attachment_filename=f'{uuid}.log',
+		)
+
+	# redults file
+	elif file == app.config['TESTRUN_RESULTS']:
+		app.logger.info(f'Requested output file from {uuid}')
+		return send_file(
+			'/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_RESULTS'])),
+			attachment_filename=f'{uuid}.xlsx',
+			as_attachment=True,
+		)
+
+	abort(404)
+
+
+@app.route('/get/<string:uuid>')
+def get_file(uuid):
+	#
+	# retrieve a file by UUID
+	#
+
+	app.logger.info(f'Requested file {uuid}')
+	#return send_from_directory(app.config['UPLOAD_FOLDER'], uuid)
+	return send_file(
+		'/'.join((app.config['UPLOAD_FOLDER'], uuid)),
+		attachment_filename=f'{uuid}.xlsx',
+		as_attachment=True,
+	)

File diff suppressed because it is too large
+ 750 - 710
ui/app/views.py