Skip to content

Commit 2d97fb3

Browse files
committed
Fixes
1 parent 0b31e68 commit 2d97fb3

4 files changed

Lines changed: 14 additions & 19 deletions

File tree

src/devhelm/_http.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ def _resolve(value: str | None, env_key: str, label: str) -> str:
3535
return result
3636

3737

38+
def _resolve_optional(value: str | None, env_key: str, default: str) -> str:
39+
return value or os.environ.get(env_key) or default
40+
41+
3842
def build_client(config: DevhelmConfig) -> httpx.Client:
3943
"""Create a configured httpx.Client with auth and tenant headers."""
4044
base_url = config.base_url.rstrip("/")
4145
token = _resolve(config.token, "DEVHELM_API_TOKEN", "token")
42-
org_id = _resolve(config.org_id, "DEVHELM_ORG_ID", "org_id")
43-
workspace_id = _resolve(config.workspace_id, "DEVHELM_WORKSPACE_ID", "workspace_id")
46+
org_id = _resolve_optional(config.org_id, "DEVHELM_ORG_ID", "1")
47+
workspace_id = _resolve_optional(config.workspace_id, "DEVHELM_WORKSPACE_ID", "1")
4448

4549
return httpx.Client(
4650
base_url=base_url,

src/devhelm/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Devhelm:
2525
2626
from devhelm import Devhelm
2727
28-
client = Devhelm(token="your-api-token", org_id="1", workspace_id="1")
28+
client = Devhelm(token="your-api-token")
2929
3030
monitors = client.monitors.list()
3131
monitor = client.monitors.create({

tests/test_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222

2323
@pytest.fixture
24-
def client(monkeypatch: pytest.MonkeyPatch) -> Devhelm:
25-
monkeypatch.setenv("DEVHELM_ORG_ID", "1")
26-
monkeypatch.setenv("DEVHELM_WORKSPACE_ID", "1")
24+
def client() -> Devhelm:
2725
return Devhelm(token="test-token", base_url="http://localhost:8080")
2826

2927

tests/test_http.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pytest
66

7-
from devhelm._errors import DevhelmError
87
from devhelm._http import DevhelmConfig, build_client, path_param, unwrap_single
98

109

@@ -41,18 +40,14 @@ def test_encodes_special_chars(self) -> None:
4140

4241

4342
class TestBuildClient:
44-
def test_requires_org_id(self, monkeypatch: pytest.MonkeyPatch) -> None:
43+
def test_defaults_org_and_workspace(self, monkeypatch: pytest.MonkeyPatch) -> None:
4544
monkeypatch.delenv("DEVHELM_ORG_ID", raising=False)
4645
monkeypatch.delenv("DEVHELM_WORKSPACE_ID", raising=False)
4746
config = DevhelmConfig(token="test-token")
48-
with pytest.raises(DevhelmError, match="org_id is required"):
49-
build_client(config)
50-
51-
def test_requires_workspace_id(self, monkeypatch: pytest.MonkeyPatch) -> None:
52-
monkeypatch.delenv("DEVHELM_WORKSPACE_ID", raising=False)
53-
config = DevhelmConfig(token="test-token", org_id="1")
54-
with pytest.raises(DevhelmError, match="workspace_id is required"):
55-
build_client(config)
47+
client = build_client(config)
48+
assert client.headers["x-phelm-org-id"] == "1"
49+
assert client.headers["x-phelm-workspace-id"] == "1"
50+
client.close()
5651

5752
def test_reads_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
5853
monkeypatch.setenv("DEVHELM_ORG_ID", "42")
@@ -72,9 +67,7 @@ def test_config_overrides_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
7267
assert client.headers["x-phelm-workspace-id"] == "cfg-ws"
7368
client.close()
7469

75-
def test_strips_trailing_slash(self, monkeypatch: pytest.MonkeyPatch) -> None:
76-
monkeypatch.setenv("DEVHELM_ORG_ID", "1")
77-
monkeypatch.setenv("DEVHELM_WORKSPACE_ID", "1")
70+
def test_strips_trailing_slash(self) -> None:
7871
config = DevhelmConfig(token="t", base_url="https://api.example.com///")
7972
client = build_client(config)
8073
assert str(client.base_url) == "https://api.example.com"

0 commit comments

Comments
 (0)