Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tensorbay/client/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ def list_dataset_names(self) -> PagingList[str]:
lambda offset, limit: self._generate_dataset_names(None, offset, limit), 128
)

def update_dataset(
self,
name: str,
*,
alias: str = ..., # type: ignore[assignment]
) -> None:
"""Update a TensorBay Dataset.

Arguments:
name: Name of the dataset, unique for a user.
alias: New alias of the dataset.

"""
dataset_id = self._get_dataset(name)["id"]
patch_data = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if alias is ... and patch_data is {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request will be sent only if patch_data is not empty.

if alias is not ...: # type: ignore[comparison-overlap]
patch_data["alias"] = alias

self._client.open_api_do("PATCH", "", dataset_id, json=patch_data)

def rename_dataset(self, name: str, new_name: str) -> None:
"""Rename a TensorBay Dataset with given name.

Expand Down
18 changes: 17 additions & 1 deletion tensorbay/client/tests/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ def test_list_dataset_names(self, mocker):
assert list(datasets) == [data["name"] for data in response_data["datasets"]]
open_api_do.assert_called_once_with("GET", "", params=params)

def test_update_dataset(self, mocker):
response_data = {
"id": "123456",
"type": 1,
"commitId": "4",
"defaultBranch": DEFAULT_BRANCH,
}
open_api_do = mocker.patch(f"{gas.__name__}.Client.open_api_do")
mocker.patch(
f"{gas.__name__}.GAS._get_dataset",
return_value=response_data,
)
patch_data = {"alias": "new_alias"}
self.gas_client.update_dataset("test", alias="new_alias")
open_api_do.assert_called_once_with("PATCH", "", response_data["id"], json=patch_data)

def test_rename_dataset(self, mocker):
response_data = {
"id": "123456",
Expand All @@ -357,7 +373,7 @@ def test_rename_dataset(self, mocker):
return_value=response_data,
)
patch_data = {"name": "new_test"}
self.gas_client.rename_dataset("test", "new_test")
self.gas_client.rename_dataset("test", new_name="new_test")
open_api_do.assert_called_once_with("PATCH", "", response_data["id"], json=patch_data)

def test_upload_dataset(self, mocker):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ def test_get_fusion_dataset_to_latest_commit(self, accesskey, url):

gas_client.delete_dataset(dataset_name)

def test_update_dataset(self, accesskey, url):
gas_client = GAS(access_key=accesskey, url=url)
dataset_name = get_dataset_name()
gas_client.create_dataset(dataset_name)

new_dataset_alias = f"{get_dataset_name()}alias"
gas_client.update_dataset(name=dataset_name, alias=new_dataset_alias)
dataset_client = gas_client.get_dataset(dataset_name)
assert dataset_client.alias == new_dataset_alias
gas_client.delete_dataset(dataset_name)

dataset_name = get_dataset_name()
gas_client.create_dataset(dataset_name, alias="alias")
gas_client.update_dataset(name=dataset_name)
dataset_client = gas_client.get_dataset(dataset_name)
assert dataset_client.alias == "alias"
gas_client.delete_dataset(dataset_name)

def test_rename_dataset(self, accesskey, url):
gas_client = GAS(access_key=accesskey, url=url)
dataset_name = get_dataset_name()
Expand Down