def run_test(server_base_url, delayed_jobs_server_base_path):
    """
    Tests that getting the data of a context
    :param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
    :param delayed_jobs_server_base_path: base path for the delayed_jobs
    """

    print('-------------------------------------------')
    print('Testing getting the data of a context')
    print('-------------------------------------------')

    job_id = utils.submit_similarity_search_job(delayed_jobs_server_base_path)
    utils.wait_until_job_finished(delayed_jobs_server_base_path, job_id)
    print('Now going to load this context')

    context_params = {
        'delayed_jobs_base_url': delayed_jobs_server_base_path,
        'context_type': 'SIMILARITY',
        'context_id': f'{job_id}'
    }

    url = f'{server_base_url}/contexts/get_context_data'

    request = requests.post(url, data=context_params)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'
def run_test(server_base_url, delayed_jobs_server_base_path):
    """
    Tests that parsing a search term works
    :param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
    :param delayed_jobs_server_base_path: base path for the delayed_jobs
    """

    print('-------------------------------------------')
    print('Testing parsing s search')
    print('-------------------------------------------')

    term_params = {
        'search_term':
        'MDCK',
        'es_indexes':
        'chembl_molecule,chembl_target,chembl_assay,chembl_document,chembl_cell_line,chembl_tissue',
    }

    url = f'{server_base_url}/search_parsing/parse_free_text_search'

    request = requests.post(url, data=term_params)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'
Ejemplo n.º 3
0
def run_test(server_base_url, delayed_jobs_server_base_path):
    """
    Tests that a simple query to elasticsearch
    :param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
    :param delayed_jobs_server_base_path: base path for the delayed_jobs
    """

    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)
    index_name = 'chembl_molecule'
    print('index_name: ', index_name)
    es_query = {
        "size": 24,
        "from": 0,
        "query": {
            "bool": {
                "must": [
                    {"query_string": {"analyze_wildcard": True, "query": "*"}}
                ],
                "filter": []
            }
        },
        "sort": []
    }
    print('es_query: ', es_query)

    payload = {
        'index_name': index_name,
        'es_query': json.dumps(es_query)
    }

    request = requests.post(url, data=payload)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'

    response_json = request.json()
    hits = response_json['es_response']['hits']['hits']

    assert len(hits) > 0, 'I should have gotten hits!'
Ejemplo n.º 4
0
def run_test(server_base_url, delayed_jobs_server_base_path):
    """
    Tests that a url can be shortened
    :param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
    :param delayed_jobs_server_base_path: base path for the delayed_jobs
    """

    print('-------------------------------------------')
    print('Testing the url shortening')
    print('-------------------------------------------')
    print('delayed_jobs_server_base_path: ', delayed_jobs_server_base_path)

    url = f'{server_base_url}/url_shortening/shorten_url'
    print('url: ', url)
    long_url = '#substructure_search_results/C[C@H](CCc1ccccc1)NC[C@H](O)c1ccc(O)c(C(N)=O)c1'

    payload = {
        "long_url": long_url
    }

    request = requests.post(url, data=payload)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'

    response_json = request.json()
    url_hash = response_json.get('hash')
    assert url_hash is not None, 'The url hash was not returned!'

    expansion_url = f'{server_base_url}/url_shortening/expand_url/{url_hash}'
    request = requests.get(expansion_url)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'

    time.sleep(5) # make it sleep to make sure the url is saved in ES

    response_json = request.json()
    long_url_got = response_json.get('long_url')
    assert long_url == long_url_got, 'The long url was not obtained!'
def run_test(server_base_url, delayed_jobs_server_base_path):
    """
    Tests that a simple query to elasticsearch
    :param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
    :param delayed_jobs_server_base_path: base path for the delayed_jobs
    """

    print('-------------------------------------------')
    print('Testing a es_query with context')
    print('-------------------------------------------')

    job_id = utils.submit_similarity_search_job(delayed_jobs_server_base_path)
    utils.wait_until_job_finished(delayed_jobs_server_base_path, job_id)
    print('Now going to make a request with this context')

    url = utils.get_url_for_get_es_data(server_base_url)
    print('url: ', url)

    es_query = {
        "size": 24,
        "from": 0,
        "query": {
            "bool": {
                "must": [{
                    "query_string": {
                        "analyze_wildcard": 'true',
                        "query": "*"
                    }
                }],
                "filter": []
            }
        },
        "sort": []
    }

    context_obj = {
        "delayed_jobs_base_url":
        delayed_jobs_server_base_path,
        "context_type":
        "SIMILARITY",
        "context_id":
        "STRUCTURE_SEARCH-V4s_piFIe9FL7sOuJ0jl6U0APMEsoV-b4HfFE_dtojc=",
    }

    payload = {
        'index_name': 'chembl_molecule',
        'es_query': json.dumps(es_query),
        'context_obj': json.dumps(context_obj),
        'contextual_sort_data': {},
    }

    print('payload: ', payload)

    request = requests.post(url, data=payload)

    status_code = request.status_code
    print(f'status_code: {status_code}')
    response_text = request.text
    utils.print_es_response(response_text)
    assert status_code == 200, 'The request failed!'

    response_json = request.json()
    hits = response_json['es_response']['hits']['hits']

    assert len(hits) > 0, 'I should have gotten hits!'

    metadata = response_json['metadata']
    print('metadata: ', metadata)

    assert metadata['total_results'] > 0, 'There should be more than 0 results!'