How to use _serialize_response method in localstack

Best Python code snippet using localstack_python

broadcast_details.py

Source:broadcast_details.py Github

copy

Full Screen

...28 def _get_validator(self, request):29 if is_active_superuser(request):30 return AdminBroadcastValidator31 return BroadcastValidator32 def _serialize_response(self, request, broadcast):33 if is_active_superuser(request):34 serializer_cls = AdminBroadcastSerializer35 else:36 serializer_cls = BroadcastSerializer37 return self.respond(serialize(broadcast, request.user, serializer=serializer_cls()))38 def get(self, request, broadcast_id):39 broadcast = self._get_broadcast(request, broadcast_id)40 return self._serialize_response(request, broadcast)41 def put(self, request, broadcast_id):42 broadcast = self._get_broadcast(request, broadcast_id)43 validator = self._get_validator(request)(data=request.data, partial=True)44 if not validator.is_valid():45 return self.respond(validator.errors, status=400)46 result = validator.validated_data47 update_kwargs = {}48 if result.get('title'):49 update_kwargs['title'] = result['title']50 if result.get('message'):51 update_kwargs['message'] = result['message']52 if result.get('link'):53 update_kwargs['link'] = result['link']54 if result.get('isActive') is not None:55 update_kwargs['is_active'] = result['isActive']56 if result.get('dateExpires', -1) != -1:57 update_kwargs['date_expires'] = result['dateExpires']58 if update_kwargs:59 with transaction.atomic():60 broadcast.update(**update_kwargs)61 logger.info('broadcasts.update', extra={62 'ip_address': request.META['REMOTE_ADDR'],63 'user_id': request.user.id,64 'broadcast_id': broadcast.id,65 'data': update_kwargs,66 })67 if result.get('hasSeen'):68 try:69 with transaction.atomic():70 BroadcastSeen.objects.create(71 broadcast=broadcast,72 user=request.user,73 )74 except IntegrityError:75 pass...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

2from flask import Flask, json, request, render_template, Response, send_from_directory3from ga4gh.schemas import protocol4import ncbi5app = Flask(__name__, static_url_path='')6def _serialize_response(response_proto):7 return Response(8 protocol.toJson(response_proto), mimetype='application/json')9@app.route('/')10def index():11 return render_template('index.html', request=request)12def search_datasets(request):13 """14 Mock Function15 """16 dataset_list = []17 for i in xrange(10):18 dataset = protocol.Dataset()19 dataset.id = str(i)20 dataset.name = "Hi there"21 dataset_list.append(dataset)22 return (dataset_list, "0:0")23def search_read_group_sets(request):24 """25 Mock function26 """27 read_group_set_list = []28 for i in xrange(10):29 read_group_set = protocol.ReadGroupSet()30 read_group_set.id = str(i)31 read_group_set.name = "Hi there"32 read_group_set_list.append(read_group_set)33 return (read_group_set_list, "somepagetoken")34def search_reads(request):35 """36 Mock function37 """38 alignments = []39 for i in xrange(10):40 ga_alignment = protocol.ReadAlignment()41 ga_alignment.id = str(i)42 ga_alignment.alignment.position.position = 123 + i43 alignments.append(ga_alignment)44 return (alignments, "tokentoken")45@app.route('/datasets/search', methods=['POST'])46def search_datasets_route():47 search_request = protocol.SearchDatasetsRequest48 try:49 deserialized_request = protocol.fromJson(request.get_data(), search_request)50 except Exception, e:51 print str(e)52 dataset_list = ncbi.search_datasets(deserialized_request)53 response_proto = protocol.SearchDatasetsResponse()54 response_proto.datasets.extend(dataset_list)55 return _serialize_response(response_proto)56@app.route('/readgroupsets/search', methods=['POST'])57def search_read_group_sets_route():58 search_request = protocol.SearchReadGroupSetsRequest59 try:60 deserialized_request = protocol.fromJson(request.get_data(), search_request)61 except Exception, e:62 print str(e)63 read_group_set_list = ncbi.search_read_group_sets(deserialized_request)64 response_proto = protocol.SearchReadGroupSetsResponse()65 response_proto.read_group_sets.extend(read_group_set_list)66 return _serialize_response(response_proto)67@app.route('/reads/search', methods=['POST'])68def search_reads_route():69 search_request = protocol.SearchReadsRequest70 try:71 deserialized_request = protocol.fromJson(request.get_data(), search_request)72 except Exception, e:73 print str(e)74 alignment_list = ncbi.search_reads(deserialized_request)75 response_proto = protocol.SearchReadsResponse()76 response_proto.alignments.extend(alignment_list)77 return _serialize_response(response_proto)78def run_server():79 app.run(debug=True)80def get_app():81 return app82if __name__ == '__main__':...

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