Skip to content

Commit a640ad1

Browse files
authored
Type refactor for runtimeStatus (#187)
1 parent c99c472 commit a640ad1

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

azure/durable_functions/models/DurableOrchestrationClient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ async def wait_for_completion_or_create_check_status_response(
442442
lambda: self._create_http_response(500, status.to_json()),
443443
}
444444

445-
result = switch_statement.get(OrchestrationRuntimeStatus(status.runtime_status))
445+
result = switch_statement.get(status.runtime_status)
446446
if result:
447447
return result()
448448

azure/durable_functions/models/DurableOrchestrationStatus.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from dateutil.parser import parse as dt_parse
33
from typing import Any, List, Dict, Optional, Union
4-
4+
from .OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
55
from .utils.json_utils import add_attrib, add_datetime_attrib
66

77

@@ -15,7 +15,8 @@ class DurableOrchestrationStatus:
1515
def __init__(self, name: Optional[str] = None, instanceId: Optional[str] = None,
1616
createdTime: Optional[str] = None, lastUpdatedTime: Optional[str] = None,
1717
input: Optional[Any] = None, output: Optional[Any] = None,
18-
runtimeStatus: Optional[str] = None, customStatus: Optional[Any] = None,
18+
runtimeStatus: Optional[OrchestrationRuntimeStatus] = None,
19+
customStatus: Optional[Any] = None,
1920
history: Optional[List[Any]] = None,
2021
**kwargs):
2122
self._name: Optional[str] = name
@@ -26,7 +27,9 @@ def __init__(self, name: Optional[str] = None, instanceId: Optional[str] = None,
2627
if lastUpdatedTime is not None else None
2728
self._input: Any = input
2829
self._output: Any = output
29-
self._runtime_status: Optional[str] = runtimeStatus # TODO: GH issue 178
30+
self._runtime_status: Optional[OrchestrationRuntimeStatus] = runtimeStatus
31+
if runtimeStatus is not None:
32+
self._runtime_status = OrchestrationRuntimeStatus(runtimeStatus)
3033
self._custom_status: Any = customStatus
3134
self._history: Optional[List[Any]] = history
3235
if kwargs is not None:
@@ -82,7 +85,8 @@ def to_json(self) -> Dict[str, Union[int, str]]:
8285
add_datetime_attrib(json, self, 'last_updated_time', 'lastUpdatedTime')
8386
add_attrib(json, self, 'output')
8487
add_attrib(json, self, 'input_', 'input')
85-
add_attrib(json, self, 'runtime_status', 'runtimeStatus')
88+
if self.runtime_status is not None:
89+
json["runtimeStatus"] = self.runtime_status.name
8690
add_attrib(json, self, 'custom_status', 'customStatus')
8791
add_attrib(json, self, 'history')
8892
return json
@@ -129,7 +133,7 @@ def output(self) -> Any:
129133
return self._output
130134

131135
@property
132-
def runtime_status(self) -> Optional[str]:
136+
def runtime_status(self) -> Optional[OrchestrationRuntimeStatus]:
133137
"""Get the runtime status of the orchestration instance."""
134138
return self._runtime_status
135139

tests/models/test_DurableOrchestrationClient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def test_get_202_get_status_success(binding_string):
147147

148148
result = await client.get_status(TEST_INSTANCE_ID)
149149
assert result is not None
150-
assert result.runtime_status == "Running"
150+
assert result.runtime_status.name == "Running"
151151

152152

153153
@pytest.mark.asyncio
@@ -161,7 +161,7 @@ async def test_get_200_get_status_success(binding_string):
161161

162162
result = await client.get_status(TEST_INSTANCE_ID)
163163
assert result is not None
164-
assert result.runtime_status == "Completed"
164+
assert result.runtime_status.name == "Completed"
165165

166166

167167
@pytest.mark.asyncio

tests/models/test_DurableOrchestrationStatus.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from azure.durable_functions.constants import DATETIME_STRING_FORMAT
77
from azure.durable_functions.models.DurableOrchestrationStatus import DurableOrchestrationStatus
8+
from azure.durable_functions.models.OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
89
from azure.durable_functions.models.history import HistoryEventType
910

1011
TEST_NAME = 'what ever I want it to be'
@@ -38,7 +39,7 @@ def test_all_the_args():
3839

3940
result = DurableOrchestrationStatus.from_json(response)
4041

41-
assert result.runtime_status == TEST_RUNTIME_STATUS
42+
assert result.runtime_status.name == TEST_RUNTIME_STATUS
4243
assert result.custom_status == TEST_CUSTOM_STATUS
4344
assert result.instance_id == TEST_INSTANCE_ID
4445
assert result.output == TEST_OUTPUT

0 commit comments

Comments
 (0)