Exemplo n.º 1
0
 def test_loads(self):
     commit = Commit.loads(_COMMIT_DATA)
     assert commit.commit_id == _COMMIT_DATA["commitId"]
     assert commit.title == _COMMIT_DATA["title"]
     assert commit.description == _COMMIT_DATA["description"]
     assert commit.committer == User.loads(_COMMIT_DATA["committer"])
     assert commit.parent_commit_id == _COMMIT_DATA["parentCommitId"]
Exemplo n.º 2
0
 def test_init(self):
     user = User.loads(_USER_DATA)
     commit = Commit(_COMMIT_ID, _PARENT_COMMIT_ID, _TITLE, _DESCRIPTION, user)
     assert commit.commit_id == _COMMIT_ID
     assert commit.title == _TITLE
     assert commit.description == _DESCRIPTION
     assert commit.committer == user
     assert commit.parent_commit_id == _PARENT_COMMIT_ID
Exemplo n.º 3
0
 def test_loads(self):
     named_commit = _NamedCommit.loads(_NAMED_COMMIT_DATA)
     assert named_commit.name == _NAMED_COMMIT_DATA["name"]
     assert named_commit.commit_id == _NAMED_COMMIT_DATA["commitId"]
     assert named_commit.title == _NAMED_COMMIT_DATA["title"]
     assert named_commit.description == _NAMED_COMMIT_DATA["description"]
     assert named_commit.committer == User.loads(_NAMED_COMMIT_DATA["committer"])
     assert named_commit.parent_commit_id == _NAMED_COMMIT_DATA["parentCommitId"]
Exemplo n.º 4
0
 def test_loads(self):
     draft = Draft.loads(_DRAFT_DATA)
     assert draft.number == _DRAFT_DATA["number"]
     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"]
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def test_dumps(self):
     user = User.loads(_USER_DATA)
     commit = Commit(_COMMIT_ID, _PARENT_COMMIT_ID, _TITLE, _DESCRIPTION, user)
     assert commit.dumps() == _COMMIT_DATA
Exemplo n.º 7
0
 def test_dumps(self):
     user = User(_USER_NAME, _DATE)
     assert user.dumps() == _USER_DATA
Exemplo n.º 8
0
 def test_loads(self):
     user = User.loads(_USER_DATA)
     assert user.name == _USER_DATA["name"]
     assert user.date == _USER_DATA["date"]
Exemplo n.º 9
0
 def test_init(self):
     user = User(_USER_NAME, _DATE)
     assert user.name == _USER_NAME
     assert user.date == _DATE
Exemplo n.º 10
0
 def test_dumps(self):
     user = User.loads(_USER_DATA)
     named_commit = _NamedCommit(
         _COMMIT_NAME, _COMMIT_ID, _PARENT_COMMIT_ID, _TITLE, _DESCRIPTION, user
     )
     assert named_commit.dumps() == _NAMED_COMMIT_DATA
Exemplo n.º 11
0
_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)