You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from types import SimpleNamespace
|
|
|
|
import app.main as main_module
|
|
from app.core.models import CoreBusySlot
|
|
|
|
|
|
class _DummyCoreService:
|
|
def check_availability(
|
|
self,
|
|
start: str,
|
|
end: str,
|
|
calendar_ids: list[str] | None,
|
|
) -> SimpleNamespace:
|
|
checked = calendar_ids or ["primary"]
|
|
busy_slots = [
|
|
CoreBusySlot(
|
|
calendar_id=checked[0],
|
|
start=start,
|
|
end=end,
|
|
)
|
|
]
|
|
return SimpleNamespace(
|
|
start=start,
|
|
end=end,
|
|
available=False,
|
|
busy_slots=busy_slots,
|
|
checked_calendars=checked,
|
|
)
|
|
|
|
|
|
def test_rest_availability_adapter_returns_expected_payload(monkeypatch) -> None:
|
|
monkeypatch.setattr(main_module, "core_service", _DummyCoreService())
|
|
|
|
response = asyncio.run(
|
|
main_module.availability(
|
|
main_module.AvailabilityRequest(
|
|
start="2026-03-10T09:00:00+01:00",
|
|
end="2026-03-10T10:00:00+01:00",
|
|
calendar_ids=["primary"],
|
|
)
|
|
)
|
|
)
|
|
|
|
payload = response.model_dump()
|
|
assert payload["available"] is False
|
|
assert payload["checked_calendars"] == ["primary"]
|
|
assert payload["busy_slots"] == [
|
|
{
|
|
"calendar_id": "primary",
|
|
"start": "2026-03-10T09:00:00+01:00",
|
|
"end": "2026-03-10T10:00:00+01:00",
|
|
}
|
|
]
|