"""Coverage tests for database/session_context.py — basic import-level checks.

Covered here:
- DatabaseSessionError is a proper Exception subclass
- with_user_database: decorator injects db_session
- DatabaseAccessMixin.get_db_session: raises DeprecationWarning

Additional branch coverage lives in test_session_context_deep_coverage.py.
"""

from unittest.mock import MagicMock, patch

import pytest

from local_deep_research.database.session_context import (
    DatabaseAccessMixin,
    DatabaseSessionError,
    with_user_database,
)

MODULE = "local_deep_research.database.session_context"


class TestGetUserDbSessionErrors:
    """Tests for error paths in get_user_db_session."""

    def test_database_session_error_is_exception(self):
        """DatabaseSessionError is a proper Exception subclass."""
        assert issubclass(DatabaseSessionError, Exception)
        err = DatabaseSessionError("test message")
        assert str(err) == "test message"


class TestWithUserDatabase:
    """Tests for with_user_database decorator."""

    def test_injects_db_session(self):
        """Decorator injects db_session as first argument."""

        @with_user_database
        def my_func(db_session, key):
            return f"session={db_session}, key={key}"

        mock_session = MagicMock()
        with patch(f"{MODULE}.get_user_db_session") as mock_ctx:
            mock_ctx.return_value.__enter__ = MagicMock(
                return_value=mock_session
            )
            mock_ctx.return_value.__exit__ = MagicMock(return_value=False)
            result = my_func("test_key")

        assert "test_key" in result


class TestDatabaseAccessMixin:
    """Tests for DatabaseAccessMixin."""

    def test_get_db_session_raises_deprecation(self):
        """get_db_session raises DeprecationWarning."""

        class MyService(DatabaseAccessMixin):
            pass

        svc = MyService()
        with pytest.raises(DeprecationWarning):
            svc.get_db_session()
