|
| 1 | +import uuid |
| 2 | + |
| 3 | +import workflowai |
| 4 | +from examples.city_to_capital_task import CityToCapitalTask, CityToCapitalTaskInput |
| 5 | +from workflowai.core.domain.task_version_reference import TaskVersionReference |
| 6 | + |
| 7 | + |
| 8 | +async def test_deploy_task(wai: workflowai.Client): |
| 9 | + task = CityToCapitalTask( |
| 10 | + id=f"citytocapital-{uuid.uuid4()}", |
| 11 | + schema_id=0, |
| 12 | + version=TaskVersionReference.with_properties(model=""), |
| 13 | + ) |
| 14 | + |
| 15 | + await wai.register(task) |
| 16 | + |
| 17 | + assert task.schema_id == 1 |
| 18 | + |
| 19 | + # Run task with input |
| 20 | + task_run = await wai.run(task, task_input=CityToCapitalTaskInput(city="Osaka")) |
| 21 | + assert task_run.task_output.capital == "Tokyo" |
| 22 | + assert task_run.version.iteration == 1 |
| 23 | + |
| 24 | + # Deploy group to dev environnment |
| 25 | + version = await wai.deploy_version(task, iteration=1, environment="dev") |
| 26 | + assert version.iteration == 1 |
| 27 | + assert version.aliases == {"environment=dev"} |
| 28 | + |
| 29 | + # Run using the environment and the same input |
| 30 | + task_run2 = await wai.run( |
| 31 | + task, task_input=CityToCapitalTaskInput(city="Osaka"), environment="dev" |
| 32 | + ) |
| 33 | + # IDs will match since we are using cache |
| 34 | + assert task_run.id == task_run2.id |
| 35 | + |
| 36 | + # Run using the environment and a different input |
| 37 | + task_run3 = await wai.run( |
| 38 | + task, task_input=CityToCapitalTaskInput(city="Toulouse"), environment="dev" |
| 39 | + ) |
| 40 | + assert task_run3.task_output.capital == "Paris" |
| 41 | + assert task_run3.id != task_run2.id |
0 commit comments