From 33463efe13a23e94a246e7c4d015af78f06fe2a0 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 15 Dec 2014 00:20:35 -0500 Subject: [PATCH] Allow multiple tool data table config files... ... use this functionality to implement tests for tool data API. --- lib/galaxy/tools/data/__init__.py | 6 ++-- scripts/functional_tests.py | 9 ++++++ test/api/test_tool_data.py | 30 +++++++++++++++++++ .../tool-data/sample_tool_data_tables.xml | 12 ++++++++ test/functional/tool-data/testalpha.loc | 2 ++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 test/api/test_tool_data.py create mode 100644 test/functional/tool-data/sample_tool_data_tables.xml create mode 100644 test/functional/tool-data/testalpha.loc diff --git a/lib/galaxy/tools/data/__init__.py b/lib/galaxy/tools/data/__init__.py index f4a97c3cab9..4b3e7dccb76 100644 --- a/lib/galaxy/tools/data/__init__.py +++ b/lib/galaxy/tools/data/__init__.py @@ -31,8 +31,10 @@ class ToolDataTableManager( object ): # at server startup. If tool shed repositories are installed that contain a valid file named tool_data_table_conf.xml.sample, entries # from that file are inserted into this dict at the time of installation. self.data_tables = {} - if config_filename: - self.load_from_config_file( config_filename, self.tool_data_path, from_shed_config=False ) + for single_config_filename in util.listify( config_filename ): + if not single_config_filename: + continue + self.load_from_config_file( single_config_filename, self.tool_data_path, from_shed_config=False ) def __getitem__( self, key ): return self.data_tables.__getitem__( key ) diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 239f62bd2fa..142ace2faee 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -231,7 +231,16 @@ def main(): start_server = 'GALAXY_TEST_EXTERNAL' not in os.environ tool_data_table_config_path = None if os.path.exists( 'tool_data_table_conf.test.xml' ): + # If explicitly defined tables for test, use those. tool_data_table_config_path = 'tool_data_table_conf.test.xml' + else: + # ... otherise find whatever Galaxy would use as the default and + # the sample data for fucntional tests to that. + default_tool_data_config = 'config/tool_data_table_conf.xml.sample' + for tool_data_config in ['config/tool_data_table_conf.xml', 'tool_data_table_conf.xml' ]: + if os.path.exists( tool_data_config ): + default_tool_data_config = tool_data_config + tool_data_table_config_path = '%s,test/functional/tool-data/sample_tool_data_tables.xml' % default_tool_data_config shed_tool_data_table_config = 'config/shed_tool_data_table_conf.xml' tool_dependency_dir = os.environ.get( 'GALAXY_TOOL_DEPENDENCY_DIR', None ) use_distributed_object_store = os.environ.get( 'GALAXY_USE_DISTRIBUTED_OBJECT_STORE', False ) diff --git a/test/api/test_tool_data.py b/test/api/test_tool_data.py new file mode 100644 index 00000000000..60cca5dd9e8 --- /dev/null +++ b/test/api/test_tool_data.py @@ -0,0 +1,30 @@ +""" Tests for the tool data API. +""" +from base import api + +import operator + + +class ToolDataApiTestCase( api.ApiTestCase ): + + def test_admin_only( self ): + index_response = self._get( "tool_data", admin=False ) + self._assert_status_code_is( index_response, 403 ) + + def test_list(self): + index_response = self._get( "tool_data", admin=True ) + self._assert_status_code_is( index_response, 200 ) + print index_response.content + index = index_response.json() + assert "testalpha" in map(operator.itemgetter("name"), index) + + def test_show(self): + show_response = self._get( "tool_data/testalpha", admin=True ) + self._assert_status_code_is( show_response, 200 ) + print show_response.content + data_table = show_response.json() + assert data_table["columns"] == ["value", "name", "path"] + first_entry = data_table["fields"][0] + assert first_entry[0] == "data1" + assert first_entry[1] == "data1name" + assert first_entry[2].endswith("test/functional/tool-data/data1/entry.txt") diff --git a/test/functional/tool-data/sample_tool_data_tables.xml b/test/functional/tool-data/sample_tool_data_tables.xml new file mode 100644 index 00000000000..5cf9cc88c7a --- /dev/null +++ b/test/functional/tool-data/sample_tool_data_tables.xml @@ -0,0 +1,12 @@ + + + value, name, path + +
+ +
diff --git a/test/functional/tool-data/testalpha.loc b/test/functional/tool-data/testalpha.loc new file mode 100644 index 00000000000..0e1d12f30d3 --- /dev/null +++ b/test/functional/tool-data/testalpha.loc @@ -0,0 +1,2 @@ +data1 data1name ${__HERE__}/data1/entry.txt +data2 data2name ${__HERE__}/data2/entry.txt