Skip to content

Commit 0cb7871

Browse files
committed
PR feedback
1 parent 3a2f94b commit 0cb7871

File tree

9 files changed

+71
-7
lines changed

9 files changed

+71
-7
lines changed

samples-v2/blueprint/tests/readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Durable Functions Sample – Unit Tests (Python)
22

3+
## Overview
4+
35
This directory contains a simple **unit test** for the sample [Durable Azure Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview) written in Python. This test demonstrates how to validate the logic of the orchestrator function in isolation using mocks.
46

7+
Writing unit tests for Durable functions requires sligtly different syntax for accessing the original method definition. Orchestrator functions, client functions, and entity functions all come with their own ways to access the user code:
8+
9+
### Orchestrator functions
10+
```
11+
my_orchestrator.build().get_user_function().orchestrator_function
12+
```
13+
14+
### Client functions
15+
```
16+
my_client_function.build().get_user_function().client_function
17+
```
18+
19+
### Entity functions
20+
```
21+
my_entity_function.build().get_user_function().entity_function
22+
```
23+
24+
This sample app demonstrates using these accessors to get and test Durable functions. It also demonstrates how to mock the calling behavior that Durable uses to run orchestrators during replay with the orchestrator_generator_wrapper method defined in test_my_orchestrator.py and simulates the Tasks yielded by DurableOrchestrationContext with MockTask objects in the same file.
25+
526
## Prerequisites
627

728
- Python

samples-v2/blueprint/tests/test_my_orchestrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# A way to wrap an orchestrator generator to simplify calling it and getting the results.
88
# Because orchestrators in Durable Functions always accept the result of the previous activity for the next send() call,
9-
# we can simplify the orchestrator like this to also simplify per-test code.
9+
# we can unwrap the orchestrator generator using this method to simplify per-test code.
1010
def orchestrator_generator_wrapper(generator):
1111
previous = next(generator)
1212
yield previous

samples-v2/blueprint/tests/test_start_orchestrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_HttpStart(self, client):
1818
client.start_new = AsyncMock(return_value="instance_id")
1919
client.create_check_status_response = Mock(return_value="check_status_response")
2020

21-
# Create a generator using the method and mocked context
21+
# Execute the function code
2222
result = asyncio.run(func_call(req, client))
2323

2424
client.start_new.assert_called_once_with("my_orchestrator")

samples-v2/fan_in_fan_out/tests/readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Durable Functions Sample – Unit Tests (Python)
22

3+
## Overview
4+
35
This directory contains a simple **unit test** for the sample [Durable Azure Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview) written in Python. This test demonstrates how to validate the logic of the orchestrator function in isolation using mocks.
46

7+
Writing unit tests for Durable functions requires sligtly different syntax for accessing the original method definition. Orchestrator functions, client functions, and entity functions all come with their own ways to access the user code:
8+
9+
### Orchestrator functions
10+
```
11+
my_orchestrator.build().get_user_function().orchestrator_function
12+
```
13+
14+
### Client functions
15+
```
16+
my_client_function.build().get_user_function().client_function
17+
```
18+
19+
### Entity functions
20+
```
21+
my_entity_function.build().get_user_function().entity_function
22+
```
23+
24+
This sample app demonstrates using these accessors to get and test Durable functions. It also demonstrates how to mock the calling behavior that Durable uses to run orchestrators during replay with the orchestrator_generator_wrapper method defined in test_E2_BackupSiteContent.py and simulates the Tasks yielded by DurableOrchestrationContext with MockTask objects in the same file.
25+
526
## Prerequisites
627

728
- Python

samples-v2/fan_in_fan_out/tests/test_E2_BackupSiteContent.py

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

66
# A way to wrap an orchestrator generator to simplify calling it and getting the results.
77
# Because orchestrators in Durable Functions always accept the result of the previous activity for the next send() call,
8-
# we can simplify the orchestrator like this to also simplify per-test code.
8+
# we can unwrap the orchestrator generator using this method to simplify per-test code.
99
def orchestrator_generator_wrapper(generator):
1010
previous = next(generator)
1111
yield previous
@@ -45,7 +45,7 @@ def test_E2_BackupSiteContent(self, context):
4545
context.call_activity = Mock(side_effect=mock_activity)
4646
context.task_all = Mock(return_value=MockTask([100, 200, 300]))
4747

48-
# Create a generator using the method and mocked context
48+
# Execute the function code
4949
user_orchestrator = func_call(context)
5050

5151
# Use a method defined above to get the values from the generator. Quick unwrap for easy access

samples-v2/fan_in_fan_out/tests/test_HttpStart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_HttpStart(self, client):
1919
client.start_new = AsyncMock(return_value="instance_id")
2020
client.create_check_status_response = Mock(return_value="check_status_response")
2121

22-
# Create a generator using the method and mocked context
22+
# Execute the function code
2323
result = asyncio.run(func_call(req, client))
2424

2525
client.start_new.assert_called_once_with("E2_BackupSiteContent", client_input={})

samples-v2/function_chaining/tests/readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Durable Functions Sample – Unit Tests (Python)
22

3+
## Overview
4+
35
This directory contains a simple **unit test** for the sample [Durable Azure Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview) written in Python. This test demonstrates how to validate the logic of the orchestrator function in isolation using mocks.
46

7+
Writing unit tests for Durable functions requires sligtly different syntax for accessing the original method definition. Orchestrator functions, client functions, and entity functions all come with their own ways to access the user code:
8+
9+
### Orchestrator functions
10+
```
11+
my_orchestrator.build().get_user_function().orchestrator_function
12+
```
13+
14+
### Client functions
15+
```
16+
my_client_function.build().get_user_function().client_function
17+
```
18+
19+
### Entity functions
20+
```
21+
my_entity_function.build().get_user_function().entity_function
22+
```
23+
24+
This sample app demonstrates using these accessors to get and test Durable functions. It also demonstrates how to mock the calling behavior that Durable uses to run orchestrators during replay with the orchestrator_generator_wrapper method defined in test_my_orchestrator.py and simulates the Tasks yielded by DurableOrchestrationContext with MockTask objects in the same file.
25+
526
## Prerequisites
627

728
- Python

samples-v2/function_chaining/tests/test_http_start.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_HttpStart(self, client):
1919
client.start_new = AsyncMock(return_value="instance_id")
2020
client.create_check_status_response = Mock(return_value="check_status_response")
2121

22-
# Create a generator using the method and mocked context
22+
# Execute the function code
2323
result = asyncio.run(func_call(req, client))
2424

2525
client.start_new.assert_called_once_with("my_orchestrator")

samples-v2/function_chaining/tests/test_my_orchestrator.py

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

77
# A way to wrap an orchestrator generator to simplify calling it and getting the results.
88
# Because orchestrators in Durable Functions always accept the result of the previous activity for the next send() call,
9-
# we can simplify the orchestrator like this to also simplify per-test code.
9+
# we can unwrap the orchestrator generator using this method to simplify per-test code.
1010
def orchestrator_generator_wrapper(generator):
1111
previous = next(generator)
1212
yield previous
@@ -43,6 +43,7 @@ def test_chaining_orchestrator(self, context):
4343
func_call = my_orchestrator.build().get_user_function().orchestrator_function
4444

4545
context.call_activity = Mock(side_effect=mock_activity)
46+
4647
# Create a generator using the method and mocked context
4748
user_orchestrator = func_call(context)
4849

0 commit comments

Comments
 (0)