Commit ecbe543f authored by David Mendez's avatar David Mendez
Browse files

Make pylint happy

parent 16cb8e25
"""
The blueprint used for handling requests to get generic es_data
"""
from flask import Blueprint, jsonify, abort, request, send_file
from flask import Blueprint, jsonify, abort, request
from app.request_validation.decorators import validate_form_with
from app.blueprints.es_proxy.controllers import marshmallow_schemas
from app.blueprints.es_proxy.services import es_proxy_service
from app.blueprints.es_proxy.services import es_proxy_service
from app import app_logging
ES_PROXY_BLUEPRINT = Blueprint('es_proxy', __name__)
@ES_PROXY_BLUEPRINT.route('/get_es_data', methods = ['POST'])
@ES_PROXY_BLUEPRINT.route('/get_es_data', methods=['POST'])
@validate_form_with(marshmallow_schemas.ESProxyQuery)
def get_es_data():
"""
......@@ -45,12 +46,13 @@ def get_es_data():
abort(500, msg=f'Internal server error: {str(error)}')
def sanitise_parameter(param_value):
"""
Makes the parameter null if it is 'null' or 'undefined', in some cases javascript produces those values
:param param_value: value of the parameter
:return: null if 'null' or 'undefined' the actual value otherwise
:return: null if param_value in ('null', 'undefined'), the actual value otherwise
"""
if param_value == 'null' or param_value == 'undefined':
if param_value in ('null', 'undefined'):
return None
return param_value
......@@ -34,17 +34,15 @@ def get_es_data(index_name, raw_es_query, raw_context, id_property, raw_contextu
}
return response
else:
app_logging.debug(f'Using context: {raw_context}')
es_response, metadata = get_items_with_context(index_name, raw_es_query, raw_context, id_property,
raw_contextual_sort_data)
app_logging.debug(f'Using context: {raw_context}')
es_response, metadata = get_items_with_context(index_name, raw_es_query, raw_context, id_property,
raw_contextual_sort_data)
response = {
'es_response': es_response,
'metadata': metadata
}
return response
response = {
'es_response': es_response,
'metadata': metadata
}
return response
def get_items_with_context(index_name, raw_es_query, raw_context, id_property, raw_contextual_sort_data='{}'):
......@@ -108,9 +106,8 @@ def get_scores_query(contextual_sort_data, id_property, total_results, context_i
# if nothing is specified use the default scoring script, which is to score them according to their original
# position in the results
score_property = 'index'
score_script = "String id=doc['" + id_property + "'].value; " \
"return " + str(
total_results) + " - params.scores[id]['" + score_property + "'];"
score_script = f'String id=doc["{id_property}"].value; ' \
f'return {str(total_results)} - params.scores[id]["{score_property}"];'
else:
raw_score_property = list(contextual_sort_data_keys)[0]
......
"""
Module that handles decorators used in request validation
"""
from flask import request, abort
from functools import wraps
from flask import request, abort
def validate_form_with(validation_schema):
"""
validates the form params with the marshmallow schema given as parameter
:param validation_schema: schema to use for validation
"""
def wrap(func):
@wraps(func)
def wrapped_func(*args, **kwargs):
validation_errors = validation_schema().validate(request.form)
if validation_errors:
abort(400, str(validation_errors))
......@@ -23,12 +27,14 @@ def validate_form_with(validation_schema):
def validate_url_params_with(validation_schema):
"""
validates the url params with the marshmallow schema given as parameter
:param validation_schema: schema to use for validation
"""
def wrap(func):
@wraps(func)
def wrapped_func(*args, **kwargs):
validation_errors = validation_schema().validate(kwargs)
if validation_errors:
abort(400, str(validation_errors))
......@@ -37,4 +43,4 @@ def validate_url_params_with(validation_schema):
return wrapped_func
return wrap
\ No newline at end of file
return wrap
......@@ -19,6 +19,7 @@ def run_test(server_base_url, delayed_jobs_server_base_path):
print('-------------------------------------------')
print('Testing a simple query')
print('-------------------------------------------')
print('delayed_jobs_server_base_path: ', delayed_jobs_server_base_path)
url = utils.get_url_for_get_es_data(server_base_url)
print('url: ', url)
......
......@@ -13,7 +13,8 @@ def get_url_for_get_es_data(server_base_url):
def get_url_for_job_status(delayed_jobs_base_url, job_id):
"""
:param delayed_jobs_base_url: base url for the delayed jobs. E.g. https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs
:param delayed_jobs_base_url: base url for the delayed jobs.
E.g. https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs
:param job_id: job_id
:return: url for getting a job status
"""
......@@ -22,7 +23,8 @@ def get_url_for_job_status(delayed_jobs_base_url, job_id):
def get_url_for_similarity_job_submission(delayed_jobs_base_url):
"""
:param delayed_jobs_base_url: base url for the delayed jobs. E.g. https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs
:param delayed_jobs_base_url: base url for the delayed jobs.
E.g. https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs
:return: url for submitting a similarity search job
"""
return f'{delayed_jobs_base_url}/submit/structure_search_job'
......
......@@ -555,7 +555,7 @@ max-bool-expr=5
max-branches=12
# Maximum number of locals for function / method body.
max-locals=15
max-locals=30
# Maximum number of parents for a class (see R0901).
max-parents=7
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment