Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation fixes for processing expand property #1465

Merged
merged 1 commit into from
Apr 6, 2024
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
20 changes: 11 additions & 9 deletions radicale/app/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import socket
import xml.etree.ElementTree as ET
from http import client
from typing import Callable, Iterable, Iterator, Optional, Sequence, Tuple
from typing import (Callable, Iterable, Iterator, List, Optional, Sequence,
Tuple, Union)
from urllib.parse import unquote, urlparse

import vobject.base
from vobject.base import ContentLine

import radicale.item as radicale_item
Expand Down Expand Up @@ -69,7 +71,7 @@ def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
xmlutils.make_human_tag(root.tag), path)
return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report")

props = root.find(xmlutils.make_clark("D:prop")) or []
props: Union[ET.Element, List] = root.find(xmlutils.make_clark("D:prop")) or []

hreferences: Iterable[str]
if root.tag in (
Expand Down Expand Up @@ -203,21 +205,21 @@ def _expand(
if rruleset:
recurrences = rruleset.between(start, end)

expanded = None
for recurrence_dt in recurrences:
vobject_item = copy.copy(expanded_item.vobject_item)
expanded: vobject.base.Component = copy.copy(expanded_item.vobject_item)
is_expanded_filled: bool = False

for recurrence_dt in recurrences:
recurrence_utc = recurrence_dt.astimezone(datetime.timezone.utc)

vevent = copy.deepcopy(vobject_item.vevent)
vevent = copy.deepcopy(expanded.vevent)
vevent.recurrence_id = ContentLine(
name='RECURRENCE-ID',
value=recurrence_utc.strftime('%Y%m%dT%H%M%SZ'), params={}
)

if expanded is None:
vobject_item.vevent = vevent
expanded = vobject_item
if is_expanded_filled is False:
expanded.vevent = vevent
is_expanded_filled = True
else:
expanded.add(vevent)

Expand Down
21 changes: 12 additions & 9 deletions radicale/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ def test_report_sync_collection_invalid_sync_token(self) -> None:
assert not sync_token

def test_report_with_expand_property(self) -> None:
"""Test report with expand property"""
self.put("/calendar.ics/", get_file_content("event_daily_rrule.ics"))
req_body_without_expand = \
"""<?xml version="1.0" encoding="utf-8" ?>
Expand All @@ -1546,21 +1547,22 @@ def test_report_with_expand_property(self) -> None:
_, responses = self.report("/calendar.ics/", req_body_without_expand)
assert len(responses) == 1

response = responses['/calendar.ics/event_daily_rrule.ics']
status, element = list(response.values())[0]
response_without_expand = responses['/calendar.ics/event_daily_rrule.ics']
assert not isinstance(response_without_expand, int)
status, element = response_without_expand["C:calendar-data"]

assert status == 200
assert status == 200 and element.text

assert "RRULE" in element.text
assert "BEGIN:VTIMEZONE" in element.text
assert "RECURRENCE-ID" not in element.text

uids = []
uids: List[str] = []
for line in element.text.split("\n"):
if line.startswith("UID:"):
uid = line[len("UID:"):]
assert uid == "event_daily_rrule"
uids.append(uids)
uids.append(uid)

assert len(uids) == 1

Expand All @@ -1586,10 +1588,11 @@ def test_report_with_expand_property(self) -> None:

assert len(responses) == 1

response = responses['/calendar.ics/event_daily_rrule.ics']
status, element = list(response.values())[0]
response_with_expand = responses['/calendar.ics/event_daily_rrule.ics']
assert not isinstance(response_with_expand, int)
status, element = response_with_expand["C:calendar-data"]

assert status == 200
assert status == 200 and element.text
assert "RRULE" not in element.text
assert "BEGIN:VTIMEZONE" not in element.text

Expand All @@ -1598,7 +1601,7 @@ def test_report_with_expand_property(self) -> None:
for line in element.text.split("\n"):
if line.startswith("UID:"):
assert line == "UID:event_daily_rrule"
uids.append(uids)
uids.append(line)

if line.startswith("RECURRENCE-ID:"):
recurrence_ids.append(line)
Expand Down
Loading