Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
54 changes: 54 additions & 0 deletions tests/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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."""
Expand Down