commit/galaxy-central: jmchilton: Collections: Add API ability to copy HDCA mirroring HDA operations.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a06c6c99d74f/ Changeset: a06c6c99d74f User: jmchilton Date: 2014-05-28 22:28:55 Summary: Collections: Add API ability to copy HDCA mirroring HDA operations. Affected #: 3 files diff -r baeea4ce794df61d9e6531023b8e4c105b26a8bb -r a06c6c99d74f7aa902fb2c23e8c904df32a49791 lib/galaxy/dataset_collections/__init__.py --- a/lib/galaxy/dataset_collections/__init__.py +++ b/lib/galaxy/dataset_collections/__init__.py @@ -138,6 +138,18 @@ changed = self._set_from_dict( trans, dataset_collection_instance, payload ) return changed + def copy( + self, + trans, + parent, # PRECONDITION: security checks on ability to add to parent occurred during load. + source, + encoded_source_id, + ): + assert source == "hdca" # for now + source_hdca = self.__get_history_collection_instance( trans, encoded_source_id ) + parent.add_dataset_collection( source_hdca.copy() ) + return source_hdca + def _set_from_dict( self, trans, dataset_collection_instance, new_data ): # Blatantly stolen from UsesHistoryDatasetAssociationMixin.set_hda_from_dict. diff -r baeea4ce794df61d9e6531023b8e4c105b26a8bb -r a06c6c99d74f7aa902fb2c23e8c904df32a49791 lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -292,9 +292,28 @@ return hda_dict def __create_dataset_collection( self, trans, history, payload, **kwd ): - create_params = api_payload_to_create_params( payload ) + source = kwd.get("source", "new_collection") service = trans.app.dataset_collections_service - dataset_collection_instance = service.create( trans, parent=history, **create_params ) + if source == "new_collection": + create_params = api_payload_to_create_params( payload ) + dataset_collection_instance = service.create( + trans, + parent=history, + **create_params + ) + elif source == "hdca": + content = payload.get( 'content', None ) + if content is None: + raise exceptions.RequestParameterMissingException( "'content' id of target to copy is missing" ) + dataset_collection_instance = service.copy( + trans=trans, + parent=history, + source="hdca", + encoded_source_id=content, + ) + else: + message = "Invalid 'source' parameter in request %s" % source + raise exceptions.RequestParameterInvalidException(message) return self.__collection_dict( trans, dataset_collection_instance, view="element" ) @expose_api_anonymous diff -r baeea4ce794df61d9e6531023b8e4c105b26a8bb -r a06c6c99d74f7aa902fb2c23e8c904df32a49791 test/api/test_history_contents.py --- a/test/api/test_history_contents.py +++ b/test/api/test_history_contents.py @@ -97,9 +97,7 @@ dataset_collection_response = self._post( "histories/%s/contents" % self.history_id, payload ) - self._assert_status_code_is( dataset_collection_response, 200 ) - dataset_collection = dataset_collection_response.json() - self._assert_has_keys( dataset_collection, "url", "name", "deleted" ) + dataset_collection = self.__check_create_collection_response( dataset_collection_response ) post_collection_count = self.__count_contents( type="dataset_collection" ) post_dataset_count = self.__count_contents( type="dataset" ) @@ -144,6 +142,23 @@ show_response = self.__show( hdca ) assert str( show_response.json()[ "name" ] ) == "newnameforpair" + def test_hdca_copy( self ): + hdca = self.dataset_collection_populator.create_pair_in_history( self.history_id ).json() + hdca_id = hdca[ "id" ] + second_history_id = self._new_history() + create_data = dict( + source='hdca', + content=hdca_id, + ) + create_response = self._post( "histories/%s/contents/dataset_collections" % second_history_id, create_data ) + self.__check_create_collection_response( create_response ) + + def __check_create_collection_response( self, response ): + self._assert_status_code_is( response, 200 ) + dataset_collection = response.json() + self._assert_has_keys( dataset_collection, "url", "name", "deleted", "visible", "elements" ) + return dataset_collection + def __show( self, contents ): show_response = self._get( "histories/%s/contents/%ss/%s" % ( self.history_id, contents["history_content_type"], contents[ "id" ] ) ) return show_response Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org