Skip to content

Commit b5d2707

Browse files
committed
Add tests for copying datasets with copied_from fields in history and library
1 parent e54bc97 commit b5d2707

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/galaxy_test/api/test_datasets.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,33 @@ def test_download_non_english_characters(self, history_id):
920920
response = self._get(f"histories/{history_id}/contents/{hda['id']}/display?to_ext=json")
921921
self._assert_status_code_is(response, 200)
922922
assert quote(name, safe="") in response.headers["Content-Disposition"]
923+
924+
def test_copy_dataset_from_history_with_copied_from_fields(self, history_id):
925+
original_hda = self.dataset_populator.new_dataset(history_id, content="original data", wait=True)
926+
self._assert_copied_from_fields(history_id, original_hda["id"], None, None, None)
927+
928+
copy_payload = {"content": original_hda["id"], "source": "hda", "type": "dataset"}
929+
copied_hda_id = self._post(f"histories/{history_id}/contents", data=copy_payload, json=True).json()["id"]
930+
self._assert_copied_from_fields(history_id, copied_hda_id, original_hda["id"], None, None)
931+
932+
@requires_new_library
933+
def test_copy_dataset_from_library_with_copied_from_fields(self, history_id):
934+
library_dataset = self.library_populator.new_library_dataset("test_library_dataset")
935+
copy_payload = {"content": library_dataset["id"], "source": "library", "type": "dataset"}
936+
copied_hda_id = self._post(f"histories/{history_id}/contents", data=copy_payload, json=True).json()["id"]
937+
self._assert_copied_from_fields(
938+
history_id, copied_hda_id, None, library_dataset["ldda_id"], library_dataset["ldda_id"]
939+
)
940+
941+
def _assert_copied_from_fields(
942+
self, history_id, hda_id, expected_history_id, expected_ldda_id, expected_library_id
943+
):
944+
keys = "copied_from_history_dataset_association_id,copied_from_ldda_id,copied_from_library_dataset_dataset_association_id"
945+
for url in [
946+
f"datasets/{hda_id}?keys={keys}",
947+
f"histories/{history_id}/contents/datasets/{hda_id}?keys={keys}",
948+
]:
949+
data = self._get(url).json()
950+
assert data["copied_from_history_dataset_association_id"] == expected_history_id
951+
assert data["copied_from_ldda_id"] == expected_ldda_id
952+
assert data["copied_from_library_dataset_dataset_association_id"] == expected_library_id

0 commit comments

Comments
 (0)