forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_activity_test.py
More file actions
51 lines (42 loc) · 1.41 KB
/
hello_activity_test.py
File metadata and controls
51 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import uuid
from concurrent.futures import ThreadPoolExecutor
from temporalio import activity
from temporalio.client import Client
from temporalio.worker import Worker
from hello.hello_activity import (
ComposeGreetingInput,
GreetingWorkflow,
compose_greeting,
)
async def test_execute_workflow(client: Client):
task_queue_name = str(uuid.uuid4())
async with Worker(
client,
task_queue=task_queue_name,
workflows=[GreetingWorkflow],
activity_executor=ThreadPoolExecutor(5),
activities=[compose_greeting],
):
assert "Hello, World!" == await client.execute_workflow(
GreetingWorkflow.run,
"World",
id=str(uuid.uuid4()),
task_queue=task_queue_name,
)
@activity.defn(name="compose_greeting")
async def compose_greeting_mocked(input: ComposeGreetingInput) -> str:
return f"{input.greeting}, {input.name} from mocked activity!"
async def test_mock_activity(client: Client):
task_queue_name = str(uuid.uuid4())
async with Worker(
client,
task_queue=task_queue_name,
workflows=[GreetingWorkflow],
activities=[compose_greeting_mocked],
):
assert "Hello, World from mocked activity!" == await client.execute_workflow(
GreetingWorkflow.run,
"World",
id=str(uuid.uuid4()),
task_queue=task_queue_name,
)