diff --git a/tensorbay/client/struct.py b/tensorbay/client/struct.py index ecc9d12f1..5d1a8c848 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: @@ -444,6 +444,9 @@ class Draft(AttrsMixin, ReprMixin): branch_name: The branch name. status: The status of the draft. description: The draft description. + parent_commit_id: The parent commit id. + author: The author of the draft. + update_time: The time of last update. """ @@ -456,15 +459,29 @@ class Draft(AttrsMixin, ReprMixin): branch_name: str = attr(key=camel) status: str = attr() description: str = attr(default="") + parent_commit_id: str = attr(key=camel) + author: User = attr() + update_time: int = attr(key=lambda _: "updateAt") 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, + author: User, + update_time: int, + parent_commit_id: str, + description: str = "", ) -> None: self.number = number self.title = title self.branch_name = branch_name self.status = status self.description = description + self.parent_commit_id = parent_commit_id + self.author = author + self.update_time = update_time def _repr_head(self) -> str: return f"{self.__class__.__name__}({self.number})" @@ -482,6 +499,12 @@ def loads(cls: Type[_T], contents: Dict[str, Any]) -> _T: "branchName": "status": "OPEN", "CLOSED" or "COMMITTED" "description": + "parentCommitId": + "committer": { + "name": + "date": + } + "update_time": } Returns: @@ -502,6 +525,12 @@ def dumps(self) -> Dict[str, Any]: "branchName": "status": "OPEN", "CLOSED" or "COMMITTED" "description": + "parentCommitId": + "committer": { + "name": + "date": + } + "update_time": } """ diff --git a/tensorbay/client/tests/test_gas.py b/tensorbay/client/tests/test_gas.py index 2966e6875..c4cdf31bf 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", + User("test", 1636967807), + 1637223060, + "4c564ea07f4e47679ec8c63d238bb3a1", + ) + ], ) 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", + User("test", 1636967807), + 1637223060, + "4c564ea07f4e47679ec8c63d238bb3a1", + ) + ], ) 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..8b0e06b0f 100644 --- a/tensorbay/client/tests/test_struct.py +++ b/tensorbay/client/tests/test_struct.py @@ -42,11 +42,17 @@ _DRAFT_BRANCH_NAME = "main" _DRAFT_STATUS = "OPEN" _DRAFT_DESCRIPTION = "description" +_DRAFT_PARENT_COMMIT_ID = "4c564ea07f4e47679ec8c63d238bb3a1" +_DRAFT_UPDATE_TIME = 1637223060 +_DRAFT_AUTHOR = User("draft author", 1636967807) _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}, + "updateAt": _DRAFT_UPDATE_TIME, } @@ -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_AUTHOR, + _DRAFT_UPDATE_TIME, + _DRAFT_PARENT_COMMIT_ID, + _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.author == _DRAFT_AUTHOR + assert draft.update_time == _DRAFT_UPDATE_TIME + assert draft.parent_commit_id == _DRAFT_PARENT_COMMIT_ID 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.update_time == _DRAFT_DATA["updateAt"] + assert draft.author == User.loads(_DRAFT_DATA["author"]) 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_AUTHOR, + _DRAFT_UPDATE_TIME, + _DRAFT_PARENT_COMMIT_ID, + ) assert draft.dumps() == _DRAFT_DATA diff --git a/tensorbay/conftest.py b/tensorbay/conftest.py index 82299fc50..513227637 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}, + "updateAt": 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}, + "updateAt": 1636967807, "description": "", }, ]