Skip to content

Commit

Permalink
add respons code
Browse files Browse the repository at this point in the history
  • Loading branch information
tilen1976 committed Dec 16, 2024
1 parent 474fd98 commit 371b2a8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/dapla_metadata/variable_definitions/variable_definition.py
Original file line number Diff line number Diff line change
@@ -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,
)
Expand Down Expand Up @@ -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"
16 changes: 16 additions & 0 deletions tests/variable_definitions/test_vardef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 371b2a8

Please sign in to comment.