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
4 changes: 2 additions & 2 deletions src/atlas/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
"""
if api_key is None:
api_key = os.environ.get("LAYERLENS_ATLAS_API_KEY")
if api_key is None:
if api_key is None or api_key == "":
raise AtlasError(
"The api_key client option must be set either by passing api_key to the client or by setting the LAYERLENS_ATLAS_API_KEY environment variable"
)
Expand Down Expand Up @@ -190,7 +190,7 @@ def __init__(
"""
if api_key is None:
api_key = os.environ.get("LAYERLENS_ATLAS_API_KEY")
if api_key is None:
if api_key is None or api_key == "":
raise AtlasError(
"The api_key client option must be set either by passing api_key to the client "
"or by setting the LAYERLENS_ATLAS_API_KEY environment variable"
Expand Down
21 changes: 11 additions & 10 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from atlas import Atlas
from atlas._exceptions import AtlasError


class TestAtlasClientInitialization:
Expand Down Expand Up @@ -52,20 +53,20 @@ def test_auth_headers_with_api_key(self, mock_org):
def test_auth_headers_without_api_key(self, mock_org):
"""auth_headers property returns empty dict when no API key."""
with patch("atlas.Atlas._get_organization", return_value=mock_org):
client = Atlas(api_key="")

headers = client.auth_headers

assert headers == {}
with pytest.raises(
AtlasError,
match="The api_key client option must be set either by passing api_key to the client or by setting the LAYERLENS_ATLAS_API_KEY environment variable",
):
Atlas(api_key="")

def test_auth_headers_with_empty_api_key(self, mock_org):
"""auth_headers property returns empty dict when API key is empty string."""
with patch("atlas.Atlas._get_organization", return_value=mock_org):
client = Atlas(api_key="")

headers = client.auth_headers

assert headers == {}
with pytest.raises(
AtlasError,
match="The api_key client option must be set either by passing api_key to the client or by setting the LAYERLENS_ATLAS_API_KEY environment variable",
):
Atlas(api_key="")

def test_copy_method(self, mock_org):
"""copy method creates new client with overridden parameters."""
Expand Down
Loading