diff --git a/tests/test_logging.py b/tests/test_logging.py index 3b8fde3..f9f91d6 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -11,6 +11,8 @@ from unittest.mock import Mock from unittest.mock import patch +import pytest + from ipsdk import heuristics from ipsdk import logging as ipsdk_logging from ipsdk import metadata @@ -400,6 +402,15 @@ def test_set_level_with_none_string(self): mock_logger.setLevel.assert_called_once_with(ipsdk_logging.NONE) + def test_set_level_with_invalid_string_raises_type_error(self): + """Test set_level with invalid string raises TypeError.""" + with patch("ipsdk.logging.get_logger") as mock_get_logger: + mock_logger = Mock() + mock_get_logger.return_value = mock_logger + + with pytest.raises(TypeError, match="Invalid level string: INVALID"): + ipsdk_logging.set_level("INVALID") + class TestSensitiveDataFiltering: """Test sensitive data filtering functions.""" diff --git a/tests/test_platform.py b/tests/test_platform.py index 2da3837..ef0f5ab 100644 --- a/tests/test_platform.py +++ b/tests/test_platform.py @@ -549,6 +549,32 @@ def test_authenticate_user_request_error(): mixin.authenticate_basicauth() +def test_authenticate_basicauth_missing_credentials(): + """Test authenticate_basicauth raises IpsdkError when user or password is None.""" + mixin = AuthMixin() + mixin.user = None + mixin.password = None + mixin.client = Mock() + + with pytest.raises(exceptions.IpsdkError) as exc_info: + mixin.authenticate_basicauth() + + assert "Username and password are required" in str(exc_info.value) + + +def test_authenticate_oauth_missing_credentials(): + """Test authenticate_oauth raises IpsdkError with missing credentials.""" + mixin = AuthMixin() + mixin.client_id = None + mixin.client_secret = None + mixin.client = Mock() + + with pytest.raises(exceptions.IpsdkError) as exc_info: + mixin.authenticate_oauth() + + assert "Client ID and client secret are required" in str(exc_info.value) + + def test_authenticate_no_credentials_error(): """Test authenticate raises IpsdkError when no credentials provided.""" mixin = AuthMixin() @@ -755,6 +781,34 @@ async def test_async_authenticate_basicauth_request_error(): await mixin.authenticate_basicauth() +@pytest.mark.asyncio +async def test_async_authenticate_basicauth_missing_credentials(): + """Test async authenticate_basicauth raises IpsdkError with missing creds.""" + mixin = AsyncAuthMixin() + mixin.user = None + mixin.password = None + mixin.client = AsyncMock() + + with pytest.raises(exceptions.IpsdkError) as exc_info: + await mixin.authenticate_basicauth() + + assert "Username and password are required" in str(exc_info.value) + + +@pytest.mark.asyncio +async def test_async_authenticate_oauth_missing_credentials(): + """Test async authenticate_oauth raises IpsdkError with missing credentials.""" + mixin = AsyncAuthMixin() + mixin.client_id = None + mixin.client_secret = None + mixin.client = AsyncMock() + + with pytest.raises(exceptions.IpsdkError) as exc_info: + await mixin.authenticate_oauth() + + assert "Client ID and client secret are required" in str(exc_info.value) + + @pytest.mark.asyncio async def test_async_authenticate_no_credentials_error(): """Test async authenticate raises IpsdkError when no credentials provided."""