How to use _parse_request_params method in responses

Best Python code snippet using responses

handlers.py

Source:handlers.py Github

copy

Full Screen

...36 Returns:37 JSON response of the aggregate counter data from38 CountersService.get_counter_data().39 """40 params = _parse_request_params(self.request)41 counters_service = stats.CountersService()42 aggregate_data = counters_service.get_counter_data(43 counter_names=params['counter_names'],44 start_date=params['start_date'],45 end_date=params['end_date'])46 self.response.headers['Content-Type'] = 'application/json'47 self.response.out.write(json.dumps(aggregate_data))48class GraphHandler(webapp2.RequestHandler):49 """Handler for graphing counter data."""50 def get(self):51 """GET request handler.52 Params:53 counter_name: A counter name. Multiple names allowed.54 start_date: An ISO-8601 date string.55 end_date: An ISO-8601 date string.56 Returns:57 Rendered HTML template with graph of counter data.58 """59 zero_between = bool(self.request.get('zero_between', False))60 window_size = int(self.request.get('window_size',61 stats.DEFAULT_WINDOW_SIZE))62 params = _parse_request_params(self.request)63 counters_service = stats.CountersService()64 aggregate_data = counters_service.get_counter_data(65 counter_names=params['counter_names'],66 start_date=params['start_date'],67 end_date=params['end_date'])68 # Render template:69 path = os.path.join(TEMPLATES_PATH, 'graph.html')70 template = jinja2.Template(open(path).read())71 self.response.out.write(template.render(72 aggregate_data=aggregate_data, window_size=window_size,73 zero_between=zero_between))74def _parse_request_params(request):75 counter_names = request.get_all('counter_name')76 start_date = request.get('start_date')77 end_date = request.get('end_date')78 if start_date:79 parsed_time = time.strptime(start_date, '%Y-%m-%d')80 start_date = datetime.date(81 parsed_time.tm_year, parsed_time.tm_mon, parsed_time.tm_mday)82 if end_date:83 parsed_time = time.strptime(end_date, '%Y-%m-%d')84 end_date = datetime.date(85 parsed_time.tm_year, parsed_time.tm_mon, parsed_time.tm_mday)86 result = {87 'counter_names': counter_names,88 'start_date': start_date,...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...9from sunlumo_project.models import Project10from .searcher import Searcher11LOG = logging.getLogger(__name__)12class SimilaritySearchView(JSONRequestResponseMixin, View):13 def _parse_request_params(self, request_json):14 required_params = ['search_string', 'search_layers']15 if not(all(param in request_json for param in required_params)):16 raise Http40417 search_string = request_json.get('search_string')18 search_layers = request_json.get('search_layers')19 params = {20 'search_string': search_string,21 'search_layers': search_layers22 }23 return params24 def post(self, request, *args, **kwargs):25 params = self._parse_request_params(self.request_json)26 project = Project.objects.get(pk=settings.SUNLUMO_PROJECT_ID)27 sl_project = Searcher(project.project_path)28 results = sl_project.search(params)29 return self.render_json_response(results)30class SearchSpecView(JSONResponseMixin, View):31 def get(self, request, *args, **kwargs):32 project = Project.objects.get(pk=settings.SUNLUMO_PROJECT_ID)33 sl_project = Searcher(project.project_path)34 results = sl_project.searchspec()35 return self.render_json_response(results)36class UpdateIndexView(JSONRequestResponseMixin, View):37 def _parse_request_params(self, request_json):38 required_params = ['reindex']39 if not(all(param in request_json for param in required_params)):40 raise Http40441 reindex = request_json.get('reindex')42 params = {43 'reindex': reindex44 }45 return params46 @method_decorator(csrf_exempt)47 def dispatch(self, *args, **kwargs):48 return super(UpdateIndexView, self).dispatch(*args, **kwargs)49 def post(self, request, *args, **kwargs):50 params = self._parse_request_params(self.request_json)51 project = Project.objects.get(pk=settings.SUNLUMO_PROJECT_ID)52 sl_project = Searcher(project.project_path)53 results = sl_project.reindex_features(params)...

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