mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-05-02 22:16:34 +00:00
zz
This commit is contained in:
@@ -82,15 +82,42 @@ async def test_subscribe(event_bus: EventBus) -> None:
|
||||
assert subscriber_id in event_bus._subscribers
|
||||
|
||||
|
||||
async def test_broadcast_with_object_id(event_bus: EventBus, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must broadcast event to subscribers with matching object_id
|
||||
"""
|
||||
_, queue = await event_bus.subscribe(object_id=package_ahriman.base)
|
||||
await event_bus.broadcast(EventType.PackageUpdated, package_ahriman.base)
|
||||
assert not queue.empty()
|
||||
|
||||
|
||||
async def test_broadcast_object_id_isolation(event_bus: EventBus, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must not broadcast event to subscribers with non-matching object_id
|
||||
"""
|
||||
_, queue = await event_bus.subscribe(object_id="other-package")
|
||||
await event_bus.broadcast(EventType.PackageUpdated, package_ahriman.base)
|
||||
assert queue.empty()
|
||||
|
||||
|
||||
async def test_subscribe_with_topics(event_bus: EventBus) -> None:
|
||||
"""
|
||||
must register subscriber with topic filter
|
||||
"""
|
||||
subscriber_id, _ = await event_bus.subscribe([EventType.BuildLog])
|
||||
topics, _ = event_bus._subscribers[subscriber_id]
|
||||
topics, _, _ = event_bus._subscribers[subscriber_id]
|
||||
assert topics == [EventType.BuildLog]
|
||||
|
||||
|
||||
async def test_subscribe_with_object_id(event_bus: EventBus, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must register subscriber with object_id filter
|
||||
"""
|
||||
subscriber_id, _ = await event_bus.subscribe(object_id=package_ahriman.base)
|
||||
_, object_id, _ = event_bus._subscribers[subscriber_id]
|
||||
assert object_id == package_ahriman.base
|
||||
|
||||
|
||||
async def test_unsubscribe(event_bus: EventBus) -> None:
|
||||
"""
|
||||
must remove subscriber
|
||||
|
||||
@@ -99,6 +99,23 @@ async def test_get_with_topic_filter(client: TestClient, package_ahriman: Packag
|
||||
assert EventType.PackageRemoved not in body
|
||||
|
||||
|
||||
async def test_get_with_object_id_filter(client: TestClient, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must filter events by object_id
|
||||
"""
|
||||
watcher = next(iter(client.app[WatcherKey].values()))
|
||||
asyncio.create_task(_producer(watcher, package_ahriman))
|
||||
request_schema = pytest.helpers.schema_request(EventBusView.get, location="querystring")
|
||||
|
||||
payload = {"object_id": "non-existent-package"}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.get("/api/v1/events/stream", params=payload)
|
||||
assert response.status == 200
|
||||
|
||||
body = await response.text()
|
||||
assert "ahriman" not in body
|
||||
|
||||
|
||||
async def test_get_bad_request(client: TestClient) -> None:
|
||||
"""
|
||||
must return bad request for invalid event type
|
||||
|
||||
Reference in New Issue
Block a user