From 371b2a8aa8e610fc367f07c667dcc32341730928 Mon Sep 17 00:00:00 2001 From: Cecilie Seim <68303562+tilen1976@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:14:29 +0100 Subject: [PATCH] add respons code --- .../variable_definition.py | 22 +++++++++++++++++++ tests/variable_definitions/test_vardef.py | 16 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/dapla_metadata/variable_definitions/variable_definition.py b/src/dapla_metadata/variable_definitions/variable_definition.py index 10f41ff..4fd3714 100644 --- a/src/dapla_metadata/variable_definitions/variable_definition.py +++ b/src/dapla_metadata/variable_definitions/variable_definition.py @@ -1,4 +1,9 @@ +from dapla_metadata.variable_definitions import config from dapla_metadata.variable_definitions._client import VardefClient +from dapla_metadata.variable_definitions.exceptions import vardef_exception_handler +from dapla_metadata.variable_definitions.generated.vardef_client.api.draft_variable_definitions_api import ( + DraftVariableDefinitionsApi, +) from dapla_metadata.variable_definitions.generated.vardef_client.api.patches_api import ( PatchesApi, ) @@ -53,3 +58,20 @@ def get_patch(self, patch_id: int) -> CompleteResponse: variable_definition_id=self.id, patch_id=patch_id, ) + + @vardef_exception_handler + def delete_draft( + self, + ) -> int: + """Update a Draft variable definition.""" + return ( + DraftVariableDefinitionsApi( + VardefClient.get_client(), + ) + .delete_variable_definition_by_id_with_http_info( + variable_definition_id=self.id, + active_group=config.get_active_group(), + ) + .status_code + ) + # return f"Variable {self.id} safely deleted" diff --git a/tests/variable_definitions/test_vardef.py b/tests/variable_definitions/test_vardef.py index ea5dddf..3c81242 100644 --- a/tests/variable_definitions/test_vardef.py +++ b/tests/variable_definitions/test_vardef.py @@ -98,6 +98,22 @@ def test_create_draft( assert my_draft.variable_status == VariableStatus.DRAFT +def test_delete_draft( + monkeypatch: pytest.MonkeyPatch, + client_configuration: Configuration, + draft: Draft, +): + monkeypatch.setenv(DAPLA_GROUP_CONTEXT, VARDEF_EXAMPLE_ACTIVE_GROUP) + VardefClient.set_config(client_configuration) + my_draft = Vardef.create_draft( + draft=draft, + ) + assert my_draft.id is not None + result = my_draft.delete_draft() + assert result == 204 + # assert result == f"Variable {VARDEF_EXAMPLE_DEFINITION_ID} safely deleted" + + def test_migrate_from_vardok( monkeypatch: pytest.MonkeyPatch, client_configuration: Configuration,