fix: use httpx query parameters to correctly URL encode since timestamp
This commit is contained in:
+4
-3
@@ -400,10 +400,11 @@ class GiteaClient(IssuesClient, PullRequestsClient, FilesClient, RefsClient, Rep
|
|||||||
def list_unread_notifications(self, since: Optional[str] = None) -> list[dict[str, Any]]:
|
def list_unread_notifications(self, since: Optional[str] = None) -> list[dict[str, Any]]:
|
||||||
try:
|
try:
|
||||||
with httpx.Client() as client:
|
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:
|
if since:
|
||||||
url += f"&since={since}"
|
params["since"] = since
|
||||||
response = client.get(url, headers=self.headers)
|
response = client.get(url, headers=self.headers, params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
notifications: list[dict[str, Any]] = response.json()
|
notifications: list[dict[str, Any]] = response.json()
|
||||||
|
|
||||||
|
|||||||
@@ -93,3 +93,32 @@ def test_gitea_client_list_assigned_pull_requests() -> None:
|
|||||||
assert 2 in numbers
|
assert 2 in numbers
|
||||||
assert 3 not 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"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user