7
7
8
8
9
9
@pytest .fixture
10
- def mock_env (monkeypatch ):
11
- "Set up environment variables for testing."
12
- monkeypatch .setenv ("ESA_TOKEN" , "test_token" )
13
- monkeypatch .setenv ("ESA_TEAM_NAME" , "test_team" )
14
-
15
-
16
- @pytest .fixture
17
- def client (mock_env ):
18
- "Return an instance of EsaClient with mocked env vars."
19
- return EsaClient ()
10
+ def client ():
11
+ "Return an instance of EsaClient with specified token and team_name."
12
+ return EsaClient (token = "test_token" , team_name = "test_team" )
20
13
21
14
22
15
def test_esa_client_initialization (client ):
@@ -27,20 +20,20 @@ def test_esa_client_initialization(client):
27
20
assert client .session .headers ["Authorization" ] == f"Bearer { client .token } "
28
21
29
22
30
- def test_esa_client_initialization_missing_token (monkeypatch ):
31
- "Test ValueError is raised if ESA_TOKEN is missing."
32
- monkeypatch .delenv ("ESA_TOKEN" , raising = False ) # Ensure it's removed if exists
33
- monkeypatch .setenv ("ESA_TEAM_NAME" , "test_team" )
23
+ def test_esa_client_initialization_missing_token ():
24
+ "Test ValueError is raised if token is missing or invalid."
34
25
with pytest .raises (ValueError , match = "ESA_TOKEN is required" ):
35
- EsaClient ()
26
+ EsaClient (token = None , team_name = "test_team" )
27
+ with pytest .raises (ValueError , match = "ESA_TOKEN is required" ):
28
+ EsaClient (token = "" , team_name = "test_team" )
36
29
37
30
38
- def test_esa_client_initialization_missing_team_name (monkeypatch ):
39
- "Test ValueError is raised if ESA_TEAM_NAME is missing."
40
- monkeypatch . setenv ( "ESA_TOKEN" , "test_token" )
41
- monkeypatch . delenv ( "ESA_TEAM_NAME " , raising = False ) # Ensure it's removed if exists
31
+ def test_esa_client_initialization_missing_team_name ():
32
+ "Test ValueError is raised if team_name is missing or invalid ."
33
+ with pytest . raises ( ValueError , match = "ESA_TEAM_NAME is required" ):
34
+ EsaClient ( token = "test_token " , team_name = None )
42
35
with pytest .raises (ValueError , match = "ESA_TEAM_NAME is required" ):
43
- EsaClient ()
36
+ EsaClient (token = "test_token" , team_name = "" )
44
37
45
38
46
39
@patch ("esa_client.requests.Session.request" )
0 commit comments