From f70d24afb5ed151237d7c7e0491b5db9337fdefc Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 15 Jan 2019 13:06:50 +0000 Subject: [PATCH] Python3: open 2 files in binary mode Fix `HistoriesApiTestCase.test_import_metadata_regeneration()` API test introduced in commit 38f7aded0b11f4c75f2265ba95ed674e8d655e7d . See: https://jenkins.galaxyproject.org/job/docker-api-py3/193/testReport/junit/test.api.test_histories/HistoriesApiTestCase/test_import_metadata_regeneration/ --- lib/galaxy/webapps/galaxy/api/datasets.py | 24 +++++++++++------------ test/api/test_histories.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/datasets.py b/lib/galaxy/webapps/galaxy/api/datasets.py index 666960d3adf..23173121b18 100644 --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -351,23 +351,23 @@ class DatasetsController(BaseAPIController, UsesVisualizationMixin): else: file_path = hda.file_name rval = open(file_path, 'rb') - else: display_kwd = kwd.copy() if 'key' in display_kwd: del display_kwd["key"] rval = hda.datatype.display_data(trans, hda, preview, filename, to_ext, **display_kwd) - - except Exception as exception: - log.error("Error getting display data for dataset (%s) from history (%s): %s", - history_content_id, history_id, str(exception), exc_info=True) + except Exception as e: + log.exception("Error getting display data for dataset (%s) from history (%s)", + history_content_id, history_id) trans.response.status = 500 - rval = ("Could not get display data for dataset: " + str(exception)) - + rval = "Could not get display data for dataset: %s" % e return rval @web.expose_api_raw_anonymous def get_metadata_file(self, trans, history_content_id, history_id, metadata_file=None, **kwd): + """ + GET /api/histories/{history_id}/contents/{history_content_id}/metadata_file + """ decoded_content_id = self.decode_id(history_content_id) rval = '' try: @@ -376,12 +376,12 @@ class DatasetsController(BaseAPIController, UsesVisualizationMixin): fname = ''.join(c in util.FILENAME_VALID_CHARS and c or '_' for c in hda.name)[0:150] trans.response.headers["Content-Type"] = "application/octet-stream" trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (hda.hid, fname, file_ext) - return open(hda.metadata.get(metadata_file).file_name) - except Exception as exception: - log.error("Error getting metadata_file (%s) for dataset (%s) from history (%s): %s", - metadata_file, history_content_id, history_id, str(exception), exc_info=True) + return open(hda.metadata.get(metadata_file).file_name, 'rb') + except Exception as e: + log.exception("Error getting metadata_file (%s) for dataset (%s) from history (%s)", + metadata_file, history_content_id, history_id) trans.response.status = 500 - rval = ("Could not get display data for dataset: " + str(exception)) + rval = "Could not get metadata for dataset: %s" % e return rval @web._future_expose_api_anonymous diff --git a/test/api/test_histories.py b/test/api/test_histories.py index 8766807ec9c..bf135b03504 100644 --- a/test/api/test_histories.py +++ b/test/api/test_histories.py @@ -192,7 +192,7 @@ class HistoriesApiTestCase(api.ApiTestCase): def test_import_metadata_regeneration(self): history_name = "for_import_metadata_regeneration" history_id = self.dataset_populator.new_history(name=history_name) - self.dataset_populator.new_dataset(history_id, content=open(self.test_data_resolver.get_filename("1.bam")), file_type='bam') + self.dataset_populator.new_dataset(history_id, content=open(self.test_data_resolver.get_filename("1.bam"), 'rb'), file_type='bam') imported_history_id = self._reimport_history(history_id, history_name) self._assert_history_length(imported_history_id, 1) import_bam_metadata = self.dataset_populator.get_history_dataset_details( @@ -203,7 +203,7 @@ class HistoriesApiTestCase(api.ApiTestCase): assert bai_metadata["file_type"] == "bam_index" api_url = bai_metadata["download_url"].split("api/", 1)[1] bai_response = self._get(api_url) - assert bai_response.status_code == 200 + self._assert_status_code_is(bai_response, 200) assert len(bai_response.content) > 4 def test_import_export_collection(self):