|
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | import zitadel_client as zitadel |
7 | | -from zitadel_client.auth.client_credentials_authenticator import ClientCredentialsAuthenticator |
| 7 | +from zitadel_client.auth.client_credentials_authenticator import ( |
| 8 | + ClientCredentialsAuthenticator, |
| 9 | +) |
8 | 10 |
|
9 | 11 |
|
10 | 12 | @pytest.fixture |
@@ -33,42 +35,35 @@ def user_id(client_id: str, client_secret: str, base_url: str) -> str | None: |
33 | 35 | response = client.users.add_human_user( |
34 | 36 | body=zitadel.models.V2AddHumanUserRequest( |
35 | 37 | username=uuid.uuid4().hex, |
36 | | - profile=zitadel.models.V2SetHumanProfile(given_name="John", family_name="Doe"), # type: ignore[call-arg] |
37 | | - email=zitadel.models.V2SetHumanEmail(email=f"johndoe{uuid.uuid4().hex}@caos.ag") |
| 38 | + profile=zitadel.models.V2SetHumanProfile(given_name="John", family_name="Doe"), # type: ignore[call-arg] |
| 39 | + email=zitadel.models.V2SetHumanEmail(email=f"johndoe{uuid.uuid4().hex}@caos.ag"), |
38 | 40 | ) |
39 | 41 | ) |
40 | | - print("User created:", response) |
41 | 42 | return response.user_id |
42 | 43 | except Exception as e: |
43 | 44 | pytest.fail(f"Exception while creating user: {e}") |
44 | 45 |
|
45 | 46 |
|
46 | | -def test_should_deactivate_and_reactivate_user_with_valid_token(user_id: str, client_id: str, client_secret: str, base_url: str) -> None: |
| 47 | +def test_should_deactivate_and_reactivate_user_with_valid_token( |
| 48 | + user_id: str, client_id: str, client_secret: str, base_url: str |
| 49 | +) -> None: |
47 | 50 | """Test to (de)activate the user with a valid token.""" |
48 | 51 | with zitadel.Zitadel(ClientCredentialsAuthenticator.builder(base_url, client_id, client_secret).build()) as client: |
49 | 52 | try: |
50 | 53 | deactivate_response = client.users.deactivate_user(user_id=user_id) |
51 | | - print("User deactivated:", deactivate_response) |
| 54 | + assert deactivate_response is not None, "Deactivation response is None" |
52 | 55 |
|
53 | 56 | reactivate_response = client.users.reactivate_user(user_id=user_id) |
54 | | - print("User reactivated:", reactivate_response) |
55 | | - # Adjust based on actual response format |
56 | | - # assert reactivate_response["status"] == "success" |
| 57 | + assert reactivate_response is not None, "Reactivation response is None" |
57 | 58 | except Exception as e: |
58 | 59 | pytest.fail(f"Exception when calling deactivate_user or reactivate_user with valid token: {e}") |
59 | 60 |
|
60 | 61 |
|
61 | 62 | def test_should_not_deactivate_or_reactivate_user_with_invalid_token(user_id: str, base_url: str) -> None: |
62 | 63 | """Test to attempt (de)activating the user with an invalid token.""" |
63 | 64 | with zitadel.Zitadel(ClientCredentialsAuthenticator.builder(base_url, "id", "secret").build()) as client: |
64 | | - try: |
| 65 | + with pytest.raises(Exception, match="Failed to refresh token: invalid_client: client not found"): |
65 | 66 | client.users.deactivate_user(user_id=user_id) |
66 | | - pytest.fail("Expected exception when deactivating user with invalid token, but got response.") |
67 | | - except Exception as e: |
68 | | - print("Caught expected UnauthorizedException:", e) |
69 | 67 |
|
70 | | - try: |
| 68 | + with pytest.raises(Exception, match="Failed to refresh token: invalid_client: client not found"): |
71 | 69 | client.users.reactivate_user(user_id=user_id) |
72 | | - pytest.fail("Expected exception when reactivating user with invalid token, but got response.") |
73 | | - except Exception as e: |
74 | | - print("Caught expected UnauthorizedException:", e) |
0 commit comments