Skip to content

Commit

Permalink
Adapt history contents API tests to use JSON payload
Browse files Browse the repository at this point in the history
See galaxyproject#12152 for details
  • Loading branch information
davelopez committed Oct 19, 2021
1 parent 9f2984d commit 80ca9d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
53 changes: 26 additions & 27 deletions lib/galaxy_test/api/test_history_contents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import time
import urllib
from datetime import datetime
Expand Down Expand Up @@ -169,7 +168,7 @@ def test_hda_copy(self):
)
second_history_id = self.dataset_populator.new_history()
assert self.__count_contents(second_history_id) == 0
create_response = self._post(f"histories/{second_history_id}/contents", create_data)
create_response = self._post(f"histories/{second_history_id}/contents", create_data, json=True)
self._assert_status_code_is(create_response, 200)
assert self.__count_contents(second_history_id) == 1

Expand All @@ -180,7 +179,7 @@ def test_library_copy(self):
content=ld["id"],
)
assert self.__count_contents(self.history_id) == 0
create_response = self._post(f"histories/{self.history_id}/contents", create_data)
create_response = self._post(f"histories/{self.history_id}/contents", create_data, json=True)
self._assert_status_code_is(create_response, 200)
assert self.__count_contents(self.history_id) == 1

Expand Down Expand Up @@ -324,18 +323,18 @@ def test_dataset_collection_create_from_exisiting_datasets_with_new_tags(self):
assert update_response['tags'] == ['existing:tag']
creation_payload = {'collection_type': 'list',
'history_id': history_id,
'element_identifiers': json.dumps([{'id': hda_id,
'src': 'hda',
'name': 'element_id1',
'tags': ['my_new_tag']},
{'id': hda2_id,
'src': 'hda',
'name': 'element_id2',
'tags': ['another_new_tag']}
]),
'element_identifiers': [{'id': hda_id,
'src': 'hda',
'name': 'element_id1',
'tags': ['my_new_tag']},
{'id': hda2_id,
'src': 'hda',
'name': 'element_id2',
'tags': ['another_new_tag']}
],
'type': 'dataset_collection',
'copy_elements': True}
r = self._post(f"histories/{self.history_id}/contents", creation_payload).json()
r = self._post(f"histories/{self.history_id}/contents", creation_payload, json=True).json()
assert r['elements'][0]['object']['id'] != hda_id, "HDA has not been copied"
assert len(r['elements'][0]['object']['tags']) == 1
assert r['elements'][0]['object']['tags'][0] == 'my_new_tag'
Expand All @@ -348,7 +347,7 @@ def _check_pair_creation(self, endpoint, payload):
pre_dataset_count = self.__count_contents(type="dataset")
pre_combined_count = self.__count_contents(type="dataset,dataset_collection")

dataset_collection_response = self._post(endpoint, payload)
dataset_collection_response = self._post(endpoint, payload, json=True)

dataset_collection = self.__check_create_collection_response(dataset_collection_response)

Expand Down Expand Up @@ -418,7 +417,7 @@ def test_dataset_collection_hide_originals(self):
)

payload["hide_source_items"] = True
dataset_collection_response = self._post(f"histories/{self.history_id}/contents", payload)
dataset_collection_response = self._post(f"histories/{self.history_id}/contents", payload, json=True)
self.__check_create_collection_response(dataset_collection_response)

contents_response = self._get(f"histories/{self.history_id}/contents")
Expand All @@ -430,10 +429,10 @@ def test_dataset_collection_hide_originals(self):

