mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-01 18:18:31 +00:00
Add basic free-busy report
This commit is contained in:
parent
6b34323c1e
commit
7b0d88ff0d
5 changed files with 156 additions and 43 deletions
|
@ -27,6 +27,7 @@ import sys
|
|||
import tempfile
|
||||
import wsgiref.util
|
||||
import xml.etree.ElementTree as ET
|
||||
import vobject
|
||||
from io import BytesIO
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
|
@ -35,7 +36,7 @@ import defusedxml.ElementTree as DefusedET
|
|||
import radicale
|
||||
from radicale import app, config, types, xmlutils
|
||||
|
||||
RESPONSES = Dict[str, Union[int, Dict[str, Tuple[int, ET.Element]]]]
|
||||
RESPONSES = Dict[str, Union[int, Dict[str, Tuple[int, ET.Element]], vobject.base.Component]]
|
||||
|
||||
# Enable debug output
|
||||
radicale.log.logger.setLevel(logging.DEBUG)
|
||||
|
@ -107,8 +108,7 @@ class BaseTest:
|
|||
def parse_responses(text: str) -> RESPONSES:
|
||||
xml = DefusedET.fromstring(text)
|
||||
assert xml.tag == xmlutils.make_clark("D:multistatus")
|
||||
path_responses: Dict[str, Union[
|
||||
int, Dict[str, Tuple[int, ET.Element]]]] = {}
|
||||
path_responses: RESPONSES = {}
|
||||
for response in xml.findall(xmlutils.make_clark("D:response")):
|
||||
href = response.find(xmlutils.make_clark("D:href"))
|
||||
assert href.text not in path_responses
|
||||
|
@ -133,6 +133,12 @@ class BaseTest:
|
|||
path_responses[href.text] = prop_respones
|
||||
return path_responses
|
||||
|
||||
@staticmethod
|
||||
def parse_free_busy(text: str) -> RESPONSES:
|
||||
path_responses: RESPONSES = {}
|
||||
path_responses[""] = vobject.readOne(text)
|
||||
return path_responses
|
||||
|
||||
def get(self, path: str, check: Optional[int] = 200, **kwargs
|
||||
) -> Tuple[int, str]:
|
||||
assert "data" not in kwargs
|
||||
|
@ -177,13 +183,18 @@ class BaseTest:
|
|||
return status, responses
|
||||
|
||||
def report(self, path: str, data: str, check: Optional[int] = 207,
|
||||
is_xml: Optional[bool] = True,
|
||||
**kwargs) -> Tuple[int, RESPONSES]:
|
||||
status, _, answer = self.request("REPORT", path, data, check=check,
|
||||
**kwargs)
|
||||
if status < 200 or 300 <= status:
|
||||
return status, {}
|
||||
assert answer is not None
|
||||
return status, self.parse_responses(answer)
|
||||
if is_xml:
|
||||
parsed = self.parse_responses(answer)
|
||||
else:
|
||||
parsed = self.parse_free_busy(answer)
|
||||
return status, parsed
|
||||
|
||||
def delete(self, path: str, check: Optional[int] = 200, **kwargs
|
||||
) -> Tuple[int, RESPONSES]:
|
||||
|
|
|
@ -22,6 +22,7 @@ Radicale tests with simple requests.
|
|||
|
||||
import os
|
||||
import posixpath
|
||||
import vobject
|
||||
from typing import Any, Callable, ClassVar, Iterable, List, Optional, Tuple
|
||||
|
||||
import defusedxml.ElementTree as DefusedET
|
||||
|
@ -1360,10 +1361,27 @@ permissions: RrWw""")
|
|||
</C:calendar-query>""")
|
||||
assert len(responses) == 1
|
||||
response = responses[event_path]
|
||||
assert not isinstance(response, int)
|
||||
assert isinstance(response, dict)
|
||||
status, prop = response["D:getetag"]
|
||||
assert status == 200 and prop.text
|
||||
|
||||
def test_report_free_busy(self) -> None:
|
||||
"""Test free busy report on a few items"""
|
||||
calendar_path = "/calendar.ics/"
|
||||
self.mkcalendar(calendar_path)
|
||||
for i in (1,2):
|
||||
filename = "event{}.ics".format(i)
|
||||
event = get_file_content(filename)
|
||||
self.put(posixpath.join(calendar_path, filename), event)
|
||||
code, responses = self.report(calendar_path, """\
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:free-busy-query xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<C:time-range start="20130901T140000Z" end="20130908T220000Z"/>
|
||||
</C:free-busy-query>""", 200, is_xml = False)
|
||||
assert len(responses) == 1
|
||||
for response in responses.values():
|
||||
assert isinstance(response, vobject.base.Component)
|
||||
|
||||
def _report_sync_token(
|
||||
self, calendar_path: str, sync_token: Optional[str] = None
|
||||
) -> Tuple[str, RESPONSES]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue