Skip to content

Commit 64db518

Browse files
authored
Merge pull request #67 from WorkflowAI/pierre/run-url
test: enhance TestRunURL with additional test cases for URL generation
2 parents 5bb4446 + bf8a84d commit 64db518

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

workflowai/core/domain/run_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ def test_format_output_no_cost_latency():
137137

138138

139139
class TestRunURL:
140+
# The @patch decorator from unittest.mock temporarily replaces the value of an attribute
141+
# during the execution of the decorated test function. The original value is restored
142+
# after the test completes.
143+
144+
# To check what happens in different environemnt configurations, see env_test.py
145+
146+
# Here we patch WORKFLOWAI_APP_URL to test the direct app URL case
140147
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
141148
def test_run_url(self, run1: Run[_TestOutput]):
149+
# The patched value is only active during this test method
142150
assert run1.run_url == "https://workflowai.hello/_/agents/agent-id/runs/run-id"
143151

144152

workflowai/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
WORKFLOWAI_DEFAULT_MODEL = os.getenv("WORKFLOWAI_DEFAULT_MODEL", "gemini-1.5-pro-latest")
66

7-
WORKFLOWAI_API_URL = os.getenv("WORKFLOWAI_API_URL")
7+
WORKFLOWAI_API_URL = os.getenv("WORKFLOWAI_API_URL", "https://run.workflowai.com")
88

99

1010
def _default_app_url():

workflowai/env_test.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1+
import importlib
2+
import os
13
from typing import Optional
24
from unittest.mock import patch
35

46
import pytest
57

6-
from .env import _default_app_url # pyright: ignore[reportPrivateUsage]
8+
from workflowai import env
9+
10+
11+
# Check what happens when the environment is fully empty
12+
@patch.dict(os.environ, clear=True)
13+
def test_default_app_url_clear_env():
14+
# We need to reload the env module so that the environment variables are read again
15+
importlib.reload(env)
16+
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.com"
17+
assert env.WORKFLOWAI_APP_URL == "https://workflowai.com"
18+
19+
20+
# Check with the default app url when an api url is provided
21+
@patch.dict(os.environ, {"WORKFLOWAI_API_URL": "https://run.workflowai.dev"}, clear=True)
22+
def test_default_app_url_dev_url():
23+
importlib.reload(env)
24+
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.dev"
25+
assert env.WORKFLOWAI_APP_URL == "https://workflowai.dev"
26+
27+
28+
# Check the app url when both api url and app url are provided
29+
@patch.dict(
30+
os.environ,
31+
{"WORKFLOWAI_API_URL": "https://run.workflowai.dev", "WORKFLOWAI_APP_URL": "https://workflowai.app"},
32+
clear=True,
33+
)
34+
def test_with_app_url():
35+
importlib.reload(env)
36+
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.dev"
37+
assert env.WORKFLOWAI_APP_URL == "https://workflowai.app"
738

839

940
@pytest.mark.parametrize(
@@ -16,5 +47,6 @@
1647
],
1748
)
1849
def test_default_app_url(api_url: Optional[str], expected: str):
50+
# Importing here to avoid setting the environment variables before the test
1951
with patch("workflowai.env.WORKFLOWAI_API_URL", api_url):
20-
assert _default_app_url() == expected
52+
assert env._default_app_url() == expected # pyright: ignore[reportPrivateUsage]

0 commit comments

Comments
 (0)