Commit ee164505 authored by Jacek Lebioda's avatar Jacek Lebioda
Browse files

Some E2E tests

parent 8a39c6b0
Pipeline #10649 failed with stage
in 53 seconds
......@@ -92,6 +92,7 @@ class Beacon(object):
def initialize_from_envvars(self,
settings_envvar: str='BEACON_SETTINGS_YAML',
datasources_envvar: str='BEACON_DATASOURCES_YAML'):
logger.debug(" * Trying to load the settings from: $" + settings_envvar + ", $" + datasources_envvar)
if settings_envvar not in os.environ or datasources_envvar not in os.environ:
return False
path_to_settings_yaml_file = os.environ.get(settings_envvar)
......
......@@ -64,7 +64,9 @@ def register_extensions(app):
logger.debug(' * Extensions successfully registered!')
def create_app(path_to_config_file=""):
def create_app(path_to_config_file="",
path_to_beacon_settings="",
path_to_data_sources_settings=""):
"""
Creates the Flask application based on config object (Flask)
passed as an argument
......@@ -72,21 +74,13 @@ def create_app(path_to_config_file=""):
:return: Flask application object
"""
try:
with open(path_to_config_file, 'r') as config_file:
config_object = json.loads(config_file.read())
if config_object.get('SUPPRESS_WARNINGS', False):
logger.setLevel(logging.CRITICAL)
except Exception as e:
logger.error('Could not load Flask''s configuration!')
if len(path_to_config_file) == 0:
logger.error('You did not specify path to Flask''s configuration file')
else:
logger.error('Please check whether ' + path_to_config_file + ' is a valid JSON')
raise e
# The main Flask application
logger.debug('Creating application:')
logger.debug(' - Loading flask configuration...')
config_object = load_configuration(path_to_config_file)
logger.debug(' - Creating Flask app object...')
app = Flask(__name__)
app.config.from_mapping(config_object)
register_extensions(app)
......@@ -94,7 +88,15 @@ def create_app(path_to_config_file=""):
# The Beacon
logger.debug(' - Initializing Beacon...')
beacon = Beacon()
if beacon.initialize_from_envvars():
if len(path_to_data_sources_settings) and len(path_to_beacon_settings):
logger.debug(' * will load the settings from manually specified files')
init_result = beacon.initialize_from_yaml_files(path_to_beacon_settings, path_to_data_sources_settings)
else:
logger.debug(' * will load the settings from files specified in envvars')
init_result = beacon.initialize_from_envvars()
if init_result:
logger.debug(' * success, Beacon correctly initialized!')
else:
logger.error(' * error, something went wrong, did you correctly set the envvars?')
......@@ -103,10 +105,28 @@ def create_app(path_to_config_file=""):
logger.debug(' - Registering views...')
register_views(app, beacon)
app.beacon = beacon
logger.debug(' - Flask application has been correctly loaded!')
return app
def load_configuration(path_to_config_file=""):
try:
logger.debug(' opening: ' + path_to_config_file)
with open(path_to_config_file, 'r') as config_file:
config_object = json.loads(config_file.read())
if config_object.get('SUPPRESS_WARNINGS', False):
logger.setLevel(logging.CRITICAL)
except Exception as e:
logger.error('Could not load Flask''s configuration!')
if len(path_to_config_file) == 0:
logger.error('You did not specify path to Flask''s configuration file')
else:
logger.error('Please check whether ' + path_to_config_file + ' is a valid JSON')
raise e
return config_object
def get_path_to_configuration():
configuration_key = 'BEACON_CONFIGURATION_JSON'
default_value = "../../configuration/flask_settings.json"
......
import json
from unittest import TestCase
from beacon.server import create_app, get_path_to_configuration
class End2endSuite(TestCase):
@classmethod
def setUpClass(cls):
super(End2endSuite, cls).setUpClass()
configuration_file = get_path_to_configuration()
cls.app = create_app(configuration_file,
'../../configuration/beacon_information.yaml',
'../../configuration/connections.yaml')
cls.client = cls.app.test_client()
def test_index(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_beacon_metadata(self):
response = self.client.get('/v1/beacon')
self.assertEqual(response.status_code, 200)
response_dict = json.loads(response.data)
self.assertTrue('alternativeUrl' in response_dict)
self.assertTrue('apiVersion' in response_dict)
self.assertTrue('createDateTime' in response_dict)
self.assertTrue('datasets' in response_dict)
self.assertTrue('description' in response_dict)
self.assertTrue('organization' in response_dict)
self.assertTrue('version' in response_dict)
def test_beacon_query(self):
response = self.client.get('/v1/beacon/query?assemblyId=GRCh37&referenceName=1')
self.assertEqual(response.status_code, 200)
def test_beacon_queries_include_dataset_responses(self):
def get_response(url):
response = self.client.get(url)
return json.loads(response.data)
def assert_correct(url):
self.assertTrue('error' not in get_response(url))
def assert_incorrect(url):
self.assertTrue('error' in get_response(url))
base_url = '/v1/beacon/query?assemblyId=GRCh37&referenceBases=A&referenceName=1&includeDatasetResponses='
assert_correct(base_url)
assert_correct(base_url + 'MISS')
assert_correct(base_url + 'NONE')
assert_correct(base_url + 'ALL')
assert_correct(base_url + 'hit')
assert_incorrect(base_url + 'hits')
assert_incorrect(base_url + 'ALLx')
assert_incorrect(base_url + '1')
assert_incorrect(base_url + 'true')
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