Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions tests/unit_tests/helpers/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandasai.helpers.session import Session, get_pandaai_session


@patch("pandasai.os.environ", {})
def test_session_init_without_api_key():
"""Test that Session initialization raises PandaAIApiKeyError when no API key is provided"""
with pytest.raises(PandaAIApiKeyError) as exc_info:
Expand All @@ -18,6 +19,7 @@ def test_session_init_without_api_key():
)


@patch("pandasai.os.environ", {})
def test_session_init_with_none_api_key():
"""Test that Session initialization raises PandaAIApiKeyError when API key is None"""
with pytest.raises(PandaAIApiKeyError) as exc_info:
Expand All @@ -28,18 +30,21 @@ def test_session_init_with_none_api_key():
)


@patch("pandasai.os.environ", {})
def test_session_init_with_api_key():
"""Test that Session initialization works with a valid API key"""
session = Session(api_key="test-key")
assert session._api_key == "test-key"


@patch("pandasai.os.environ", {})
def test_session_init_with_default_api_url():
"""Test that Session initialization uses DEFAULT_API_URL when no URL is provided"""
session = Session(api_key="test-key")
assert session._endpoint_url == DEFAULT_API_URL


@patch("pandasai.os.environ", {})
def test_session_init_with_custom_api_url():
"""Test that Session initialization uses provided URL"""
custom_url = "https://custom.api.url"
Expand All @@ -64,6 +69,7 @@ def test_session_init_with_env_api_url():
assert session._endpoint_url == "https://env.api.url"


@patch("pandasai.os.environ", {})
def test_get_pandaai_session_without_credentials():
"""Test that get_pandaai_session raises PandaAIApiKeyError when no credentials are provided"""
with pytest.raises(PandaAIApiKeyError) as exc_info:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit_tests/test_pandasai_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ def test_load_successful_zip_extraction(
mock_zip_file.return_value.__enter__.return_value.extractall.assert_called_once()
assert isinstance(result, MagicMock)

def test_load_without_api_credentials(self):
@patch("pandasai.os.environ", {})
def test_load_without_api_credentials(
self,
):
"""Test that load raises PandaAIApiKeyError when no API credentials are provided"""
with pytest.raises(PandaAIApiKeyError) as exc_info:
pandasai.load("test/dataset")
Expand Down