def test_update_dataset_collection(self):
hdca = self._create_pair_collection()
update_url = self._api_url(f"histories/{self.history_id}/contents/dataset_collections/{hdca['id']}", use_key=True)
# Awkward json.dumps required here because of https://trello.com/c/CQwmCeG6
body = json.dumps(dict(name="newnameforpair"))
update_response = put(update_url, data=body)
body = dict(name="newnameforpair")
update_response = self._put(
f"histories/{self.history_id}/contents/dataset_collections/{hdca['id']}", data=body, json=True
)
self._assert_status_code_is(update_response, 200)
show_response = self.__show(hdca)
assert str(show_response.json()["name"]) == "newnameforpair"
Expand All @@ -457,7 +456,7 @@ def _create_pair_collection(self):
self.history_id,
type="dataset_collection"
)
dataset_collection_response = self._post(f"histories/{self.history_id}/contents", payload)
dataset_collection_response = self._post(f"histories/{self.history_id}/contents", payload, json=True)
self._assert_status_code_is(dataset_collection_response, 200)
hdca = dataset_collection_response.json()
return hdca
Expand All @@ -471,7 +470,7 @@ def test_hdca_copy(self):
content=hdca_id,
)
assert len(self._get(f"histories/{second_history_id}/contents/dataset_collections").json()) == 0
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data)
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data, json=True)
self.__check_create_collection_response(create_response)
contents = self._get(f"histories/{second_history_id}/contents/dataset_collections").json()
assert len(contents) == 1
Expand All @@ -485,7 +484,7 @@ def test_hdca_copy_with_new_dbkey(self):
assert hdca["elements"][0]["object"]["metadata_dbkey"] == "?"
assert hdca["elements"][0]["object"]["genome_build"] == "?"
create_data = {'source': 'hdca', 'content': hdca_id, 'dbkey': 'hg19'}
create_response = self._post(f"histories/{self.history_id}/contents/dataset_collections", create_data)
create_response = self._post(f"histories/{self.history_id}/contents/dataset_collections", create_data, json=True)
collection = self.__check_create_collection_response(create_response)
new_forward = collection['elements'][0]['object']
assert new_forward["metadata_dbkey"] == "hg19"
Expand All @@ -501,7 +500,7 @@ def test_hdca_copy_and_elements(self):
copy_elements=True,
)
assert len(self._get(f"histories/{second_history_id}/contents/dataset_collections").json()) == 0
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data)
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data, json=True)
self.__check_create_collection_response(create_response)

contents = self._get(f"histories/{second_history_id}/contents/dataset_collections").json()
Expand Down Expand Up @@ -531,10 +530,10 @@ def test_hdca_from_library_datasets(self):
history_id=history_id,
type="dataset_collection",
name="Test From Library",
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)
create_response = self._post(f"histories/{history_id}/contents/dataset_collections", create_data)
create_response = self._post(f"histories/{history_id}/contents/dataset_collections", create_data, json=True)
hdca = self.__check_create_collection_response(create_response)
elements = hdca["elements"]
assert len(elements) == 1
Expand All @@ -552,12 +551,12 @@ def test_hdca_from_inaccessible_library_datasets(self):
history_id=self.history_id,
type="dataset_collection",
name="Test From Library",
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)
with self._different_user():
second_history_id = self.dataset_populator.new_history()
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data)
create_response = self._post(f"histories/{second_history_id}/contents/dataset_collections", create_data, json=True)
self._assert_status_code_is(create_response, 403)

def __check_create_collection_response(self, response):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy_test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ def __create_payload_collection(self, history_id, identifiers_func, collection_t
del kwds["contents"]

if "element_identifiers" not in kwds:
kwds["element_identifiers"] = json.dumps(identifiers_func(history_id, contents=contents))
kwds["element_identifiers"] = identifiers_func(history_id, contents=contents)

if "name" not in kwds:
kwds["name"] = "Test Dataset Collection"
Expand Down Expand Up @@ -1666,7 +1666,7 @@ def __init__(self, galaxy_interactor: ApiTestInteractor):
self.dataset_populator = DatasetPopulator(galaxy_interactor)

def _create_collection(self, payload: dict) -> Response:
create_response = self.galaxy_interactor.post("dataset_collections", data=payload)
create_response = self.galaxy_interactor.post("dataset_collections", data=payload, json=True)
return create_response


Expand Down

0 comments on commit 80ca9d5

Please sign in to comment.