-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_run_worker.py
54 lines (44 loc) · 1.53 KB
/
test_run_worker.py
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
52
53
54
# @@@SNIPSTART hello-world-project-template-python-tests
import uuid
import pytest
from temporalio import activity
from temporalio.worker import Worker
from temporalio.testing import WorkflowEnvironment
from activities import say_hello
from workflows import SayHello
@pytest.mark.asyncio
async def test_execute_workflow():
task_queue_name = str(uuid.uuid4())
async with await WorkflowEnvironment.start_time_skipping() as env:
async with Worker(
env.client,
task_queue=task_queue_name,
workflows=[SayHello],
activities=[say_hello],
):
assert "Hello, World!" == await env.client.execute_workflow(
SayHello.run,
"World",
id=str(uuid.uuid4()),
task_queue=task_queue_name,
)
@activity.defn(name="say_hello")
async def say_hello_mocked(name: str) -> str:
return f"Hello, {name} from mocked activity!"
@pytest.mark.asyncio
async def test_mock_activity():
task_queue_name = str(uuid.uuid4())
async with await WorkflowEnvironment.start_time_skipping() as env:
async with Worker(
env.client,
task_queue=task_queue_name,
workflows=[SayHello],
activities=[say_hello_mocked],
):
assert "Hello, World from mocked activity!" == await env.client.execute_workflow(
SayHello.run,
"World",
id=str(uuid.uuid4()),
task_queue=task_queue_name,
)
# @@@SNIPEND