Skip to content

Commit 4d588c9

Browse files
committed
hnng
1 parent 61f5db7 commit 4d588c9

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ This project should adhere to [Semantic Versioning](https://semver.org/spec/v2.0
1414

1515
## [Unreleased]
1616

17-
### Breaking Changes
18-
19-
* The icalendar dependency is updated from 6 to 7 - not because 3.0 depends on icalendar7, but because I'm planning to use icalendar7-features in some upcoming 3.x. If this causes problems for you, just reach out and I will downgrade the dependency, release a new 3.0.1, and possibly procrastinate the icalendar7-stuff until 4.0.
20-
2117
### Added
2218

2319
* **Stalwart CalDAV server** added to Docker test server framework.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies = [
5656
"niquests",
5757
"recurring-ical-events>=2.0.0",
5858
"typing_extensions;python_version<'3.11'",
59-
"icalendar>7.0.0",
59+
"icalendar>6.0.0",
6060
"icalendar-searcher>=1.0.5,<2",
6161
"dnspython",
6262
"python-dateutil",

tests/test_async_davclient.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,63 @@ def test_has_component_with_only_vcalendar(self) -> None:
821821
assert obj.has_component() is False
822822

823823

824+
class TestAsyncCalendarAddObject:
825+
"""Tests for Calendar.add_object/add_event/add_todo with async clients (issue #631)."""
826+
827+
SIMPLE_EVENT = """BEGIN:VCALENDAR
828+
VERSION:2.0
829+
PRODID:-//Test//Test//EN
830+
BEGIN:VEVENT
831+
UID:test-async-add-event@example.com
832+
DTSTART:20200101T100000Z
833+
DTEND:20200101T110000Z
834+
SUMMARY:Test Async Add Event
835+
END:VEVENT
836+
END:VCALENDAR"""
837+
838+
@pytest.mark.asyncio
839+
async def test_add_event_returns_coroutine_with_async_client(self) -> None:
840+
"""Calendar.add_event() must be awaitable when using AsyncDAVClient.
841+
842+
Regression test for issue #631: o.save() returns a coroutine for async
843+
clients, so add_object() must await it instead of doing o.url on the
844+
coroutine object.
845+
"""
846+
from caldav.aio import AsyncEvent
847+
from caldav.collection import Calendar
848+
849+
client = AsyncDAVClient(url="https://caldav.example.com/dav/")
850+
# Mock _async_create so no real HTTP happens
851+
AsyncEvent._async_create = AsyncMock()
852+
853+
calendar = Calendar(client=client, url="https://caldav.example.com/dav/calendars/test/")
854+
855+
result = calendar.add_event(self.SIMPLE_EVENT)
856+
# With an async client, add_event must return a coroutine
857+
import inspect
858+
859+
assert inspect.isawaitable(result), (
860+
"add_event() should return a coroutine when using AsyncDAVClient, "
861+
"got %r instead" % result
862+
)
863+
event = await result
864+
assert isinstance(event, AsyncEvent)
865+
866+
@pytest.mark.asyncio
867+
async def test_add_event_result_has_url(self) -> None:
868+
"""Awaiting add_event() with async client returns an Event with a URL."""
869+
from caldav.aio import AsyncEvent
870+
from caldav.collection import Calendar
871+
872+
client = AsyncDAVClient(url="https://caldav.example.com/dav/")
873+
AsyncEvent._async_create = AsyncMock()
874+
875+
calendar = Calendar(client=client, url="https://caldav.example.com/dav/calendars/test/")
876+
event = await calendar.add_event(self.SIMPLE_EVENT)
877+
# Should have a URL set (or None, but not crash)
878+
_ = event.url # must not raise AttributeError
879+
880+
824881
class TestAsyncRateLimiting:
825882
"""
826883
Unit tests for 429/503 rate-limit handling in AsyncDAVClient.

0 commit comments

Comments
 (0)