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

Properties configuration: allow support for sticky and highlight properties subgroups

parent d5011a2b
The location of the config file can be set up with the variable CONFIG_FILE_PATH, if not set, the value is 'config.yml'
# To run unit tests
```bash
python -m unittest
```
# Run development server
```bash
......
......@@ -13,3 +13,9 @@ chembl_molecule:
additional: ['_metadata.atc_classifications.level2', '_metadata.atc_classifications.level2_description',
'_metadata.atc_classifications.level3' ]
# see the entry for this group in test_default_sorting.yml
chembl_target:
eubopen_search_results:
default: ['pref_name']
sticky: ['target_chembl_id']
highlight: ['pref_name']
......@@ -31,6 +31,26 @@ class GroupsConfigurationManagerTester(unittest.TestCase):
Class to test the configuration manager
"""
def assert_groups_are_correct(self, groups_configuration_manager, index_name, group_name):
"""
Asserts that the groups were parsed correctly
:param groups_configuration_manager: instance of the groups config manager used
:param index_name: name of the index in the config
:param group_name: name of the group in the config
:return:
"""
configs_got = groups_configuration_manager.get_config_for_group(index_name, group_name)['properties']
with open(groups_configuration_manager.groups_file_path, 'rt') as groups_config_file:
groups_must_be = yaml.load(groups_config_file, Loader=yaml.FullLoader)
group_must_be = groups_must_be[index_name][group_name]
for sub_group, props_list_must_be in group_must_be.items():
props_list_got = [conf['prop_id'] for conf in configs_got[sub_group]]
self.assertTrue(props_list_got == props_list_must_be,
msg=f'sub group {sub_group} was not read correctly')
# ------------------------------------------------------------------------------------------------------------------
# Getting a custom list of properties
# ------------------------------------------------------------------------------------------------------------------
......@@ -129,15 +149,7 @@ class GroupsConfigurationManagerTester(unittest.TestCase):
index_name = f'{es_index_prefix}activity'
group_name = 'download'
configs_got = groups_configuration_manager.get_config_for_group(index_name, group_name)['properties']
with open(groups_configuration_manager.groups_file_path, 'rt') as groups_config_file:
groups_must_be = yaml.load(groups_config_file, Loader=yaml.FullLoader)
group_must_be = groups_must_be[index_name][group_name]
for sub_group, props_list_must_be in group_must_be.items():
props_list_got = [conf['prop_id'] for conf in configs_got[sub_group]]
self.assertTrue(props_list_got == props_list_must_be)
self.assert_groups_are_correct(groups_configuration_manager, index_name, group_name)
def test_gets_config_for_a_group_with_default_and_additional_properties(self):
"""
......@@ -149,15 +161,7 @@ class GroupsConfigurationManagerTester(unittest.TestCase):
index_name = f'{es_index_prefix}activity'
group_name = 'table'
configs_got = groups_configuration_manager.get_config_for_group(index_name, group_name)['properties']
with open(groups_configuration_manager.groups_file_path, 'rt') as groups_config_file:
groups_must_be = yaml.load(groups_config_file, Loader=yaml.FullLoader)
group_must_be = groups_must_be[index_name][group_name]
for sub_group, props_list_must_be in group_must_be.items():
props_list_got = [conf['prop_id'] for conf in configs_got[sub_group]]
self.assertTrue(props_list_got == props_list_must_be)
self.assert_groups_are_correct(groups_configuration_manager, index_name, group_name)
def test_gets_all_configured_properties(self):
"""
......@@ -180,3 +184,34 @@ class GroupsConfigurationManagerTester(unittest.TestCase):
self.assertEqual(sorted(props_list_got), sorted(props_list_must_be),
msg='The properties list is not correct!')
def test_gets_all_configured_properties_2(self):
"""
Tests that it returns all the configured properties for an index with sticky and highlight properties defined in the subgroups
"""
groups_configuration_manager = get_group_configuration_instance()
es_index_prefix = RUN_CONFIG.get('es_index_prefix')
index_name = f'{es_index_prefix}target'
props_list_must_be = [
'pref_name', 'target_chembl_id',
]
props_list_got = groups_configuration_manager.get_list_of_configured_properties(index_name)
self.assertEqual(sorted(props_list_got), sorted(props_list_must_be),
msg='The properties list is not correct!')
def test_gets_config_for_a_group_with_sticky_and_highlight_properties(self):
"""
tests that gets config for a group with default and additional properties
"""
groups_configuration_manager = get_group_configuration_instance()
es_index_prefix = RUN_CONFIG.get('es_index_prefix')
index_name = f'{es_index_prefix}target'
group_name = 'eubopen_search_results'
self.assert_groups_are_correct(groups_configuration_manager, index_name, group_name)
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