diff --git a/tensorbay/client/struct.py b/tensorbay/client/struct.py index ecc9d12f1..f522c2c60 100644 --- a/tensorbay/client/struct.py +++ b/tensorbay/client/struct.py @@ -435,7 +435,7 @@ def _loads(self, contents: Dict[str, Any]) -> None: self.committer = User.loads(contents["committer"]) -class Draft(AttrsMixin, ReprMixin): +class Draft(AttrsMixin, ReprMixin): # pylint: disable=too-many-instance-attributes """This class defines the basic structure of a draft. Arguments: @@ -443,6 +443,9 @@ class Draft(AttrsMixin, ReprMixin): title: The title of the draft. branch_name: The branch name. status: The status of the draft. + parent_commit_id: The parent commit id. + author: The author of the draft. + updated_at: The time of last update. description: The draft description. """ @@ -455,15 +458,29 @@ class Draft(AttrsMixin, ReprMixin): title: str = attr() branch_name: str = attr(key=camel) status: str = attr() + parent_commit_id: str = attr(key=camel) + author: User = attr() + updated_at: int = attr(key=camel) description: str = attr(default="") def __init__( # pylint: disable=too-many-arguments - self, number: int, title: str, branch_name: str, status: str, description: str = "" + self, + number: int, + title: str, + branch_name: str, + status: str, + parent_commit_id: str, + author: User, + updated_at: int, + description: str = "", ) -> None: self.number = number self.title = title self.branch_name = branch_name self.status = status + self.parent_commit_id = parent_commit_id + self.author = author + self.updated_at = updated_at self.description = description def _repr_head(self) -> str: @@ -481,6 +498,12 @@ def loads(cls: Type[_T], contents: Dict[str, Any]) -> _T: "title": "branchName": "status": "OPEN", "CLOSED" or "COMMITTED" + "parentCommitId": + "author": { + "name": + "date": + } + "updatedAt": "description": } @@ -501,6 +524,12 @@ def dumps(self) -> Dict[str, Any]: "title": "branchName": "status": "OPEN", "CLOSED" or "COMMITTED" + "parentCommitId": + "author": { + "name": + "date": + } + "updatedAt": "description": } diff --git a/tensorbay/client/tests/test_gas.py b/tensorbay/client/tests/test_gas.py index 2966e6875..602ec95a4 100644 --- a/tensorbay/client/tests/test_gas.py +++ b/tensorbay/client/tests/test_gas.py @@ -12,7 +12,7 @@ from tensorbay.client.dataset import DatasetClient, FusionDatasetClient from tensorbay.client.gas import DEFAULT_BRANCH, DEFAULT_IS_PUBLIC, GAS from tensorbay.client.status import Status -from tensorbay.client.struct import ROOT_COMMIT_ID, Draft +from tensorbay.client.struct import ROOT_COMMIT_ID, Draft, User from tensorbay.client.tests.utility import mock_response from tensorbay.dataset import Dataset from tensorbay.exception import DatasetTypeError, ResourceNotExistError @@ -509,7 +509,17 @@ def test_upload_dataset(self, mocker): # upload the dataset in main branch containing a draft list_drafts = mocker.patch( f"{gas.__name__}.DatasetClient.list_drafts", - return_value=[Draft(1, "title", DEFAULT_BRANCH, "OPEN")], + return_value=[ + Draft( + 1, + "title", + DEFAULT_BRANCH, + "OPEN", + "4c564ea07f4e47679ec8c63d238bb3a1", + User("test", 1636967807), + 1637223060, + ) + ], ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") self.gas_client.upload_dataset(dataset) @@ -533,7 +543,17 @@ def test_upload_dataset(self, mocker): # upload the dataset in dev branch containing a draft list_drafts = mocker.patch( f"{gas.__name__}.DatasetClient.list_drafts", - return_value=[Draft(1, "title", "dev", "OPEN")], + return_value=[ + Draft( + 1, + "title", + "dev", + "OPEN", + "4c564ea07f4e47679ec8c63d238bb3a1", + User("test", 1636967807), + 1637223060, + ) + ], ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") self.gas_client.upload_dataset(dataset, branch_name="dev") diff --git a/tensorbay/client/tests/test_struct.py b/tensorbay/client/tests/test_struct.py index e2d8978c0..a76de7a18 100644 --- a/tensorbay/client/tests/test_struct.py +++ b/tensorbay/client/tests/test_struct.py @@ -41,12 +41,18 @@ _DRAFT_TITLE = "draft title" _DRAFT_BRANCH_NAME = "main" _DRAFT_STATUS = "OPEN" +_DRAFT_PARENT_COMMIT_ID = "4c564ea07f4e47679ec8c63d238bb3a1" +_DRAFT_UPDATED_AT = 1637223060 +_DRAFT_AUTHOR = User("draft author", 1636967807) _DRAFT_DESCRIPTION = "description" _DRAFT_DATA = { "number": _DRAFT_NUMBER, "title": _DRAFT_TITLE, "branchName": _DRAFT_BRANCH_NAME, "status": _DRAFT_STATUS, + "parentCommitId": _DRAFT_PARENT_COMMIT_ID, + "author": {"name": "draft author", "date": 1636967807}, + "updatedAt": _DRAFT_UPDATED_AT, } @@ -139,12 +145,23 @@ def test_loads(self): class TestDraft: def test_init(self): draft = Draft( - _DRAFT_NUMBER, _DRAFT_TITLE, _DRAFT_BRANCH_NAME, _DRAFT_STATUS, _DRAFT_DESCRIPTION + _DRAFT_NUMBER, + _DRAFT_TITLE, + _DRAFT_BRANCH_NAME, + _DRAFT_STATUS, + _DRAFT_PARENT_COMMIT_ID, + _DRAFT_AUTHOR, + _DRAFT_UPDATED_AT, + _DRAFT_DESCRIPTION, ) assert draft.number == _DRAFT_NUMBER assert draft.title == _DRAFT_TITLE assert draft.status == _DRAFT_STATUS + assert draft.branch_name == _DRAFT_BRANCH_NAME assert draft.description == _DRAFT_DESCRIPTION + assert draft.parent_commit_id == _DRAFT_PARENT_COMMIT_ID + assert draft.author == _DRAFT_AUTHOR + assert draft.updated_at == _DRAFT_UPDATED_AT def test_loads(self): draft = Draft.loads(_DRAFT_DATA) @@ -152,7 +169,18 @@ def test_loads(self): assert draft.title == _DRAFT_DATA["title"] assert draft.branch_name == _DRAFT_DATA["branchName"] assert draft.status == _DRAFT_DATA["status"] + assert draft.parent_commit_id == _DRAFT_DATA["parentCommitId"] + assert draft.author == User.loads(_DRAFT_DATA["author"]) + assert draft.updated_at == _DRAFT_DATA["updatedAt"] def test_dumps(self): - draft = Draft(_DRAFT_NUMBER, _DRAFT_TITLE, _DRAFT_BRANCH_NAME, _DRAFT_STATUS) + draft = Draft( + _DRAFT_NUMBER, + _DRAFT_TITLE, + _DRAFT_BRANCH_NAME, + _DRAFT_STATUS, + _DRAFT_PARENT_COMMIT_ID, + _DRAFT_AUTHOR, + _DRAFT_UPDATED_AT, + ) assert draft.dumps() == _DRAFT_DATA diff --git a/tensorbay/conftest.py b/tensorbay/conftest.py index 82299fc50..8108cd94d 100644 --- a/tensorbay/conftest.py +++ b/tensorbay/conftest.py @@ -236,6 +236,9 @@ def mock_list_drafts(mocker, branch_name): "title": "draft1", "branchName": branch_name, "status": "OPEN", + "parentCommitId": "4c564ea07f4e47679ec8c63d238bb3a1", + "author": {"name": "draft author", "date": 1636967807}, + "updatedAt": 1636967807, "description": "first draft of test_draft", }, { @@ -243,6 +246,9 @@ def mock_list_drafts(mocker, branch_name): "title": "", "branchName": branch_name, "status": "CLOSED", + "parentCommitId": "4c564ea07f4e47679ec8c63d238bb3a1", + "author": {"name": "draft author", "date": 1636967807}, + "updatedAt": 1636967807, "description": "", }, ]