(fix) add logic to test for message forwarding
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
import logging
|
||||||
|
import json
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
from .main import app
|
from .main import app
|
||||||
|
from .base_types import NotificationType, Notification
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
forward_notification_success_req = {
|
forward_notification_success_req = {
|
||||||
"warning": {
|
"warning": {
|
||||||
@@ -49,7 +54,7 @@ forward_notification_fail_req = {
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@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():
|
for description, req in forward_notification_success_req.items():
|
||||||
async with AsyncClient(
|
async with AsyncClient(
|
||||||
transport=ASGITransport(app=app), base_url="http://test"
|
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)
|
response = await ac.post("/notification", json=req)
|
||||||
assert response.status_code == 204, description
|
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
|
@pytest.mark.anyio
|
||||||
async def test_forward_notification_failure():
|
async def test_forward_notification_failure():
|
||||||
|
|||||||
Reference in New Issue
Block a user