How to use assert_image_exists method in ATX

Best Python code snippet using ATX

ImageManager.py

Source:ImageManager.py Github

copy

Full Screen

...49@image.route('/image/<imageid>', methods=['GET'])50def get_image(imageid):51 try:52 init_tenant_context(request, db, minioClient)53 orm_image = assert_image_exists(imageid)54 result = image_schema.dump(orm_image)55 return make_response(jsonify(result), 200)56 except HTTPRequestError as e:57 if isinstance(e.message, dict):58 return make_response(jsonify(e.message), e.error_code)59 else:60 return format_response(e.error_code, e.message)61@image.route('/image/<imageid>/binary', methods=['GET'])62def get_image_binary(imageid):63 try:64 tenant = init_tenant_context(request, db, minioClient)65 orm_image = assert_image_exists(imageid)66 filename = imageid + '.hex'67 if not orm_image.confirmed:68 raise HTTPRequestError(404, "Image does not have an binary file")69 minioClient.fget_object(tenant, filename, os.path.join('/tmp/', filename))70 return send_from_directory(directory='/tmp/', filename=filename)71 except HTTPRequestError as e:72 if isinstance(e.message, dict):73 return make_response(jsonify(e.message), e.error_code)74 else:75 return format_response(e.error_code, e.message)76@image.route('/image/<imageid>', methods=['DELETE'])77def delete_image(imageid):78 try:79 tenant = init_tenant_context(request, db, minioClient)80 orm_image = assert_image_exists(imageid)81 data = image_schema.dump(orm_image)82 if orm_image.confirmed:83 minioClient.remove_object(tenant, imageid + '.hex')84 db.session.delete(orm_image)85 db.session.commit()86 result ={'result': 'ok', 'removed_image': data}87 return make_response(jsonify(result), 200)88 except HTTPRequestError as e:89 if isinstance(e.message, dict):90 return make_response(jsonify(e.message), e.error_code)91 else:92 return format_response(e.error_code, e.message)93@image.route('/image/<imageid>/binary', methods=['DELETE'])94def delete_image_binary(imageid):95 try:96 tenant = init_tenant_context(request, db, minioClient)97 orm_image = assert_image_exists(imageid)98 minioClient.remove_object(tenant, imageid + '.hex')99 orm_image.confirmed = False100 db.session.commit()101 return make_response(jsonify({'result': 'ok'}), 200)102 except HTTPRequestError as e:103 if isinstance(e.message, dict):104 return make_response(jsonify(e.message), e.error_code)105 else:106 return format_response(e.error_code, e.message)107@image.route('/image/', methods=['POST'])108def create_image():109 """ Creates and configures the given image (in json) """110 try:111 tenant = init_tenant_context(request, db, minioClient)112 image_data, json_payload = parse_json_payload(request, image_schema)113 imageid = str(uuid.uuid4())114 image_data['id'] = imageid115 orm_image = Image(**image_data)116 db.session.add(orm_image)117 try:118 db.session.commit()119 except IntegrityError as error:120 handle_consistency_exception(error)121 else:122 result = {123 "id": orm_image.id,124 "label": orm_image.label,125 "published_at": orm_image.created,126 "url": '/image/' + imageid127 }128 return make_response(jsonify(result), 201, {'location': '/image/' + imageid})129 except HTTPRequestError as e:130 if isinstance(e.message, dict):131 return make_response(jsonify(e.message), e.error_code)132 else:133 return format_response(e.error_code, e.message)134@image.route('/image/<imageid>/binary', methods=['POST'])135def upload_image(imageid):136 try:137 tenant = init_tenant_context(request, db, minioClient)138 orm_image = assert_image_exists(imageid)139 if orm_image.confirmed:140 raise HTTPRequestError(400, "Binary already exists")141 orm_image.confirmed = True142 file_data = parse_form_payload(request)143 for f in file_data:144 print(f)145 extension = file_data.filename.rsplit('.', 1)[1].lower()146 filename = imageid + '.' + extension147 file_data.seek(0)148 file_data.save(os.path.join('/tmp/', filename))149 try:150 minioClient.fput_object(tenant, filename, os.path.join('/tmp/', filename))151 orm_image.confirmed = True152 db.session.commit()...

Full Screen

Full Screen

invoke_test.py

Source:invoke_test.py Github

copy

Full Screen

...29def assert_fatal(condition, error):30 if not condition:31 sys.stdout.write("[error] %s\n" % error)32 sys.exit(1)33def assert_image_exists(name, path):34 assert_fatal(os.path.isfile(path), "%s image %s does not exist." % (name, path))35def compareImages(image0,image1,dimage):36 error = float("inf")37 assert_image_exists("output", image0)38 assert_image_exists("reference", image1)39 line, unused_err = subprocess.Popen("compare -metric MAE "+image0+" "+image1+" -compose Src "+dimage, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True).communicate()40 try: error = float(line[line.index('(')+1:line.index(')')])41 except ValueError:42 print("Error: "+line)43 raise ValueError44 return error45def printUsage():46 sys.stderr.write('Usage: ' + sys.argv[0] + ' --name testname --modeldir path --model path/model.ecs --execute executable args\n')47 sys.exit(1)48def parseArgs(argv):49 global name50 global model51 global reference52 global modeldir...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful