Commit 1af5e909 authored by David Mendez's avatar David Mendez
Browse files

Add first functional test

parent 1b32c43a
......@@ -36,7 +36,7 @@ paths:
description: 'name of the index to query'
required: true
type: 'string'
- name: 'search_data'
- name: 'es_query'
in: 'formData'
description: 'stringifyied version of the query to send to elasticsearch'
required: true
......@@ -64,4 +64,6 @@ definitions:
type: 'object'
properties:
es_response:
type: 'object'
metadata:
type: 'object'
\ No newline at end of file
#!/usr/bin/env python3
# pylint: disable=import-error
"""
Script that runs the functional tests for the app
"""
import argparse
from specific_tests import fun_test_simple_query
PARSER = argparse.ArgumentParser()
PARSER.add_argument('server_base_path', help='server base path to run the tests against',
default='http://127.0.0.1:5000', nargs='?')
......@@ -16,6 +19,9 @@ def run():
"""
print(f'Running functional tests on {ARGS.server_base_path}')
for test_module in [fun_test_simple_query]:
test_module.run_test(ARGS.server_base_path)
if __name__ == "__main__":
run()
# pylint: disable=import-error
"""
Module that tests a simple es query
"""
import json
import requests
from specific_tests import utils
def run_test(server_base_url):
"""
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
"""
print('-------------------------------------------')
print('Testing a simple query')
print('-------------------------------------------')
url = utils.get_url_for_get_es_data(server_base_url)
print('url: ', url)
index_name = 'chembl_26_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}')
assert status_code == 200, 'The request failed!'
"""
Module with utils functions for the tests
"""
def get_url_for_get_es_data(server_base_url):
"""
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:return: url for the get_es_data_endpoint
"""
return f'{server_base_url}/get_es_data'
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