From ecdfcd69b7a7894d5ed847549c0f045d41bdcb67 Mon Sep 17 00:00:00 2001 From: Patrick Rachford <64233065+rachfop@users.noreply.github.com> Date: Mon, 27 Nov 2023 08:41:24 -0800 Subject: [PATCH] Use temporalio.testing.ActivityEnvironment (#96) --- tests/hello/hello_activity_choice_test.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/hello/hello_activity_choice_test.py diff --git a/tests/hello/hello_activity_choice_test.py b/tests/hello/hello_activity_choice_test.py new file mode 100644 index 00000000..236634de --- /dev/null +++ b/tests/hello/hello_activity_choice_test.py @@ -0,0 +1,32 @@ +import pytest +from temporalio.testing import ActivityEnvironment + +from hello.hello_activity_choice import ( + order_apples, + order_bananas, + order_cherries, + order_oranges, +) + +# A list of tuples where each tuple contains: +# - The activity function +# - The order amount +# - The expected result string +activity_test_data = [ + (order_apples, 5, "Ordered 5 Apples..."), + (order_bananas, 5, "Ordered 5 Bananas..."), + (order_cherries, 5, "Ordered 5 Cherries..."), + (order_oranges, 5, "Ordered 5 Oranges..."), +] + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "activity_func, order_amount, expected_result", activity_test_data +) +async def test_order_fruit(activity_func, order_amount, expected_result): + activity_environment = ActivityEnvironment() + + result = await activity_environment.run(activity_func, order_amount) + + assert result == expected_result