How to use create_request_validator method in localstack

Best Python code snippet using localstack_python

test_validators.py

Source:test_validators.py Github

copy

Full Screen

...199 ["cookie", RequestCookiesValidator],200 ["path", RequestPathValidator],201 ["query", RequestQueryValidator]202])203def test_create_request_validator(parameter_location: str, expected_type: Type) -> None:204 validator = create_request_validator(parameter_location, None)...

Full Screen

Full Screen

request.py

Source:request.py Github

copy

Full Screen

1from flask import Blueprint, jsonify2from model import Request, Header, db, User, create_request_validator, update_request_validator, request_schema, requests_schema, Project3from decorators import token_required, load_data4request_api = Blueprint('request_api', __name__)5@request_api.route('/api/v1/projects/<project_id>/requests', methods=['GET'])6@token_required7def get_project_requests(current_user, project_id):8 """Devolver todas las requests."""9 project = Project.query.filter_by(project_id=project_id).first()10 if not project:11 return jsonify({'message': 'No project found!'}), 40412 if current_user != project.user:13 return jsonify({'message': 'You don\'t have permission to access these requests!'}), 40314 the_requests = project.requests15 output = requests_schema.dump(the_requests)16 data = output.data17 data.sort(key=lambda x: x["name"].lower())18 return jsonify({"requests": data})19@request_api.route('/api/v1/requests/<request_id>', methods=['GET'])20@token_required21def get_one_request(current_user, request_id):22 """Devuelve una request."""23 one_request = Request.query.filter_by(request_id=request_id).first()24 if not one_request:25 return jsonify({'message': 'No request found!'}), 40426 if current_user != one_request.project.user:27 return jsonify({'message': 'You don\'t have permission to access that request!'}), 40328 return jsonify({'request': request_schema.dump(one_request).data})29@request_api.route('/api/v1/projects/<project_id>/requests', methods=['POST'])30@token_required31@load_data32def create_request(data, current_user: User, project_id):33 """Crea una request."""34 project = Project.query.filter_by(project_id=project_id).first()35 if not project:36 return jsonify({'message': 'No project found!'}), 40437 if current_user != project.user:38 return jsonify({'message': 'You don\'t have permission to create a request in that project!'}), 40339 if create_request_validator.validate(data):40 for req in project.requests:41 if req.name == data['name']:42 return jsonify({'message': 'A request with that name already exists'}), 40943 one_request = Request(**data)44 db.session.add(one_request)45 project.requests.append(one_request)46 db.session.commit()47 return jsonify({'message': 'New request created!', 'request': request_schema.dump(one_request).data})48 else:49 return jsonify({'message': 'Request not created!', 'errors': create_request_validator.errors}), 40050@request_api.route('/api/v1/requests/<request_id>', methods=['DELETE'])51@token_required52def delete_request(current_user, request_id):53 """Devuelve una request."""54 one_request = Request.query.filter_by(request_id=request_id).first()55 if not one_request:56 return jsonify({'message': 'No request found!'}), 40457 if current_user != one_request.project.user:58 return jsonify({'message': 'You don\'t have permission to delete that request!'}), 40359 db.session.delete(one_request)60 db.session.commit()61 return jsonify({'message': 'The request has been deleted!'})62@request_api.route('/api/v1/requests/<request_id>', methods=['POST'])63@token_required64@load_data65def update_request(data, current_user, request_id):66 """Actualiza una request."""67 one_request = Request.query.filter_by(request_id=request_id).first()68 if not one_request:69 return jsonify({'message': 'No request found!'}), 40470 if current_user != one_request.project.user:71 return jsonify({'message': 'You don\'t have permission to update that request!'}), 40372 if update_request_validator.validate(data):73 # no actualizar si ya existe una request con ese nombre74 if Request.query.filter(Request.name == data['name'], Request.request_id != one_request.request_id).first():75 return jsonify({'message': 'A request with that name already exists'}), 40976 # eliminar las header anteriores77 for previous_header in one_request.headers:78 db.session.delete(previous_header)79 # rellenar datos de la header80 for key, value in data.items():81 # añadir directamente los campos que no sean las headers82 if key != "headers":83 setattr(one_request, key, value)84 # gestionar las headers85 else:86 # crear las nuevas headers87 for new_header_data in value:88 header = Header(**new_header_data)89 one_request.headers.append(header)90 db.session.commit()91 return jsonify({'message': 'Request updated!', 'request': request_schema.dump(one_request).data})92 else:...

Full Screen

Full Screen

middleware.py

Source:middleware.py Github

copy

Full Screen

...84 merged_parameters[location]["required"] = []85 merged_parameters[location]["required"].append(name)86 for location, schema in merged_parameters.items():87 if location in self.validators and self.validators[location]:88 validators.append(create_request_validator(location, schema))...

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 localstack 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