def test_upload_dataset(self, mocker): dataset = Dataset("test") dataset.load_catalog( os.path.join( os.path.dirname(__file__), "..", "..", "opendataset", "HeadPoseImage", "catalog.json", )) for i in range(5): dataset.create_segment(str(i)) # upload the dataset in main branch containing no draft get_dataset = mocker.patch( f"{gas.__name__}.GAS.get_dataset", return_value=DatasetClient( "test", "12345", self.gas_client, status=Status(DEFAULT_BRANCH, commit_id=ROOT_COMMIT_ID), alias="", is_public=False, ), ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") list_drafts = mocker.patch(f"{gas.__name__}.DatasetClient.list_drafts", return_value=[]) create_draft = mocker.patch( f"{gas.__name__}.DatasetClient.create_draft") upload_catalog = mocker.patch( f"{gas.__name__}.DatasetClient.upload_catalog") update_notes = mocker.patch( f"{gas.__name__}.DatasetClient.update_notes") _upload_segment = mocker.patch( f"{gas.__name__}.DatasetClient._upload_segment") self.gas_client.upload_dataset(dataset) assert not checkout.called get_dataset.assert_called_once_with(dataset.name, False) list_drafts.assert_called_once_with(branch_name=DEFAULT_BRANCH) create_draft.assert_called_once_with( 'Draft autogenerated by "GAS.upload_dataset"', branch_name=DEFAULT_BRANCH) upload_catalog.assert_called_once_with(dataset.catalog) update_notes.assert_called_once_with(**dataset.notes) assert _upload_segment.call_count == 5 # 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", "4c564ea07f4e47679ec8c63d238bb3a1", User("test", 1636967807), 1637223060, ) ], ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") self.gas_client.upload_dataset(dataset) list_drafts.assert_called_once_with(branch_name=DEFAULT_BRANCH) checkout.assert_called_once_with(draft_number=1) # upload the dataset in dev branch containing no draft list_drafts = mocker.patch( f"{gas.__name__}.DatasetClient.list_drafts", return_value=[], ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") create_draft = mocker.patch( f"{gas.__name__}.DatasetClient.create_draft") self.gas_client.upload_dataset(dataset, branch_name="dev") assert not checkout.called list_drafts.assert_called_once_with(branch_name="dev") create_draft.assert_called_once_with( 'Draft autogenerated by "GAS.upload_dataset"', branch_name="dev") # 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", "4c564ea07f4e47679ec8c63d238bb3a1", User("test", 1636967807), 1637223060, ) ], ) checkout = mocker.patch(f"{gas.__name__}.DatasetClient.checkout") self.gas_client.upload_dataset(dataset, branch_name="dev") list_drafts.assert_called_once_with(branch_name="dev") checkout.assert_called_once_with(draft_number=1)
def test_init(self): user = User(_USER_NAME, _DATE) assert user.name == _USER_NAME assert user.date == _DATE
def test_dumps(self): user = User(_USER_NAME, _DATE) assert user.dumps() == _USER_DATA
_BRANCH_DATA = { "name": "main", "commitId": ROOT_COMMIT_ID, "parentCommitId": ROOT_COMMIT_ID, "title": None, "description": "", "committer": None, } _DRAFT_NUMBER = 1 _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, } class TestUser: def test_init(self): user = User(_USER_NAME, _DATE)