From 1e70211fa4827badf4bd3fe1f1703004d369afec Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 31 Mar 2017 16:14:51 -0400 Subject: [PATCH] Touch up #3559 based on post-merge discussions. --- lib/galaxy/webapps/galaxy/api/folder_contents.py | 11 +++++------ lib/galaxy/webapps/galaxy/api/library_contents.py | 14 +++++--------- test/api/test_libraries.py | 3 +-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/folder_contents.py b/lib/galaxy/webapps/galaxy/api/folder_contents.py index f2295465591..619dadda53f 100644 --- a/lib/galaxy/webapps/galaxy/api/folder_contents.py +++ b/lib/galaxy/webapps/galaxy/api/folder_contents.py @@ -258,8 +258,9 @@ class FolderContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrary :type extended_metadata: dict :type payload: dict - :returns: a list of dictionaries containing the id, name, and 'show' url of the new item - :rtype: list + :returns: a dictionary describing the new item if ``from_hda_id`` is supplied or a list of + such dictionaries describing the new items if ``from_hdca_id`` is supplied. + :rtype: object :raises: ObjectAttributeInvalidException, InsufficientPermissionsException, ItemAccessibilityException, @@ -271,14 +272,13 @@ class FolderContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrary ldda_message = payload.pop( 'ldda_message', '' ) if ldda_message: ldda_message = util.sanitize_html.sanitize_html( ldda_message, 'utf-8' ) - rvals = [] try: if from_hda_id: decoded_hda_id = self.decode_id( from_hda_id ) - rvals.append(self._copy_hda_to_library_folder( trans, self.hda_manager, decoded_hda_id, encoded_folder_id_16, ldda_message )) + return self._copy_hda_to_library_folder( trans, self.hda_manager, decoded_hda_id, encoded_folder_id_16, ldda_message ) if from_hdca_id: decoded_hdca_id = self.decode_id( from_hdca_id ) - rvals.extend(self._copy_hdca_to_library_folder( trans, self.hda_manager, decoded_hdca_id, encoded_folder_id_16, ldda_message )) + return self._copy_hdca_to_library_folder( trans, self.hda_manager, decoded_hdca_id, encoded_folder_id_16, ldda_message ) except Exception as exc: # TODO handle exceptions better within the mixins if 'not accessible to the current user' in str( exc ) or 'You are not allowed to access this dataset' in str( exc ): @@ -286,7 +286,6 @@ class FolderContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrary else: log.exception( exc ) raise exc - return rvals def __decode_library_content_id( self, trans, encoded_folder_id ): """ diff --git a/lib/galaxy/webapps/galaxy/api/library_contents.py b/lib/galaxy/webapps/galaxy/api/library_contents.py index 89c8e0b8c49..c27c93c1a53 100644 --- a/lib/galaxy/webapps/galaxy/api/library_contents.py +++ b/lib/galaxy/webapps/galaxy/api/library_contents.py @@ -183,9 +183,9 @@ class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrar * description: (optional, only if create_type is 'folder') description of the folder to create - :rtype: list - :returns: a list of dictionaries containing the id, name, - and 'show' url of the new item + :returns: a dictionary describing the new item unless ``from_hdca_id`` is supplied, + in that case a list of such dictionaries is returned. + :rtype: object """ if 'create_type' not in payload: trans.response.status = 400 @@ -213,15 +213,11 @@ class LibraryContentsController( BaseAPIController, UsesLibraryMixin, UsesLibrar # are we copying an HDA to the library folder? # we'll need the id and any message to attach, then branch to that private function from_hda_id, from_hdca_id, ldda_message = ( payload.pop( 'from_hda_id', None ), payload.pop( 'from_hdca_id', None ), payload.pop( 'ldda_message', '' ) ) - log.debug(payload) if create_type == 'file': - rval = [] if from_hda_id: - rval.append(self._copy_hda_to_library_folder( trans, self.hda_manager, self.decode_id(from_hda_id), real_folder_id, ldda_message )) + return self._copy_hda_to_library_folder( trans, self.hda_manager, self.decode_id(from_hda_id), real_folder_id, ldda_message ) if from_hdca_id: - rval.extend(self._copy_hdca_to_library_folder(trans, self.hda_manager, self.decode_id(from_hdca_id), real_folder_id, ldda_message)) - if from_hda_id or from_hdca_id: - return rval + return self._copy_hdca_to_library_folder(trans, self.hda_manager, self.decode_id(from_hdca_id), real_folder_id, ldda_message) # check for extended metadata, store it and pop it out of the param # otherwise sanitize_param will have a fit diff --git a/test/api/test_libraries.py b/test/api/test_libraries.py index d5f88c71de4..a857dd797f2 100644 --- a/test/api/test_libraries.py +++ b/test/api/test_libraries.py @@ -111,8 +111,7 @@ class LibrariesApiTestCase( api.ApiTestCase, TestsDatasets ): payload = {'from_hda_id': hda_id} create_response = self._post( "folders/%s/contents" % folder_id, payload ) self._assert_status_code_is( create_response, 200 ) - library_datasets = create_response.json() - assert len( library_datasets ) == 1 + self._assert_has_keys( create_response.json(), "name", "id" ) def test_create_datasets_in_library_from_collection( self ): library = self.library_populator.new_private_library( "ForCreateDatasetsFromCollection" )