(fix) add logic to test for message forwarding

This commit is contained in:
Nicolas Sebastian Schuler
2025-07-18 09:58:48 +02:00
parent 8d1f6774b2
commit 8763e7f741

View File

@@ -1,8 +1,13 @@
import pytest
import logging
import json
from httpx import ASGITransport, AsyncClient
from pydantic import ValidationError
from .main import app
from .base_types import NotificationType, Notification
LOGGER = logging.getLogger(__name__)
forward_notification_success_req = {
"warning": {
@@ -49,7 +54,7 @@ forward_notification_fail_req = {
@pytest.mark.anyio
async def test_forward_notification_success():
async def test_forward_notification_success(caplog):
for description, req in forward_notification_success_req.items():
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
@@ -57,6 +62,21 @@ async def test_forward_notification_success():
response = await ac.post("/notification", json=req)
assert response.status_code == 204, description
match req["Type"]:
case NotificationType.INFO:
pass
case NotificationType.WARNING:
# Check forwarding to logger
try:
res = Notification.model_validate_json(
json_data=json.dumps(req)
)
except ValidationError:
raise Exception(
"Model could not be serialized. Check dummy data"
)
assert str(res) in caplog.text
@pytest.mark.anyio
async def test_forward_notification_failure():