From 8763e7f741310c2e8bdef1b447ef7d290b619596 Mon Sep 17 00:00:00 2001 From: Nicolas Sebastian Schuler Date: Fri, 18 Jul 2025 09:58:48 +0200 Subject: [PATCH] (fix) add logic to test for message forwarding --- app/test_main.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/test_main.py b/app/test_main.py index 803666f..8247530 100644 --- a/app/test_main.py +++ b/app/test_main.py @@ -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():