Skip to content

Commit 18f29c5

Browse files
committed
Encapsulated all the specificiation tests into classes
1 parent d68615b commit 18f29c5

5 files changed

Lines changed: 126 additions & 116 deletions
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
SettingsService Integration Tests (Personal Access Token)
3-
4-
This suite verifies the Zitadel SettingsService API's general settings
5-
endpoint works when authenticating via a Personal Access Token:
6-
7-
1. Retrieve general settings successfully with a valid token
8-
2. Expect an ApiException when using an invalid token
9-
10-
Each test instantiates a new client to ensure a clean, stateless call.
11-
"""
12-
131
import os
142

153
import pytest
@@ -36,20 +24,39 @@ def auth_token() -> str:
3624
return url
3725

3826

39-
def test_retrieves_general_settings_with_valid_token(base_url: str, auth_token: str) -> None:
40-
"""Retrieves general settings successfully with a valid access token."""
41-
client = zitadel.Zitadel.with_access_token(
42-
base_url,
43-
auth_token,
44-
)
45-
client.settings.settings_service_get_general_settings()
27+
class TestUseAccessTokenSpec:
28+
"""
29+
SettingsService Integration Tests (Personal Access Token)
4630
31+
This suite verifies the Zitadel SettingsService API's general settings
32+
endpoint works when authenticating via a Personal Access Token:
4733
48-
def test_raises_api_exception_with_invalid_token(base_url: str) -> None:
49-
"""Raises ApiException when using an invalid access token."""
50-
client = zitadel.Zitadel.with_access_token(
51-
base_url,
52-
"invalid",
53-
)
54-
with pytest.raises(OpenApiError):
34+
1. Retrieve general settings successfully with a valid token
35+
2. Expect an ApiException when using an invalid token
36+
37+
Each test instantiates a new client to ensure a clean, stateless call.
38+
"""
39+
40+
def test_retrieves_general_settings_with_valid_token(
41+
self,
42+
base_url: str,
43+
auth_token: str,
44+
) -> None:
45+
"""Retrieves general settings successfully with a valid access token."""
46+
client = zitadel.Zitadel.with_access_token(
47+
base_url,
48+
auth_token,
49+
)
5550
client.settings.settings_service_get_general_settings()
51+
52+
def test_raises_api_exception_with_invalid_token(
53+
self,
54+
base_url: str,
55+
) -> None:
56+
"""Raises ApiException when using an invalid access token."""
57+
client = zitadel.Zitadel.with_access_token(
58+
base_url,
59+
"invalid",
60+
)
61+
with pytest.raises(OpenApiError):
62+
client.settings.settings_service_get_general_settings()
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
SettingsService Integration Tests (Client Credentials)
3-
4-
This suite verifies the Zitadel SettingsService API's general settings
5-
endpoint works when authenticating via Client Credentials:
6-
7-
1. Retrieve general settings successfully with valid credentials
8-
2. Expect an ApiException when using invalid credentials
9-
10-
Each test instantiates a new client to ensure a clean, stateless call.
11-
"""
12-
131
import os
142

153
import pytest
@@ -45,22 +33,42 @@ def client_secret() -> str:
4533
return cs
4634

4735

48-
def test_retrieves_general_settings_with_valid_client_credentials(base_url: str, client_id: str, client_secret: str) -> None:
49-
"""Retrieves general settings successfully with valid client credentials."""
50-
client = zitadel.Zitadel.with_client_credentials(
51-
base_url,
52-
client_id,
53-
client_secret,
54-
)
55-
client.settings.settings_service_get_general_settings()
36+
class TestUseClientCredentialsSpec:
37+
"""
38+
SettingsService Integration Tests (Client Credentials)
5639
40+
This suite verifies the Zitadel SettingsService API's general settings
41+
endpoint works when authenticating via Client Credentials:
5742
58-
def test_raises_api_exception_with_invalid_client_credentials(base_url: str) -> None:
59-
"""Raises ApiException when using invalid client credentials."""
60-
client = zitadel.Zitadel.with_client_credentials(
61-
base_url,
62-
"invalid",
63-
"invalid",
64-
)
65-
with pytest.raises(OpenApiError):
43+
1. Retrieve general settings successfully with valid credentials
44+
2. Expect an ApiException when using invalid credentials
45+
46+
Each test instantiates a new client to ensure a clean, stateless call.
47+
"""
48+
49+
def test_retrieves_general_settings_with_valid_client_credentials(
50+
self,
51+
base_url: str,
52+
client_id: str,
53+
client_secret: str,
54+
) -> None:
55+
"""Retrieves general settings successfully with valid client credentials."""
56+
client = zitadel.Zitadel.with_client_credentials(
57+
base_url,
58+
client_id,
59+
client_secret,
60+
)
6661
client.settings.settings_service_get_general_settings()
62+
63+
def test_raises_api_exception_with_invalid_client_credentials(
64+
self,
65+
base_url: str,
66+
) -> None:
67+
"""Raises ApiException when using invalid client credentials."""
68+
client = zitadel.Zitadel.with_client_credentials(
69+
base_url,
70+
"invalid",
71+
"invalid",
72+
)
73+
with pytest.raises(OpenApiError):
74+
client.settings.settings_service_get_general_settings()
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
"""
2-
SettingsService Integration Tests (Private Key Assertion)
3-
4-
This suite verifies the Zitadel SettingsService API's general settings
5-
endpoint works when authenticating via a private key assertion:
6-
7-
1. Retrieve general settings successfully with a valid private key
8-
2. Expect an ApiException when using an invalid private key path
9-
10-
Each test instantiates a new client to ensure a clean, stateless call.
11-
"""
12-
131
import os
142
import pathlib
153

