"""Test jwtauth.testing schemas""" from typing import Any import pytest from pydantic import ValidationError from jwtauth.testing.schemas import Auth0Creds, SecretLookupInfo, UserCreds @pytest.mark.parametrize( "payload, expect_exception, expected", [ pytest.param( {}, True, None, id="empty payload", ), pytest.param( { "auth0_client_secret": "secret", }, True, None, id="missing auth0_client_id", ), pytest.param( { "auth0_client_id": "1234565656", }, True, None, id="missing auth0_client_secret", ), pytest.param( { "auth0_client_id": "1234565656", "auth0_client_secret": "secret", }, False, { "auth0_client_id": "1234565656", "auth0_client_secret": "secret", }, id="valid payload", ), ], ) def test_auth0_creds( payload: dict[str, Any], expect_exception: bool, expected: dict[str, Any], ) -> None: """Test the Auth0Creds schema.""" if expect_exception: with pytest.raises(ValidationError): Auth0Creds.model_validate(payload) else: assert Auth0Creds.model_validate(payload) == Auth0Creds.model_validate(expected) @pytest.mark.parametrize( "payload, expect_exception, expected", [ pytest.param( {}, True, None, id="empty payload", ), pytest.param( { "password": "password", "otp_secret_key": "secret", }, True, None, id="Missing email", ), pytest.param( { "email": "test@sonymusic-pde.com", "otp_secret_key": "secret", }, True, None, id="Invalid email", ), pytest.param( { "email": "test@sonymusic-pde.com", "otp_secret_key": "secret", }, True, None, id="Missing password", ), pytest.param( { "email": "test@sonymusic-pde.com", "password": "password", }, False, { "email": "test@sonymusic-pde.com", "password": "password", "otp_secret_key": None, }, id="Its OK when otp_secret_key is missing", ), pytest.param( { "email": "test@sonymusic-pde.com", "password": "password", "otp_secret_key": "secret", }, False, { "email": "test@sonymusic-pde.com", "password": "password", "otp_secret_key": "secret", }, id="Valid payload", ), ], ) def test_user_creds( payload: dict[str, Any], expect_exception: bool, expected: dict[str, Any], ) -> None: """Test the Auth0Creds schema.""" if expect_exception: with pytest.raises(ValidationError): UserCreds.model_validate(payload) else: assert UserCreds.model_validate(payload) == UserCreds.model_validate(expected) @pytest.mark.parametrize( "payload, expect_exception, expected", [ pytest.param( {}, True, None, id="empty payload", ), pytest.param( { "environment": "qa", "service_name": "test-service", }, True, None, id="Missing secret_name", ), pytest.param( { "environment": "qa", "secret_name": "SPECIAL_SECRET", }, True, None, id="Missing service_name", ), pytest.param( { "service_name": "test-service", "secret_name": "SPECIAL_SECRET", }, True, None, id="Missing environment", ), pytest.param( { "environment": "uat", "service_name": "test-service", "secret_name": "SPECIAL_SECRET", }, False, { "environment": "uat", "service_name": "test-service", "secret_name": "SPECIAL_SECRET", }, id="Missing environment", ), ], ) def test_secret_lookup_info( payload: dict[str, Any], expect_exception: bool, expected: dict[str, Any], ) -> None: """Test for the SecretLookupInfo schema.""" if expect_exception: with pytest.raises(ValidationError): SecretLookupInfo.model_validate(payload) else: assert SecretLookupInfo.model_validate( payload ) == SecretLookupInfo.model_validate(expected)