Import regeneration test case.

This commit is contained in:
John Chilton
2019-01-07 20:17:11 -05:00
parent 681225bc9c
commit 38f7aded0b
3 changed files with 36 additions and 16 deletions
+7
View File
@@ -2250,6 +2250,13 @@ class SetMetadataTool(Tool):
tool_type = 'set_metadata'
requires_setting_metadata = False
def regenerate_imported_metadata_if_needed(self, hda, history, job):
if hda.extension == 'bam':
self.tool_action.execute_via_app(
self, self.app, job.session_id,
history.id, job.user, incoming={'input1': hda}, overwrite=False
)
def exec_after_process(self, app, inp_data, out_data, param_dict, job=None):
for name, dataset in inp_data.items():
external_metadata = JobExternalOutputMetadataWrapper(job)
+3 -6
View File
@@ -182,12 +182,9 @@ class JobImportHistoryArchiveWrapper(UsesAnnotations):
self.sa_session.flush()
"""
# Although metadata is set above, need to set metadata to recover BAI for BAMs.
if hda.extension == 'bam':
self.app.datatypes_registry.set_external_metadata_tool.tool_action.execute_via_app(
self.app.datatypes_registry.set_external_metadata_tool, self.app, jiha.job.session_id,
new_history.id, jiha.job.user, incoming={'input1': hda}, overwrite=False
)
self.app.datatypes_registry.set_external_metadata_tool.regenerate_imported_metadata_if_needed(
hda, new_history, jiha.job
)
#
# Create jobs.
+26 -10
View File
@@ -182,17 +182,30 @@ class HistoriesApiTestCase(api.ApiTestCase):
history_id = self.dataset_populator.new_history(name=history_name)
self.dataset_populator.new_dataset(history_id, content="1 2 3")
imported_history_id = self._reimport_history(history_id, history_name)
contents_response = self._get("histories/%s/contents" % imported_history_id)
self._assert_status_code_is(contents_response, 200)
contents = contents_response.json()
assert len(contents) == 1
self._assert_history_length(imported_history_id, 1)
imported_content = self.dataset_populator.get_history_dataset_content(
history_id=imported_history_id,
dataset_id=contents[0]["id"]
hid=1,
)
assert imported_content == "1 2 3\n"
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')
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(
history_id=imported_history_id,
hid=1,
)
bai_metadata = import_bam_metadata["meta_files"][0]
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
assert len(bai_response.content) > 4
def test_import_export_collection(self):
from nose.plugins.skip import SkipTest
raise SkipTest("Collection import/export not yet implemented")
@@ -203,10 +216,7 @@ class HistoriesApiTestCase(api.ApiTestCase):
imported_history_id = self._reimport_history(history_id, history_name)
contents_response = self._get("histories/%s/contents" % imported_history_id)
self._assert_status_code_is(contents_response, 200)
contents = contents_response.json()
assert len(contents) == 3
self._assert_history_length(imported_history_id, 3)
def _reimport_history(self, history_id, history_name):
# Ensure the history is ready to go...
@@ -242,6 +252,12 @@ class HistoriesApiTestCase(api.ApiTestCase):
return imported_history_id
def _assert_history_length(self, history_id, n):
contents_response = self._get("histories/%s/contents" % history_id)
self._assert_status_code_is(contents_response, 200)
contents = contents_response.json()
assert len(contents) == n, contents
def test_create_tag(self):
post_data = dict(name="TestHistoryForTag")
history_id = self._post("histories", data=post_data).json()["id"]