@@ -36,20 +24,39 @@ def key_file(tmp_path: pathlib.Path) -> str:
3624
return str(file_path)
3725

3826

39-
def test_retrieves_general_settings_with_valid_private_key(base_url: str, key_file: str) -> None:
40-
"""Retrieves general settings successfully with a valid private key."""
41-
client = zitadel.Zitadel.with_private_key(
42-
base_url,
43-
key_file,
44-
)
45-
client.settings.settings_service_get_general_settings()
27+
class TestUsePrivateKeySpec:
28+
"""
29+
SettingsService Integration Tests (Private Key Assertion)
4630
31+
This suite verifies the Zitadel SettingsService API's general settings
32+
endpoint works when authenticating via a private key assertion:
4733
48-
def test_raises_api_exception_with_invalid_private_key(key_file: str) -> None:
49-
"""Raises ApiException when using an invalid private key path."""
50-
client = zitadel.Zitadel.with_private_key(
51-
"https://zitadel.cloud",
52-
key_file,
53-
)
54-
with pytest.raises(OpenApiError):
34+
1. Retrieve general settings successfully with a valid private key
35+
2. Expect an ApiException when using an invalid private key path
36+
37+
Each test instantiates a new client to ensure a clean, stateless call.
38+
"""
39+
40+
def test_retrieves_general_settings_with_valid_private_key(
41+
self,
42+
base_url: str,
43+
key_file: str,
44+
) -> None:
45+
"""Retrieves general settings successfully with a valid private key."""
46+
client = zitadel.Zitadel.with_private_key(
47+
base_url,
48+
key_file,
49+
)
5550
client.settings.settings_service_get_general_settings()
51+
52+
def test_raises_api_exception_with_invalid_private_key(
53+
self,
54+
key_file: str,
55+
) -> None:
56+
"""Raises ApiException when using an invalid private key path."""
57+
client = zitadel.Zitadel.with_private_key(
58+
"https://zitadel.cloud",
59+
key_file,
60+
)
61+
with pytest.raises(OpenApiError):
62+
client.settings.settings_service_get_general_settings()

spec/check_session_service_spec.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
"""
2-
SessionService Integration Tests
3-
4-
This suite verifies the Zitadel SessionService API's basic operations using a
5-
personal access token:
6-
7-
1. Create a session with specified checks and lifetime
8-
2. Retrieve the session by ID
9-
3. List sessions and ensure the created session appears
10-
4. Update the session's lifetime and confirm a new token is returned
11-
5. Error when retrieving a non-existent session
12-
13-
Each test runs in isolation: a new session is created in the `session` fixture and
14-
deleted after the test to ensure a clean state.
15-
"""
16-
171
import os
182
import uuid
193
from typing import Generator
@@ -82,9 +66,19 @@ def session(client: zitadel.Zitadel) -> Generator[SessionServiceCreateSessionRes
8266

8367
class TestSessionServiceSanityCheckSpec:
8468
"""
85-
Integration tests for the SessionService endpoints.
69+
SessionService Integration Tests
70+
71+
This suite verifies the Zitadel SessionService API's basic operations using a
72+
personal access token:
73+
74+
1. Create a session with specified checks and lifetime
75+
2. Retrieve the session by ID
76+
3. List sessions and ensure the created session appears
77+
4. Update the session's lifetime and confirm a new token is returned
78+
5. Error when retrieving a non-existent session
8679
87-
Verifies create, get, list, set, and error behaviors for sessions.
80+
Each test runs in isolation: a new session is created in the `session` fixture and
81+
deleted after the test to ensure a clean state.
8882
"""
8983

9084
def test_retrieves_session_details_by_id(

spec/check_user_service_spec.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
"""
2-
UserService Integration Tests
3-
4-
This suite verifies the Zitadel UserService API's basic operations using a
5-
personal access token:
6-
7-
1. Create a human user
8-
2. Retrieve the user by ID
9-
3. List users and ensure the created user appears
10-
4. Update the user's email and confirm the change
11-
5. Error when retrieving a non-existent user
12-
13-
Each test runs in isolation: a new user is created in the `user` fixture and
14-
removed after the test to ensure a clean state.
15-
"""
16-
171
import os
182
import uuid
193
from typing import Generator
@@ -75,9 +59,19 @@ def user(client: zitadel.Zitadel) -> Generator[UserServiceAddHumanUserResponse,
7559

7660
class TestUserServiceSanityCheckSpec:
7761
"""
78-
Integration tests for the UserService endpoints.
62+
UserService Integration Tests
63+
64+
This suite verifies the Zitadel UserService API's basic operations using a
65+
personal access token:
66+
67+
1. Create a human user
68+
2. Retrieve the user by ID
69+
3. List users and ensure the created user appears
70+
4. Update the user's email and confirm the change
71+
5. Error when retrieving a non-existent user
7972
80-
Verifies create, get, list, set, and error behaviors for users.
73+
Each test runs in isolation: a new user is created in the `user` fixture and
74+
removed after the test to ensure a clean state.
8175
"""
8276

8377
def test_retrieves_user_details_by_id(

0 commit comments

Comments
 (0)