Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TASK.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@
- [x] Add async EmergencyManagement controller handlers for new CRUD endpoints.
- [x] Expand EmergencyManagement OpenAPI specification with notifications streaming and updated schemas.
- [x] Resolve dataclass JSON decoding for postponed annotations in nested payloads.
- [x] Extend EmergencyManagement controller and client tests for identifier errors and MessagePack/JSON fallbacks.

83 changes: 83 additions & 0 deletions tests/test_example_emergency_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,56 @@ async def test_event_controller_delete_missing(emergency_db) -> None:
assert result == {"status": "not_found", "uid": "999"}


@pytest.mark.asyncio
async def test_event_controller_retrieve_invalid_identifier_returns_error(
emergency_db,
) -> None:
"""Invalid identifiers should surface structured controller errors."""

controller = EventController()

result = await controller.RetrieveEvent("not-an-integer")

assert result == {"error": "InternalServerError", "code": 500}


@pytest.mark.asyncio
async def test_event_controller_list_without_session_factory(monkeypatch) -> None:
"""Missing session factories should be reported via controller error payloads."""

monkeypatch.setattr(
"examples.EmergencyManagement.Server.controllers_emergency.async_session",
None,
)
monkeypatch.setattr(
database_module,
"async_session",
None,
raising=False,
)

controller = EventController()

result = await controller.ListEvent()

assert result == {"error": "InternalServerError", "code": 500}


def test_decode_event_fallback_handles_messagepack() -> None:
"""The client decoder accepts MessagePack event payloads."""

from examples.EmergencyManagement.client import client as client_module

event = Event(uid=8, type="Exercise", qos=2)
payload = dataclass_to_msgpack(event)

decoded = client_module._decode_event(payload)

assert isinstance(decoded, Event)
assert decoded.uid == event.uid
assert decoded.qos == event.qos


def test_decode_event_fallback_handles_compressed_json() -> None:
"""The client decoder accepts compressed JSON event payloads."""

Expand All @@ -163,6 +213,21 @@ def test_decode_event_fallback_handles_compressed_json() -> None:
assert decoded.point.lat == event.point.lat


def test_decode_optional_event_fallback_handles_messagepack() -> None:
"""Optional event decoding handles MessagePack payloads."""

from examples.EmergencyManagement.client import client as client_module

event = Event(uid=12, type="Status", version=3)
payload = dataclass_to_msgpack(event)

decoded = client_module._decode_optional_event(payload)

assert isinstance(decoded, Event)
assert decoded.uid == event.uid
assert decoded.version == event.version


def test_decode_optional_event_fallback_handles_compressed_json() -> None:
"""Optional event decoding also supports compressed JSON payloads."""

Expand All @@ -179,6 +244,24 @@ def test_decode_optional_event_fallback_handles_compressed_json() -> None:
assert decoded.point.lon == event.point.lon


def test_decode_event_list_fallback_handles_messagepack() -> None:
"""List decoder accepts MessagePack payloads containing mapping entries."""

from examples.EmergencyManagement.client import client as client_module

events = [
Event(uid=31, type="Drill", qos=1),
Event(uid=32, type="Alert", opex=2),
]
payload = dataclass_to_msgpack([asdict(item) for item in events])

decoded = client_module._decode_event_list(payload)

assert [item.uid for item in decoded] == [31, 32]
assert decoded[0].qos == events[0].qos
assert decoded[1].opex == events[1].opex


def test_decode_event_list_fallback_handles_compressed_json() -> None:
"""List decoder returns dataclasses when given compressed JSON payloads."""

Expand Down
Loading