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

Use a mapping for the hostnames for loading contexts

parent ecbe543f
"""
Module that loads contexts from results
"""
import re
import requests
from app.config import RUN_CONFIG
......@@ -19,7 +21,12 @@ def get_context_url(context_dict):
returns the url for loading the context
:param context_dict: dict describing the context
"""
return f'{context_dict["delayed_jobs_base_url"]}/outputs/{context_dict["context_id"]}/results.json'
host = re.search(r'[^/]+\.ebi\.ac\.uk(:\d+)?', context_dict["delayed_jobs_base_url"]).group(0)
host_mappings = RUN_CONFIG.get('delayed_jobs', {}).get('server_mapping', {})
mapped_host = host_mappings.get(host)
mapped_base_url = context_dict['delayed_jobs_base_url'].replace(host, mapped_host)
return f'{mapped_base_url}/outputs/{context_dict["context_id"]}/results.json'
def get_context(context_dict):
......
......@@ -2,8 +2,10 @@
Module to test the context loader
"""
import unittest
import re
from app.blueprints.es_proxy.services.helpers import context_loader
from app.config import RUN_CONFIG
class TestContextLoader(unittest.TestCase):
......@@ -21,8 +23,12 @@ class TestContextLoader(unittest.TestCase):
'context_id': 'STRUCTURE_SEARCH-V4s_piFIe9FL7sOuJ0jl6U0APMEsoV-b4HfFE_dtojc='
}
context_url_must_be = f'{context_dict["delayed_jobs_base_url"]}' \
f'/outputs/{context_dict["context_id"]}/results.json'
host = re.search(r'[^/]+\.ebi\.ac\.uk(:\d+)?', context_dict["delayed_jobs_base_url"]).group(0)
host_mappings = RUN_CONFIG.get('delayed_jobs', {}).get('server_mapping', {})
mapped_host = host_mappings.get(host)
mapped_base_url = context_dict['delayed_jobs_base_url'].replace(host, mapped_host)
context_url_must_be = f'{mapped_base_url}/outputs/{context_dict["context_id"]}/results.json'
context_url_got = context_loader.get_context_url(context_dict)
self.assertEqual(context_url_must_be, context_url_got, msg='The context url was not generated correctly!')
......@@ -104,7 +104,8 @@ if RUN_CONFIG.get('filter_query_max_clauses') is None:
DELAYED_JOBS_CONFIG = RUN_CONFIG.get('delayed_jobs', {})
DEFAULT_DELAYED_JOBS_CONFIG = {
'base_url': 'https://www.ebi.ac.uk/chembl/interface_api/delayed_jobs'
'wwwdev.ebi.ac.uk': 'wwwdev.ebi.ac.uk',
'www.ebi.ac.uk': 'www.ebi.ac.uk'
}
RUN_CONFIG['delayed_jobs'] = {
**DEFAULT_CACHE_CONFIG,
......
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