diff --git a/radicale/tests/static/contact1.vcf b/radicale/tests/static/contact1.vcf
index 3f526d24..35472ded 100644
--- a/radicale/tests/static/contact1.vcf
+++ b/radicale/tests/static/contact1.vcf
@@ -3,4 +3,5 @@ VERSION:3.0
UID:contact1
N:Contact;;;;
FN:Contact
+NICKNAME:test
END:VCARD
diff --git a/radicale/tests/test_base.py b/radicale/tests/test_base.py
index 608d4b79..9bc640a6 100644
--- a/radicale/tests/test_base.py
+++ b/radicale/tests/test_base.py
@@ -25,6 +25,7 @@ import posixpath
import shutil
import tempfile
import xml.etree.ElementTree as ET
+from functools import partial
import pytest
@@ -404,31 +405,162 @@ class BaseRequestsMixIn:
assert status == 200
assert answer.count("BEGIN:VEVENT") == 2
- def _test_filter(self, filters, kind="event", items=(1,)):
- filters_text = "".join(
- "%s" % filter_ for filter_ in filters)
- status, _, _ = self.request("DELETE", "/calendar.ics/")
+ def _test_filter(self, filters, kind="event", test=None, items=(1,)):
+ filter_template = "{}"
+ if kind in ("event", "journal", "todo"):
+ create_collection_fn = partial(self.request, "MKCALENDAR")
+ path = "/calendar.ics/"
+ filename_template = "{}{}.ics"
+ namespace = "urn:ietf:params:xml:ns:caldav"
+ report = "calendar-query"
+ elif kind == "contact":
+ create_collection_fn = self._create_addressbook
+ if test:
+ filter_template = '{{}}'.format(
+ test)
+ path = "/contacts.vcf/"
+ filename_template = "{}{}.vcf"
+ namespace = "urn:ietf:params:xml:ns:carddav"
+ report = "addressbook-query"
+ else:
+ raise ValueError("Unsupported kind: %r" % kind)
+ status, _, _ = self.request("DELETE", path)
assert status in (200, 404)
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
+ status, _, _ = create_collection_fn(path)
assert status == 201
for i in items:
- filename = "{}{}.ics".format(kind, i)
+ filename = filename_template.format(kind, i)
event = get_file_content(filename)
status, _, _ = self.request(
- "PUT", "/calendar.ics/%s" % filename, event)
+ "PUT", posixpath.join(path, filename), event)
assert status == 201
+ filters_text = "".join(
+ filter_template.format(filter_) for filter_ in filters)
status, _, answer = self.request(
- "REPORT", "/calendar.ics",
+ "REPORT", path,
"""
-
+
- %s
- """ % filters_text)
+ {2}
+ """.format(namespace, report, filters_text))
assert status == 207
return answer
+ def test_addressbook_empty_filter(self):
+ self._test_filter([""], kind="contact")
+
+ def test_addressbook_prop_filter(self):
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ es
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ es
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ a
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ test
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ tes
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ est
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ tes
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ est
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ est
+ """], "contact")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ tes
+ """], "contact")
+
+ def test_addressbook_prop_filter_any(self):
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ test
+
+
+ test
+ """], "contact", test="anyof")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ a
+
+
+ test
+ """], "contact", test="anyof")
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ test
+
+
+ test
+ """], "contact")
+
+ def test_addressbook_prop_filter_all(self):
+ assert "href>/contacts.vcf/contact1.vcf" in self._test_filter(["""
+
+ tes
+
+
+ est
+ """], "contact", test="allof")
+ assert "href>/contacts.vcf/contact1.vcf" not in self._test_filter(["""
+
+ test
+
+
+ test
+ """], "contact", test="allof")
+
def test_calendar_empty_filter(self):
self._test_filter([""])