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
3 changes: 1 addition & 2 deletions src/delega/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Delega Python SDK - Official client for the Delega API."""

from ._version import __version__
from .client import Delega
from .exceptions import (
DelegaAPIError,
Expand All @@ -11,8 +12,6 @@
from .models import Agent, Comment, Project, Task
from .webhooks import verify_webhook

__version__ = "0.1.2"

__all__ = [
"Agent",
"AsyncDelega",
Expand Down
2 changes: 2 additions & 0 deletions src/delega/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import urllib.request
from typing import Any, Optional

from ._version import USER_AGENT
from .exceptions import (
DelegaAPIError,
DelegaAuthError,
Expand Down Expand Up @@ -64,6 +65,7 @@ def _headers(self) -> dict[str, str]:
"X-Agent-Key": self._api_key,
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
}

def request(
Expand Down
4 changes: 4 additions & 0 deletions src/delega/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Package version metadata."""

__version__ = "0.1.2"
USER_AGENT = f"delega-python/{__version__}"
2 changes: 2 additions & 0 deletions src/delega/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DelegaRateLimitError,
)
from .models import Agent, Comment, Project, Task
from ._version import USER_AGENT

_DEFAULT_BASE_URL = "https://api.delega.dev"

Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(self, base_url: str, api_key: str, timeout: int = 30) -> None:
"X-Agent-Key": api_key,
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
},
timeout=timeout,
)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Project,
Task,
)
from delega._version import USER_AGENT


def _mock_response(data: Any, status: int = 200) -> MagicMock:
Expand Down Expand Up @@ -388,6 +389,21 @@ def test_auth_header(self, mock_urlopen: MagicMock) -> None:
request = mock_urlopen.call_args[0][0]
self.assertEqual(request.get_header("X-agent-key"), "dlg_mykey123")
self.assertEqual(request.get_header("Content-type"), "application/json")
self.assertEqual(request.get_header("User-agent"), USER_AGENT)

@patch("delega.async_client._require_httpx")
def test_async_client_sets_user_agent(self, mock_require_httpx: MagicMock) -> None:
fake_httpx = MagicMock()
fake_async_client = MagicMock()
fake_httpx.AsyncClient = fake_async_client
mock_require_httpx.return_value = fake_httpx

from delega.async_client import AsyncDelega

AsyncDelega(api_key="dlg_async")

_, kwargs = fake_async_client.call_args
self.assertEqual(kwargs["headers"]["User-Agent"], USER_AGENT)


class TestModels(unittest.TestCase):
Expand Down