From 071c2a522d0a7d747d6dab03f08fbbee5511debf Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 30 Jun 2026 22:10:34 +0200 Subject: [PATCH] fix: use httpx query parameters to correctly URL encode since timestamp --- gitea/client.py | 7 ++++--- tests/test_client.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gitea/client.py b/gitea/client.py index 73cb119..311f2c5 100644 --- a/gitea/client.py +++ b/gitea/client.py @@ -400,10 +400,11 @@ class GiteaClient(IssuesClient, PullRequestsClient, FilesClient, RefsClient, Rep def list_unread_notifications(self, since: Optional[str] = None) -> list[dict[str, Any]]: try: with httpx.Client() as client: - url = f"{self.base_url}/api/v1/notifications?all=false" + url = f"{self.base_url}/api/v1/notifications" + params: dict[str, str] = {"all": "false"} if since: - url += f"&since={since}" - response = client.get(url, headers=self.headers) + params["since"] = since + response = client.get(url, headers=self.headers, params=params) response.raise_for_status() notifications: list[dict[str, Any]] = response.json() diff --git a/tests/test_client.py b/tests/test_client.py index c05d2bf..8857667 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -93,3 +93,32 @@ def test_gitea_client_list_assigned_pull_requests() -> None: assert 2 in numbers assert 3 not in numbers + +def test_gitea_client_list_unread_notifications() -> None: + client: GiteaClient = GiteaClient() + with patch("httpx.Client.get") as mock_get: + mock_response: MagicMock = MagicMock() + mock_response.status_code = 200 + mock_response.json.return_value = [ + {"id": 1, "repository": {"owner": {"login": "meeks"}}}, + {"id": 2, "repository": {"owner": {"login": "other"}}}, + ] + mock_get.return_value = mock_response + + # Test without since + res = client.list_unread_notifications() + mock_get.assert_called_once() + _, kwargs = mock_get.call_args + assert kwargs.get("params") == {"all": "false"} + assert len(res) == 1 + assert res[0]["id"] == 1 + + mock_get.reset_mock() + + # Test with since + res = client.list_unread_notifications(since="2026-06-30T21:41:16+02:00") + mock_get.assert_called_once() + _, kwargs = mock_get.call_args + assert kwargs.get("params") == {"all": "false", "since": "2026-06-30T21:41:16+02:00"} + +