review fixes

This commit is contained in:
2026-03-31 01:49:38 +03:00
parent a69e3338b1
commit 71f9044f27
2 changed files with 23 additions and 5 deletions

View File

@@ -19,7 +19,7 @@
#
import json
from aiohttp.web import StreamResponse
from aiohttp.web import HTTPBadRequest, StreamResponse
from aiohttp_sse import EventSourceResponse, sse_response
from asyncio import Queue, QueueShutDown, wait_for
from typing import ClassVar
@@ -69,6 +69,7 @@ class EventBusView(BaseView):
summary="Live updates",
description="Stream live updates via SSE",
permission=GET_PERMISSION,
error_400_enabled=True,
error_404_description="Repository is unknown",
schema=SSESchema(many=True),
query_schema=EventBusFilterSchema,
@@ -79,8 +80,14 @@ class EventBusView(BaseView):
Returns:
StreamResponse: 200 with streaming updates
Raises:
HTTPBadRequest: if invalid event type is supplied
"""
try:
topics = [EventType(event) for event in self.request.query.getall("event", [])] or None
except ValueError as ex:
raise HTTPBadRequest(reason=str(ex))
event_bus = self.service().event_bus
async with sse_response(self.request) as response:

View File

@@ -33,7 +33,8 @@ async def test_get_permission() -> None:
"""
must return correct permission for the request
"""
request = pytest.helpers.request("", "", "GET")
for method in ("GET",):
request = pytest.helpers.request("", "", method)
assert await EventBusView.get_permission(request) == UserAccess.Full
@@ -98,6 +99,17 @@ async def test_get_with_topic_filter(client: TestClient, package_ahriman: Packag
assert EventType.PackageRemoved not in body
async def test_get_bad_request(client: TestClient) -> None:
"""
must return bad request for invalid event type
"""
response_schema = pytest.helpers.schema_response(EventBusView.get, code=400)
response = await client.get("/api/v1/events/stream", params={"event": "invalid"})
assert response.status == 400
assert not response_schema.validate(await response.json())
async def test_get_not_found(client: TestClient) -> None:
"""
must return not found for unknown repository
@@ -114,6 +126,5 @@ async def test_get_connection_reset(client: TestClient, mocker: MockerFixture) -
must handle connection reset
"""
mocker.patch.object(EventBusView, "_run", side_effect=ConnectionResetError)
response = await client.get("/api/v1/events/stream")
assert response.status == 200