Skip to content

Commit

Permalink
Adapt 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 28, 2021
1 parent c5f8510 commit d401283
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ def run_tool(self, testdef, history_id, resource_parameters=None):
def _create_collection(self, history_id, collection_def):
create_payload = dict(
name=collection_def.name,
element_identifiers=dumps(self._element_identifiers(collection_def)),
element_identifiers=self._element_identifiers(collection_def),
collection_type=collection_def.collection_type,
history_id=history_id,
)
return self._post("dataset_collections", data=create_payload).json()["id"]
return self._post("dataset_collections", data=create_payload, json=True).json()["id"]

def _element_identifiers(self, collection_def):
element_identifiers = []
Expand Down
26 changes: 13 additions & 13 deletions lib/galaxy_test/api/test_dataset_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_create_pair_from_history(self):
self.history_id,
instance_type="history",
)
create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = self._check_create_response(create_response)
returned_datasets = dataset_collection["elements"]
assert len(returned_datasets) == 2, dataset_collection
Expand All @@ -33,11 +33,11 @@ def test_create_list_from_history(self):
payload = dict(
instance_type="history",
history_id=self.history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)

create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = self._check_create_response(create_response)
returned_datasets = dataset_collection["elements"]
assert len(returned_datasets) == 3, dataset_collection
Expand All @@ -47,7 +47,7 @@ def test_create_list_of_existing_pairs(self):
self.history_id,
instance_type="history",
)
pair_create_response = self._post("dataset_collections", pair_payload)
pair_create_response = self._post("dataset_collections", pair_payload, json=True)
dataset_collection = self._check_create_response(pair_create_response)
hdca_id = dataset_collection["id"]

Expand All @@ -58,10 +58,10 @@ def test_create_list_of_existing_pairs(self):
payload = dict(
instance_type="history",
history_id=self.history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)
create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = self._check_create_response(create_response)
returned_collections = dataset_collection["elements"]
assert len(returned_collections) == 1, dataset_collection
Expand All @@ -73,9 +73,9 @@ def test_create_list_of_new_pairs(self):
instance_type="history",
history_id=self.history_id,
name="a nested collection",
element_identifiers=json.dumps(identifiers),
element_identifiers=identifiers,
)
create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = self._check_create_response(create_response)
assert dataset_collection["collection_type"] == "list:paired"
assert dataset_collection["name"] == "a nested collection"
Expand Down Expand Up @@ -169,10 +169,10 @@ def test_hda_security(self):
payload = dict(
instance_type="history",
history_id=history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="paired",
)
create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
self._assert_status_code_is(create_response, 403)

def test_enforces_unique_names(self):
Expand All @@ -181,11 +181,11 @@ def test_enforces_unique_names(self):
payload = dict(
instance_type="history",
history_id=self.history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)

create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
self._assert_status_code_is(create_response, 400)

def test_upload_collection(self):
Expand Down Expand Up @@ -488,7 +488,7 @@ def _compare_collection_contents_elements(self, contents_elements, hdca_elements
def _create_collection_contents_pair(self):
# Create a simple collection, return hdca and contents_url
payload = self.dataset_collection_populator.create_pair_payload(self.history_id, instance_type="history")
create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
hdca = self._check_create_response(create_response)
root_contents_url = self._get_contents_url_for_hdca(hdca)
return hdca, root_contents_url
Expand Down
22 changes: 11 additions & 11 deletions lib/galaxy_test/api/test_history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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 +418,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 +430,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 +457,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 Down Expand Up @@ -531,10 +531,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 +552,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
8 changes: 4 additions & 4 deletions lib/galaxy_test/api/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,11 +1941,11 @@ def test_identifier_with_data_collection(self, history_id):
payload = dict(
instance_type="history",
history_id=history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)

create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = create_response.json()

inputs = {
Expand All @@ -1972,11 +1972,11 @@ def test_identifier_in_actions(self, history_id):
payload = dict(
instance_type="history",
history_id=history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type="list",
)

create_response = self._post("dataset_collections", payload)
create_response = self._post("dataset_collections", payload, json=True)
dataset_collection = create_response.json()

inputs = {
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy_test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ def create_nested_collection(self, history_id, collection_type, name=None, colle
payload = dict(
instance_type="history",
history_id=history_id,
element_identifiers=json.dumps(element_identifiers),
element_identifiers=element_identifiers,
collection_type=collection_type,
name=name,
)
Expand Down Expand Up @@ -1594,7 +1594,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 @@ -1672,7 +1672,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 Expand Up @@ -1861,7 +1861,7 @@ def __init__(self, gi):
self.dataset_collection_populator = GiDatasetCollectionPopulator(gi)

def _create_collection(self, payload):
create_response = self._post("dataset_collections", data=payload)
create_response = self._post("dataset_collections", data=payload, json=True)
return create_response


Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/selenium/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def __init__(self, selenium_context: GalaxySeleniumContext):
self.dataset_populator = SeleniumSessionDatasetPopulator(selenium_context)

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


Expand Down

0 comments on commit d401283

Please sign in to comment.