Skip to content

Commit 9aed4b6

Browse files
authored
Fix publish external draft variable (#387)
* test that all status is handled correct * coorect comparison * other test covers the scenario
1 parent 156db20 commit 9aed4b6

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/dapla_metadata/variable_definitions/variable_definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def publish_external(self) -> "VariableDefinition":
377377
raise ValueError(
378378
msg,
379379
)
380-
if self.variable_status is VariableStatus.DRAFT:
380+
if self.variable_status == VariableStatus.DRAFT.name:
381381
update = self.update_draft(
382382
UpdateDraft(variable_status=VariableStatus.PUBLISHED_EXTERNAL),
383383
)

tests/variable_definitions/test_variable_definition.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,28 +407,34 @@ def test_publish_methods(
407407
):
408408
variable_definition.variable_status = initial_status
409409
method_to_call = getattr(variable_definition, method_name)
410-
if initial_status is VariableStatus.PUBLISHED_EXTERNAL:
410+
if initial_status == VariableStatus.PUBLISHED_EXTERNAL:
411411
# It doesn't make sense to publish other statuses internally
412412
with pytest.raises(ValueError, match="That won't work here."):
413413
method_to_call()
414414
elif method_name == "publish_internal":
415-
if initial_status is VariableStatus.DRAFT:
416-
# Normal publishing flow
415+
if initial_status == VariableStatus.DRAFT:
417416
method_to_call()
418417
mock_update_draft.assert_called_once_with(
419418
UpdateDraft(variable_status=expected_status),
420419
)
421420
mock_create_patch.assert_not_called()
422-
else:
423-
# It doesn't make sense to publish other statuses internally
421+
if initial_status == VariableStatus.PUBLISHED_INTERNAL:
422+
# It doesn't make sense to publish internally already published internally
424423
with pytest.raises(ValueError, match="That won't work here."):
425424
method_to_call()
426-
else:
427-
method_to_call()
428-
mock_update_draft.assert_not_called()
429-
mock_create_patch.assert_called_once_with(
430-
CreatePatch(variable_status=VariableStatus.PUBLISHED_EXTERNAL),
431-
)
425+
elif method_name == "publish_external":
426+
if initial_status == VariableStatus.PUBLISHED_INTERNAL:
427+
method_to_call()
428+
mock_update_draft.assert_not_called()
429+
mock_create_patch.assert_called_once_with(
430+
CreatePatch(variable_status=VariableStatus.PUBLISHED_EXTERNAL),
431+
)
432+
if initial_status == VariableStatus.DRAFT:
433+
method_to_call()
434+
mock_update_draft.assert_called_once_with(
435+
UpdateDraft(variable_status=expected_status),
436+
)
437+
mock_create_patch.assert_not_called()
432438

433439

434440
def test_str(variable_definition):

0 commit comments

Comments
 (0)