Skip to content

Commit 9716a23

Browse files
authored
♻️ Refactor env vars creation (#92)
1 parent 7a0ac48 commit 9716a23

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/fastapi_cloud_cli/commands/env.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ def _delete_environment_variable(app_id: str, name: str) -> bool:
4444
return True
4545

4646

47-
def _set_environment_variable(app_id: str, name: str, value: str) -> None:
47+
def _set_environment_variable(
48+
app_id: str, name: str, value: str, is_secret: bool = False
49+
) -> None:
4850
with APIClient() as client:
49-
response = client.patch(
51+
response = client.post(
5052
f"/apps/{app_id}/environment-variables/",
51-
json={name: value},
53+
json={"name": name, "value": value, "is_secret": is_secret},
5254
)
5355
response.raise_for_status()
5456

tests/test_env_set.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def test_shows_a_message_if_app_is_not_configured(logged_in_cli: None) -> None:
4747
def test_shows_a_message_if_something_is_wrong(
4848
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: Path
4949
) -> None:
50-
respx_mock.patch("/apps/123/environment-variables/").mock(
51-
return_value=Response(500)
52-
)
50+
respx_mock.post("/apps/123/environment-variables/").mock(return_value=Response(500))
5351

5452
with changing_dir(configured_app):
5553
result = runner.invoke(app, ["env", "set", "SOME_VAR", "secret"])
@@ -65,9 +63,7 @@ def test_shows_a_message_if_something_is_wrong(
6563
def test_shows_message_when_it_sets(
6664
logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: Path
6765
) -> None:
68-
respx_mock.patch("/apps/123/environment-variables/").mock(
69-
return_value=Response(200)
70-
)
66+
respx_mock.post("/apps/123/environment-variables/").mock(return_value=Response(200))
7167

7268
with changing_dir(configured_app):
7369
result = runner.invoke(app, ["env", "set", "SOME_VAR", "secret"])
@@ -82,9 +78,7 @@ def test_asks_for_name_and_value(
8278
) -> None:
8379
steps = [*"SOME_VAR", Keys.ENTER, *"secret", Keys.ENTER]
8480

85-
respx_mock.patch("/apps/123/environment-variables/").mock(
86-
return_value=Response(200)
87-
)
81+
respx_mock.post("/apps/123/environment-variables/").mock(return_value=Response(200))
8882

8983
with changing_dir(configured_app), patch(
9084
"rich_toolkit.container.getchar", side_effect=steps

0 commit comments

Comments
 (0)