|
| 1 | +import importlib |
| 2 | +import os |
1 | 3 | from typing import Optional |
2 | 4 | from unittest.mock import patch |
3 | 5 |
|
4 | 6 | import pytest |
5 | 7 |
|
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" |
7 | 38 |
|
8 | 39 |
|
9 | 40 | @pytest.mark.parametrize( |
|
16 | 47 | ], |
17 | 48 | ) |
18 | 49 | def test_default_app_url(api_url: Optional[str], expected: str): |
| 50 | + # Importing here to avoid setting the environment variables before the test |
19 | 51 | 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