From 1c40b4f3591beff779c6af5cb4470a1d695f5708 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 21 Nov 2013 19:17:13 -0600 Subject: [PATCH] Extend tool functional test framework to allow testing output dataset metadata. Adding file test/functional/tools/metadata.xml demonstrating how to check output metadata - this file also demonstrates setting metadata on uploaded datasets and verifies both of these functionalities. Checking output metadata is only available for new API driven tool testing. --- lib/galaxy/tools/test.py | 6 ++++- test/functional/test_toolbox.py | 15 +++++++++++ test/functional/tools/metadata.xml | 29 +++++++++++++++++++++ test/functional/tools/samples_tool_conf.xml | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/functional/tools/metadata.xml diff --git a/lib/galaxy/tools/test.py b/lib/galaxy/tools/test.py index 8bb45341616..88e32802143 100644 --- a/lib/galaxy/tools/test.py +++ b/lib/galaxy/tools/test.py @@ -265,10 +265,14 @@ class ToolTestBuilder( object ): attributes['ftype'] = attrib['ftype'] for extra in output_elem.findall( 'extra_files' ): extra_files.append( self.__parse_extra_files_elem( extra ) ) - if not (assert_list or file or extra_files): + metadata = {} + for metadata_elem in output_elem.findall( 'metadata' ): + metadata[ metadata_elem.get('name') ] = metadata_elem.get( 'value' ) + if not (assert_list or file or extra_files or metadata): raise Exception( "Test output defines not checks (e.g. must have a 'file' check against, assertions to check, etc...)") attributes['assert_list'] = assert_list attributes['extra_files'] = extra_files + attributes['metadata'] = metadata self.__add_output( name, file, attributes ) except Exception, e: self.error = True diff --git a/test/functional/test_toolbox.py b/test/functional/test_toolbox.py index 3642dfcf187..9a9f2fad36d 100644 --- a/test/functional/test_toolbox.py +++ b/test/functional/test_toolbox.py @@ -88,6 +88,21 @@ class GalaxyInteractorApi( object ): fetcher = self.__dataset_fetcher( history_id ) ## TODO: Twill version verifys dataset is 'ok' in here. self.twill_test_case.verify_hid( outfile, hda_id=hid, attributes=attributes, dataset_fetcher=fetcher, shed_tool_id=shed_tool_id ) + metadata = attributes.get( 'metadata', {} ) + if metadata: + dataset = self.__get( "histories/%s/contents/%s" % ( history_id, hid ) ).json() + for key, value in metadata.iteritems(): + dataset_key = "metadata_%s" % key + try: + dataset_value = dataset.get( dataset_key, None ) + if dataset_value != value: + msg = "Dataset metadata verification for [%s] failed, expected [%s] but found [%s]." + msg_params = ( key, value, dataset_value ) + msg = msg % msg_params + raise Exception( msg ) + except KeyError: + msg = "Failed to verify dataset metadata, metadata key [%s] was not found." % key + raise Exception( msg ) def get_job_stream( self, history_id, output_data, stream ): hid = output_data.get( 'id' ) diff --git a/test/functional/tools/metadata.xml b/test/functional/tools/metadata.xml new file mode 100644 index 00000000000..044557c560a --- /dev/null +++ b/test/functional/tools/metadata.xml @@ -0,0 +1,29 @@ + + mkdir $output_copy_of_input.extra_files_path; cp $input.extra_files_path/* $output_copy_of_input.extra_files_path; echo "$input.metadata.base_name" > $output_of_input_metadata + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index cc05026efb8..b29f49e7516 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -9,4 +9,5 @@ + \ No newline at end of file