Skip to content

Commit

Permalink
add pydantic Temporal test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Jan 14, 2025
1 parent 9433680 commit d36066f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/workflows/test_temporal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import asyncio
from datetime import timedelta
from typing import List

import pytest
from pydantic import BaseModel
from temporalio import activity, workflow
from temporalio.client import Client

from temporalio.worker import Worker, UnsandboxedWorkflowRunner


Expand Down Expand Up @@ -59,3 +59,34 @@ async def test_simple_workflow(temporal_client: Client) -> None:
)
expected_results = ['Hello, user1!', 'Hello, user2!', 'Hello, user3!', 'Hello, user4!', 'Hello, user5!']
assert result == expected_results



class User(BaseModel):
name: str
age: int


@activity.defn
async def get_hello_pydantic_user_data() -> User:
return User(name="John Doe", age=30)


@workflow.defn
class HelloPydanticWorkflow:
@workflow.run
async def run(self) -> User:
return await workflow.execute_activity(get_hello_pydantic_user_data, args=[],
start_to_close_timeout=timedelta(seconds=5))


@pytest.mark.asyncio
async def test_pydantic_workflow(temporal_client: Client) -> None:
# Run a worker for the workflow
async with Worker(temporal_client, task_queue="hello-parallel-activity-task-queue",
workflows=[HelloPydanticWorkflow], activities=[get_hello_pydantic_user_data],
workflow_runner=UnsandboxedWorkflowRunner()):
result = await temporal_client.execute_workflow(HelloPydanticWorkflow.run, args=[],
id="hello-pydantic-workflow-id", task_queue="hello-parallel-activity-task-queue", )
expected_results = User(name="John Doe", age=30)
assert result == expected_results

0 comments on commit d36066f

Please sign in to comment.