Skip to content

Commit bf8a84d

Browse files
committed
test: add tests for _default_app_url
1 parent e51ba21 commit bf8a84d

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

workflowai/core/domain/run_test.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,14 @@ class TestRunURL:
141141
# during the execution of the decorated test function. The original value is restored
142142
# after the test completes.
143143

144+
# To check what happens in different environemnt configurations, see env_test.py
145+
144146
# Here we patch WORKFLOWAI_APP_URL to test the direct app URL case
145147
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
146148
def test_run_url(self, run1: Run[_TestOutput]):
147149
# The patched value is only active during this test method
148150
assert run1.run_url == "https://workflowai.hello/_/agents/agent-id/runs/run-id"
149151

150-
# Here we patch WORKFLOWAI_API_URL to test URL derivation from API URL
151-
@patch("workflowai.env.WORKFLOWAI_API_URL", "https://api.workflowai.dev")
152-
def test_run_url_empty_env(self, run1: Run[_TestOutput]):
153-
# When WORKFLOWAI_API_URL is set to api.workflowai.dev, the app URL should be workflowai.dev
154-
# The patch is scoped only to this test method
155-
assert run1.run_url == "https://workflowai.dev/_/agents/agent-id/runs/run-id"
156-
157-
# Multiple patches can be stacked - they are applied from bottom to top
158-
# Both patches are only active for the duration of this test method
159-
@patch("workflowai.env.WORKFLOWAI_API_URL", None)
160-
@patch("workflowai.env.WORKFLOWAI_APP_URL", None)
161-
def test_run_url_no_api_url(self, run1: Run[_TestOutput]):
162-
# When WORKFLOWAI_API_URL is not set, the app URL should default to workflowai.com
163-
assert run1.run_url == "https://workflowai.com/_/agents/agent-id/runs/run-id"
164-
165152

166153
class TestFetchCompletions:
167154
"""Tests for the fetch_completions method of the Run class."""

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)