File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from dataclasses import dataclass
22import os
33
4+ from .exceptions import HyperbrowserError
5+
46
57@dataclass
68class ClientConfig :
@@ -13,7 +15,9 @@ class ClientConfig:
1315 def from_env (cls ) -> "ClientConfig" :
1416 api_key = os .environ .get ("HYPERBROWSER_API_KEY" )
1517 if api_key is None :
16- raise ValueError ("HYPERBROWSER_API_KEY environment variable is required" )
18+ raise HyperbrowserError (
19+ "HYPERBROWSER_API_KEY environment variable is required"
20+ )
1721
1822 base_url = os .environ .get (
1923 "HYPERBROWSER_BASE_URL" , "https://api.hyperbrowser.ai"
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+ from hyperbrowser .config import ClientConfig
4+ from hyperbrowser .exceptions import HyperbrowserError
5+
6+
7+ def test_client_config_from_env_raises_hyperbrowser_error_without_api_key (monkeypatch ):
8+ monkeypatch .delenv ("HYPERBROWSER_API_KEY" , raising = False )
9+
10+ with pytest .raises (HyperbrowserError , match = "HYPERBROWSER_API_KEY" ):
11+ ClientConfig .from_env ()
12+
13+
14+ def test_client_config_from_env_reads_api_key_and_base_url (monkeypatch ):
15+ monkeypatch .setenv ("HYPERBROWSER_API_KEY" , "test-key" )
16+ monkeypatch .setenv ("HYPERBROWSER_BASE_URL" , "https://example.local" )
17+
18+ config = ClientConfig .from_env ()
19+
20+ assert config .api_key == "test-key"
21+ assert config .base_url == "https://example.local"
You can’t perform that action at this time.
0 commit comments