-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_env_list.py
More file actions
116 lines (90 loc) · 3.58 KB
/
test_env_list.py
File metadata and controls
116 lines (90 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from pathlib import Path
import pytest
import respx
from httpx import Response
from typer.testing import CliRunner
from fastapi_cloud_cli.cli import cloud_app as app
from fastapi_cloud_cli.config import Settings
from tests.conftest import ConfiguredApp
from tests.utils import changing_dir
runner = CliRunner()
settings = Settings.get()
assets_path = Path(__file__).parent / "assets"
def test_shows_a_message_if_not_logged_in(logged_out_cli: None) -> None:
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 1
assert "No credentials found." in result.output
def test_shows_a_message_if_app_is_not_configured(logged_in_cli: None) -> None:
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 1
assert "No app found" in result.output
@pytest.mark.respx(base_url=settings.base_api_url)
def test_shows_a_message_if_something_is_wrong(
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp
) -> None:
respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock(
return_value=Response(500)
)
with changing_dir(configured_app.path):
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 1
assert (
"Something went wrong while contacting the FastAPI Cloud server."
in result.output
)
@pytest.mark.respx(base_url=settings.base_api_url)
def test_shows_a_message_if_no_env_variables(
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp
) -> None:
respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock(
return_value=Response(200, json={"data": []})
)
with changing_dir(configured_app.path):
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 0
assert "No environment variables found." in result.output
@pytest.mark.respx(base_url=settings.base_api_url)
def test_shows_environment_variables_names(
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp
) -> None:
respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock(
return_value=Response(
200,
json={
"data": [
{"name": "SECRET_KEY", "value": "123"},
{"name": "API_KEY", "value": "456"},
]
},
)
)
with changing_dir(configured_app.path):
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 0
assert "SECRET_KEY" in result.output
assert "API_KEY" in result.output
@pytest.mark.respx(base_url=settings.base_api_url)
def test_shows_secret_environment_variables_without_value(
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp
) -> None:
"""Test that secret env vars without a value field are handled correctly."""
respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock(
return_value=Response(
200,
json={
"data": [
{
"name": "SECRET_KEY",
"is_secret": True,
"created_at": "2026-01-13T19:01:07.408378Z",
"updated_at": "2026-01-13T19:01:07.408389Z",
"connected_resource": None,
},
]
},
)
)
with changing_dir(configured_app.path):
result = runner.invoke(app, ["env", "list"])
assert result.exit_code == 0
assert "SECRET_KEY" in result.output