From be6d1b2a10949d16910d5e9d80814f8ddc9ee9fb Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Fri, 25 Oct 2024 11:37:25 -0700 Subject: [PATCH] feat: add experiment.save_revision() --- README.md | 1 + cellengine/resources/experiment.py | 9 +++++++++ cellengine/utils/api_client/APIClient.py | 6 ++++++ tests/integration/test_experiment.py | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 03fcf7d9..7bb03002 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,4 @@ v1.0.0 will be the first stable release of the CellEngine Python Toolkit. permissions required for some operations. * All tests now run against a real CellEngine instance instead of using mocks, avoiding bugs due to stale mocks. +* Support for `experiment.save_revision()`. \ No newline at end of file diff --git a/cellengine/resources/experiment.py b/cellengine/resources/experiment.py index fb02613a..26060494 100644 --- a/cellengine/resources/experiment.py +++ b/cellengine/resources/experiment.py @@ -365,6 +365,15 @@ def undelete(self) -> None: self.deleted = None ce.APIClient().update_experiment(self._id, {"deleted": self.deleted}) + def save_revision(self, description: str) -> None: + """ + Saves a revision of the experiment. The new revision will be the last + entry in the `revisions` property. + """ + r = ce.APIClient().save_experiment_revision(self._id, description) + self._properties["revisions"] = r.get("revisions") + self._properties["deepUpdated"] = r.get("deepUpdated") + # Attachments @property diff --git a/cellengine/utils/api_client/APIClient.py b/cellengine/utils/api_client/APIClient.py index 2e485d5b..4a1c5538 100644 --- a/cellengine/utils/api_client/APIClient.py +++ b/cellengine/utils/api_client/APIClient.py @@ -352,6 +352,12 @@ def delete_experiment(self, _id): """ self._delete(f"{self.base_url}/api/v1/experiments/{_id}") + def save_experiment_revision(self, _id, description: str) -> Dict: + return self._post( + f"{self.base_url}/api/v1/experiments/{_id}/revision", + json={"description": description}, + ) + # ------------------------------- FCS Files -------------------------------- def get_fcs_files(self, experiment_id, as_dict=False) -> List[FcsFile]: diff --git a/tests/integration/test_experiment.py b/tests/integration/test_experiment.py index 61b4981e..d0376c42 100644 --- a/tests/integration/test_experiment.py +++ b/tests/integration/test_experiment.py @@ -111,6 +111,14 @@ def test_experiment_clone(blank_experiment: Experiment): assert exp.name == blank_experiment.name + "-1" +def test_save_revision(blank_experiment): + preDU = blank_experiment.deep_updated + blank_experiment.save_revision("my description") + assert len(blank_experiment.revisions) == 1 + assert blank_experiment.revisions[0].get("description") == "my description" + assert blank_experiment.deep_updated > preDU + + def test_experiment_upload_fcs_file(blank_experiment: Experiment): file = blank_experiment.upload_fcs_file( "tests/data/Specimen_001_A1_A01_MeOHperm(DL350neg).fcs"