Skip to content

Commit

Permalink
fix: fixing a bug that confuses types
Browse files Browse the repository at this point in the history
  • Loading branch information
hamakou108 committed Jun 4, 2023
1 parent d6898ae commit c6a6133
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 45 deletions.
21 changes: 4 additions & 17 deletions depwatch/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,14 @@ def __is_succeeded_workflows(workflow) -> bool:
)

for id in workflow_ids:
workflows = __get_workflow(id)
succeeded_workflows = filter(__is_succeeded_workflows, workflows)

first_succeeded_workflow = None
for w in succeeded_workflows:
if first_succeeded_workflow is None:
first_succeeded_workflow = w
continue

if datetime.fromisoformat(w.get("stopped_at")) < datetime.fromisoformat(
first_succeeded_workflow.get("stopped_at")
):
first_succeeded_workflow = w

if first_succeeded_workflow is None:
workflow = __get_workflow(id)
if not __is_succeeded_workflows(workflow):
continue

histories.append(
DeploymentHistory(
first_succeeded_workflow.get("id"),
datetime.fromisoformat(first_succeeded_workflow.get("stopped_at")),
workflow.get("id"),
datetime.fromisoformat(workflow.get("stopped_at")),
)
)

Expand Down
48 changes: 20 additions & 28 deletions tests/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ class TestDeployment:
def test_get_deployment_history(self, mock_Api: Mock):
mock_ci = MagicMock()
mock_ci.get_workflow.side_effect = [
[
{
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "success",
"stopped_at": "2023-01-01T00:00:00.000Z",
},
],
[
{
"id": "84abef06-1fa2-48ec-875e-382e9b7add78",
"status": "success",
"stopped_at": "2023-01-02T00:00:00.000Z",
},
],
{
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "success",
"stopped_at": "2023-01-01T00:00:00.000Z",
},
{
"id": "84abef06-1fa2-48ec-875e-382e9b7add78",
"status": "success",
"stopped_at": "2023-01-02T00:00:00.000Z",
},
]
mock_Api.return_value = mock_ci

Expand Down Expand Up @@ -64,13 +60,11 @@ def test_get_deployment_history_when_the_workflow_has_not_been_completed_then_th
self, mock_Api: Mock
):
mock_ci = MagicMock()
mock_ci.get_workflow.return_value = [
{
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "success",
"stopped_at": None,
},
]
mock_ci.get_workflow.return_value = {
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "success",
"stopped_at": None,
}
mock_Api.return_value = mock_ci

workflow_ids = [
Expand All @@ -85,13 +79,11 @@ def test_get_deployment_history_when_the_workflow_is_not_successful_then_the_ite
self, mock_Api: Mock
):
mock_ci = MagicMock()
mock_ci.get_workflow.return_value = [
{
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "failed",
"stopped_at": "2023-01-01T00:00:00.000Z",
},
]
mock_ci.get_workflow.return_value = {
"id": "40020909-fd66-4657-b3e4-8872627507d2",
"status": "failed",
"stopped_at": "2023-01-01T00:00:00.000Z",
}
mock_Api.return_value = mock_ci

workflow_ids = [
Expand Down

0 comments on commit c6a6133

Please sign in to comment.