| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538 |
- # This file is part of Radicale Server - Calendar Server
- # Copyright © 2012-2017 Guillaume Ayoub
- #
- # This library is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
- """
- Radicale tests with simple requests.
- """
- import base64
- import os
- import posixpath
- import shutil
- import tempfile
- import xml.etree.ElementTree as ET
- from functools import partial
- import pytest
- from radicale import Application, config
- from . import BaseTest
- from .helpers import get_file_content
- class BaseRequestsMixIn:
- """Tests with simple requests."""
- def test_root(self):
- """GET request at "/"."""
- status, _, answer = self.request("GET", "/")
- assert status == 302
- assert answer == "Redirected to .web"
- def test_script_name(self):
- """GET request at "/" with SCRIPT_NAME."""
- status, _, answer = self.request("GET", "/", SCRIPT_NAME="/radicale")
- assert status == 302
- assert answer == "Redirected to .web"
- status, _, answer = self.request("GET", "", SCRIPT_NAME="/radicale")
- assert status == 302
- assert answer == "Redirected to radicale/.web"
- def test_add_event(self):
- """Add an event."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- path = "/calendar.ics/event1.ics"
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, headers, answer = self.request("GET", path)
- assert status == 200
- assert "ETag" in headers
- assert headers["Content-Type"] == "text/calendar; charset=utf-8"
- assert "VEVENT" in answer
- assert "Event" in answer
- assert "UID:event" in answer
- def test_add_event_without_uid(self):
- """Add an event without UID."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics").replace("UID:event1\n", "")
- assert "\nUID:" not in event
- path = "/calendar.ics/event.ics"
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- uids = []
- for line in answer.split("\r\n"):
- if line.startswith("UID:"):
- uids.append(line[len("UID:"):])
- assert len(uids) == 1 and uids[0]
- # Overwrite the event with an event without UID and check that the UID
- # is still the same
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- assert "\r\nUID:%s\r\n" % uids[0] in answer
- def test_add_todo(self):
- """Add a todo."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- todo = get_file_content("todo1.ics")
- path = "/calendar.ics/todo1.ics"
- status, _, _ = self.request("PUT", path, todo)
- assert status == 201
- status, headers, answer = self.request("GET", path)
- assert status == 200
- assert "ETag" in headers
- assert headers["Content-Type"] == "text/calendar; charset=utf-8"
- assert "VTODO" in answer
- assert "Todo" in answer
- assert "UID:todo" in answer
- def _create_addressbook(self, path):
- return self.request(
- "MKCOL", path, """\
- <?xml version="1.0" encoding="UTF-8" ?>
- <create xmlns="DAV:" xmlns:CR="urn:ietf:params:xml:ns:carddav">
- <set>
- <prop>
- <resourcetype>
- <collection />
- <CR:addressbook />
- </resourcetype>
- </prop>
- </set>
- </create>""")
- def test_add_contact(self):
- """Add a contact."""
- status, _, _ = self._create_addressbook("/contacts.vcf/")
- assert status == 201
- contact = get_file_content("contact1.vcf")
- path = "/contacts.vcf/contact.vcf"
- status, _, _ = self.request("PUT", path, contact)
- assert status == 201
- status, headers, answer = self.request("GET", path)
- assert status == 200
- assert "ETag" in headers
- assert headers["Content-Type"] == "text/vcard; charset=utf-8"
- assert "VCARD" in answer
- assert "UID:contact1" in answer
- status, _, answer = self.request("GET", path)
- assert status == 200
- assert "UID:contact1" in answer
- def test_add_contact_without_uid(self):
- """Add a contact."""
- status, _, _ = self._create_addressbook("/contacts.vcf/")
- assert status == 201
- contact = get_file_content("contact1.vcf").replace("UID:contact1\n",
- "")
- assert "\nUID" not in contact
- path = "/contacts.vcf/contact.vcf"
- status, _, _ = self.request("PUT", path, contact)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- uids = []
- for line in answer.split("\r\n"):
- if line.startswith("UID:"):
- uids.append(line[len("UID:"):])
- assert len(uids) == 1 and uids[0]
- # Overwrite the contact with an contact without UID and check that the
- # UID is still the same
- status, _, _ = self.request("PUT", path, contact)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- assert "\r\nUID:%s\r\n" % uids[0] in answer
- def test_update(self):
- """Update an event."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- path = "/calendar.ics/event1.ics"
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, headers, answer = self.request("GET", path)
- assert "ETag" in headers
- assert status == 200
- assert "VEVENT" in answer
- assert "Event" in answer
- assert "UID:event" in answer
- assert "DTSTART;TZID=Europe/Paris:20130901T180000" in answer
- assert "DTEND;TZID=Europe/Paris:20130901T190000" in answer
- # Then we send another PUT request
- event = get_file_content("event1-prime.ics")
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, _, answer = self.request("GET", "/calendar.ics/")
- assert status == 200
- assert answer.count("BEGIN:VEVENT") == 1
- status, headers, answer = self.request("GET", path)
- assert status == 200
- assert "ETag" in headers
- assert "VEVENT" in answer
- assert "Event" in answer
- assert "UID:event" in answer
- assert "DTSTART;TZID=Europe/Paris:20130901T180000" not in answer
- assert "DTEND;TZID=Europe/Paris:20130901T190000" not in answer
- assert "DTSTART;TZID=Europe/Paris:20140901T180000" in answer
- assert "DTEND;TZID=Europe/Paris:20140901T210000" in answer
- def test_put_whole_calendar(self):
- """Create and overwrite a whole calendar."""
- status, _, _ = self.request(
- "PUT", "/calendar.ics/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
- assert status == 201
- event1 = get_file_content("event1.ics")
- status, _, _ = self.request(
- "PUT", "/calendar.ics/test_event.ics", event1)
- assert status == 201
- # Overwrite
- events = get_file_content("event_multiple.ics")
- status, _, _ = self.request("PUT", "/calendar.ics/", events)
- assert status == 201
- status, _, _ = self.request("GET", "/calendar.ics/test_event.ics")
- assert status == 404
- status, _, answer = self.request("GET", "/calendar.ics/")
- assert status == 200
- assert "\r\nUID:event\r\n" in answer and "\r\nUID:todo\r\n" in answer
- assert "\r\nUID:event1\r\n" not in answer
- def test_put_whole_calendar_without_uids(self):
- """Create a whole calendar without UID."""
- event = get_file_content("event_multiple.ics")
- event = event.replace("UID:event\n", "").replace("UID:todo\n", "")
- assert "\nUID:" not in event
- status, _, _ = self.request("PUT", "/calendar.ics/", event)
- assert status == 201
- status, _, answer = self.request("GET", "/calendar.ics")
- assert status == 200
- uids = []
- for line in answer.split("\r\n"):
- if line.startswith("UID:"):
- uids.append(line[len("UID:"):])
- assert len(uids) == 2
- for i, uid1 in enumerate(uids):
- assert uid1
- for uid2 in uids[i + 1:]:
- assert uid1 != uid2
- def test_put_whole_addressbook(self):
- """Create and overwrite a whole addressbook."""
- contacts = get_file_content("contact_multiple.vcf")
- status, _, _ = self.request("PUT", "/contacts.vcf/", contacts)
- assert status == 201
- status, _, answer = self.request("GET", "/contacts.vcf/")
- assert status == 200
- assert ("\r\nUID:contact1\r\n" in answer and
- "\r\nUID:contact2\r\n" in answer)
- def test_put_whole_addressbook_without_uids(self):
- """Create a whole addressbook without UID."""
- contacts = get_file_content("contact_multiple.vcf")
- contacts = contacts.replace("UID:contact1\n", "").replace(
- "UID:contact2\n", "")
- assert "\nUID:" not in contacts
- status, _, _ = self.request("PUT", "/contacts.vcf/", contacts)
- assert status == 201
- status, _, answer = self.request("GET", "/contacts.vcf")
- assert status == 200
- uids = []
- for line in answer.split("\r\n"):
- if line.startswith("UID:"):
- uids.append(line[len("UID:"):])
- assert len(uids) == 2
- for i, uid1 in enumerate(uids):
- assert uid1
- for uid2 in uids[i + 1:]:
- assert uid1 != uid2
- def test_delete(self):
- """Delete an event."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- path = "/calendar.ics/event1.ics"
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- # Then we send a DELETE request
- status, _, answer = self.request("DELETE", path)
- assert status == 200
- assert "href>%s</" % path in answer
- status, _, answer = self.request("GET", "/calendar.ics/")
- assert status == 200
- assert "VEVENT" not in answer
- def test_mkcalendar(self):
- """Make a calendar."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- status, _, answer = self.request("GET", "/calendar.ics/")
- assert status == 200
- assert "BEGIN:VCALENDAR" in answer
- assert "END:VCALENDAR" in answer
- def test_move(self):
- """Move a item."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- path1 = "/calendar.ics/event1.ics"
- path2 = "/calendar.ics/event2.ics"
- status, _, _ = self.request("PUT", path1, event)
- assert status == 201
- status, _, _ = self.request(
- "MOVE", path1, HTTP_DESTINATION=path2, HTTP_HOST="")
- assert status == 201
- status, _, _ = self.request("GET", path1)
- assert status == 404
- status, _, _ = self.request("GET", path2)
- assert status == 200
- def test_head(self):
- status, _, _ = self.request("HEAD", "/")
- assert status == 302
- def test_options(self):
- status, headers, _ = self.request("OPTIONS", "/")
- assert status == 200
- assert "DAV" in headers
- def test_delete_collection(self):
- """Delete a collection."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- self.request("PUT", "/calendar.ics/event1.ics", event)
- status, _, answer = self.request("DELETE", "/calendar.ics/")
- assert status == 200
- assert "href>/calendar.ics/</" in answer
- status, _, _ = self.request("GET", "/calendar.ics/")
- assert status == 404
- def test_delete_root_collection(self):
- """Delete the root collection."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- status, _, _ = self.request("PUT", "/event1.ics", event)
- assert status == 201
- status, _, _ = self.request("PUT", "/calendar.ics/event1.ics", event)
- assert status == 201
- status, _, answer = self.request("DELETE", "/")
- assert status == 200
- assert "href>/</" in answer
- status, _, _ = self.request("GET", "/calendar.ics/")
- assert status == 404
- status, _, _ = self.request("GET", "/event1.ics")
- assert status == 404
- def test_propfind(self):
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- status, _, answer = self.request("PROPFIND", "/", HTTP_DEPTH="1")
- assert status == 207
- assert "href>/</" in answer
- assert "href>%s</" % calendar_path in answer
- status, _, answer = self.request(
- "PROPFIND", calendar_path, HTTP_DEPTH="1")
- assert status == 207
- assert "href>%s</" % calendar_path in answer
- assert "href>%s</" % event_path in answer
- def test_propfind_propname(self):
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- status, _, _ = self.request("PUT", "/calendar.ics/event.ics", event)
- assert status == 201
- propfind = get_file_content("propname.xml")
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/", propfind)
- assert "<sync-token />" in answer
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/event.ics", propfind)
- assert "<getetag />" in answer
- def test_propfind_allprop(self):
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- status, _, _ = self.request("PUT", "/calendar.ics/event.ics", event)
- assert status == 201
- propfind = get_file_content("allprop.xml")
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/", propfind)
- assert "<sync-token>" in answer
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/event.ics", propfind)
- assert "<getetag>" in answer
- def test_proppatch(self):
- """Write a property and read it back."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- proppatch = get_file_content("proppatch1.xml")
- status, _, answer = self.request(
- "PROPPATCH", "/calendar.ics/", proppatch)
- assert status == 207
- assert "calendar-color" in answer
- assert "200 OK</status" in answer
- # Read property back
- propfind = get_file_content("propfind1.xml")
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/", propfind)
- assert status == 207
- assert "<ICAL:calendar-color>#BADA55</" in answer
- assert "200 OK</status" in answer
- propfind = get_file_content("allprop.xml")
- status, _, answer = self.request(
- "PROPFIND", "/calendar.ics/", propfind)
- assert "<ICAL:calendar-color>" in answer
- def test_put_whole_calendar_multiple_events_with_same_uid(self):
- """Add two events with the same UID."""
- status, _, _ = self.request(
- "PUT", "/calendar.ics/", get_file_content("event2.ics"))
- assert status == 201
- status, _, answer = self.request(
- "REPORT", "/calendar.ics/",
- """<?xml version="1.0" encoding="utf-8" ?>
- <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
- <D:prop xmlns:D="DAV:"><D:getetag/></D:prop>
- </C:calendar-query>""")
- assert status == 207
- assert answer.count("<getetag>") == 1
- status, _, answer = self.request("GET", "/calendar.ics/")
- assert status == 200
- assert answer.count("BEGIN:VEVENT") == 2
- def _test_filter(self, filters, kind="event", test=None, items=(1,)):
- filter_template = "<C:filter>{}</C:filter>"
- 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 = '<C:filter test="{}">{{}}</C:filter>'.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, _, _ = create_collection_fn(path)
- assert status == 201
- for i in items:
- filename = filename_template.format(kind, i)
- event = get_file_content(filename)
- status, _, _ = self.request(
- "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", path,
- """<?xml version="1.0" encoding="utf-8" ?>
- <C:{1} xmlns:C="{0}">
- <D:prop xmlns:D="DAV:">
- <D:getetag/>
- </D:prop>
- {2}
- </C:{1}>""".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(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="contains"
- >es</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >es</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="contains"
- >a</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="equals"
- >test</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="equals"
- >tes</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="equals"
- >est</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="starts-with"
- >tes</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="starts-with"
- >est</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="ends-with"
- >est</C:text-match>
- </C:prop-filter>"""], "contact")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- match-type="ends-with"
- >tes</C:text-match>
- </C:prop-filter>"""], "contact")
- def test_addressbook_prop_filter_any(self):
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>
- <C:prop-filter name="EMAIL">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>"""], "contact", test="anyof")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >a</C:text-match>
- </C:prop-filter>
- <C:prop-filter name="EMAIL">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>"""], "contact", test="anyof")
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>
- <C:prop-filter name="EMAIL">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>"""], "contact")
- def test_addressbook_prop_filter_all(self):
- assert "href>/contacts.vcf/contact1.vcf</" in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >tes</C:text-match>
- </C:prop-filter>
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >est</C:text-match>
- </C:prop-filter>"""], "contact", test="allof")
- assert "href>/contacts.vcf/contact1.vcf</" not in self._test_filter(["""
- <C:prop-filter name="NICKNAME">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>
- <C:prop-filter name="EMAIL">
- <C:text-match collation="i;unicode-casemap"
- >test</C:text-match>
- </C:prop-filter>"""], "contact", test="allof")
- def test_calendar_empty_filter(self):
- self._test_filter([""])
- def test_calendar_tag_filter(self):
- """Report request with tag-based filter on calendar."""
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR"></C:comp-filter>"""])
- def test_item_tag_filter(self):
- """Report request with tag-based filter on an item."""
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT"></C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO"></C:comp-filter>
- </C:comp-filter>"""])
- def test_item_not_tag_filter(self):
- """Report request with tag-based is-not filter on an item."""
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:is-not-defined />
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:is-not-defined />
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_item_prop_filter(self):
- """Report request with prop-based filter on an item."""
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY"></C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="UNKNOWN"></C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_item_not_prop_filter(self):
- """Report request with prop-based is-not filter on an item."""
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="UNKNOWN">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_mutiple_filters(self):
- """Report request with multiple filters on an item."""
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>""", """
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="UNKNOWN">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY"></C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>""", """
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="UNKNOWN">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY"></C:prop-filter>
- <C:prop-filter name="UNKNOWN">
- <C:is-not-defined />
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_text_match_filter(self):
- """Report request with text-match filter on calendar."""
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY">
- <C:text-match>event</C:text-match>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="UNKNOWN">
- <C:text-match>event</C:text-match>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY">
- <C:text-match>unknown</C:text-match>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="SUMMARY">
- <C:text-match negate-condition="yes">event</C:text-match>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_param_filter(self):
- """Report request with param-filter on calendar."""
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="ATTENDEE">
- <C:param-filter name="PARTSTAT">
- <C:text-match collation="i;ascii-casemap"
- >ACCEPTED</C:text-match>
- </C:param-filter>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="ATTENDEE">
- <C:param-filter name="PARTSTAT">
- <C:text-match collation="i;ascii-casemap"
- >UNKNOWN</C:text-match>
- </C:param-filter>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" not in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="ATTENDEE">
- <C:param-filter name="PARTSTAT">
- <C:is-not-defined />
- </C:param-filter>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- assert "href>/calendar.ics/event1.ics</" in self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="ATTENDEE">
- <C:param-filter name="UNKNOWN">
- <C:is-not-defined />
- </C:param-filter>
- </C:prop-filter>
- </C:comp-filter>
- </C:comp-filter>"""])
- def test_time_range_filter_events(self):
- """Report request with time-range filter on events."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" in answer
- assert "href>/calendar.ics/event2.ics</" in answer
- assert "href>/calendar.ics/event3.ics</" in answer
- assert "href>/calendar.ics/event4.ics</" in answer
- assert "href>/calendar.ics/event5.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:prop-filter name="ATTENDEE">
- <C:param-filter name="PARTSTAT">
- <C:is-not-defined />
- </C:param-filter>
- </C:prop-filter>
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- assert "href>/calendar.ics/event3.ics</" not in answer
- assert "href>/calendar.ics/event4.ics</" not in answer
- assert "href>/calendar.ics/event5.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130902T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" in answer
- assert "href>/calendar.ics/event3.ics</" in answer
- assert "href>/calendar.ics/event4.ics</" in answer
- assert "href>/calendar.ics/event5.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130903T000000Z" end="20130908T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- assert "href>/calendar.ics/event3.ics</" in answer
- assert "href>/calendar.ics/event4.ics</" in answer
- assert "href>/calendar.ics/event5.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130903T000000Z" end="20130904T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- assert "href>/calendar.ics/event3.ics</" in answer
- assert "href>/calendar.ics/event4.ics</" not in answer
- assert "href>/calendar.ics/event5.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130805T000000Z" end="20130810T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=range(1, 6))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- assert "href>/calendar.ics/event3.ics</" not in answer
- assert "href>/calendar.ics/event4.ics</" not in answer
- assert "href>/calendar.ics/event5.ics</" not in answer
- # HACK: VObject doesn't match RECURRENCE-ID to recurrences, the
- # overwritten recurrence is still used for filtering.
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20170601T063000Z" end="20170601T070000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=(6, 7, 8))
- assert "href>/calendar.ics/event6.ics</" in answer
- assert "href>/calendar.ics/event7.ics</" in answer
- assert "href>/calendar.ics/event8.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20170701T060000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=(6, 7, 8))
- assert "href>/calendar.ics/event6.ics</" in answer
- assert "href>/calendar.ics/event7.ics</" in answer
- assert "href>/calendar.ics/event8.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20170702T070000Z" end="20170704T060000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], items=(6, 7, 8))
- assert "href>/calendar.ics/event6.ics</" not in answer
- assert "href>/calendar.ics/event7.ics</" not in answer
- assert "href>/calendar.ics/event8.ics</" not in answer
- def test_time_range_filter_events_rrule(self):
- """Report request with time-range filter on events with rrules."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=(1, 2))
- assert "href>/calendar.ics/event1.ics</" in answer
- assert "href>/calendar.ics/event2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20140801T000000Z" end="20141001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=(1, 2))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20120801T000000Z" end="20121001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=(1, 2))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VEVENT">
- <C:time-range start="20130903T000000Z" end="20130907T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "event", items=(1, 2))
- assert "href>/calendar.ics/event1.ics</" not in answer
- assert "href>/calendar.ics/event2.ics</" not in answer
- def test_time_range_filter_todos(self):
- """Report request with time-range filter on todos."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo1.ics</" in answer
- assert "href>/calendar.ics/todo2.ics</" in answer
- assert "href>/calendar.ics/todo3.ics</" in answer
- assert "href>/calendar.ics/todo4.ics</" in answer
- assert "href>/calendar.ics/todo5.ics</" in answer
- assert "href>/calendar.ics/todo6.ics</" in answer
- assert "href>/calendar.ics/todo7.ics</" in answer
- assert "href>/calendar.ics/todo8.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130901T160000Z" end="20130901T183000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo1.ics</" not in answer
- assert "href>/calendar.ics/todo2.ics</" in answer
- assert "href>/calendar.ics/todo3.ics</" in answer
- assert "href>/calendar.ics/todo4.ics</" not in answer
- assert "href>/calendar.ics/todo5.ics</" not in answer
- assert "href>/calendar.ics/todo6.ics</" not in answer
- assert "href>/calendar.ics/todo7.ics</" in answer
- assert "href>/calendar.ics/todo8.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130903T160000Z" end="20130901T183000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo2.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130903T160000Z" end="20130901T173000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo2.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130903T160000Z" end="20130903T173000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo3.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130903T160000Z" end="20130803T203000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=range(1, 9))
- assert "href>/calendar.ics/todo7.ics</" in answer
- def test_time_range_filter_todos_rrule(self):
- """Report request with time-range filter on todos with rrules."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20130801T000000Z" end="20131001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=(1, 2))
- assert "href>/calendar.ics/todo1.ics</" in answer
- assert "href>/calendar.ics/todo2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20140801T000000Z" end="20141001T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=(1, 2))
- assert "href>/calendar.ics/todo1.ics</" not in answer
- assert "href>/calendar.ics/todo2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20140902T000000Z" end="20140903T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=(1, 2))
- assert "href>/calendar.ics/todo1.ics</" not in answer
- assert "href>/calendar.ics/todo2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VTODO">
- <C:time-range start="20140904T000000Z" end="20140914T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "todo", items=(1, 2))
- assert "href>/calendar.ics/todo1.ics</" not in answer
- assert "href>/calendar.ics/todo2.ics</" not in answer
- def test_time_range_filter_journals(self):
- """Report request with time-range filter on journals."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="19991229T000000Z" end="20000202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2, 3))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- assert "href>/calendar.ics/journal3.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="19991229T000000Z" end="20000202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2, 3))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- assert "href>/calendar.ics/journal3.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="19981229T000000Z" end="19991012T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2, 3))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" not in answer
- assert "href>/calendar.ics/journal3.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="20131229T000000Z" end="21520202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2, 3))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- assert "href>/calendar.ics/journal3.ics</" not in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="20000101T000000Z" end="20000202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2, 3))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- assert "href>/calendar.ics/journal3.ics</" in answer
- def test_time_range_filter_journals_rrule(self):
- """Report request with time-range filter on journals with rrules."""
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="19991229T000000Z" end="20000202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="20051229T000000Z" end="20060202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" in answer
- answer = self._test_filter(["""
- <C:comp-filter name="VCALENDAR">
- <C:comp-filter name="VJOURNAL">
- <C:time-range start="20060102T000000Z" end="20060202T000000Z"/>
- </C:comp-filter>
- </C:comp-filter>"""], "journal", items=(1, 2))
- assert "href>/calendar.ics/journal1.ics</" not in answer
- assert "href>/calendar.ics/journal2.ics</" not in answer
- def test_report_item(self):
- """Test report request on an item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- status, _, answer = self.request(
- "REPORT", event_path,
- """<?xml version="1.0" encoding="utf-8" ?>
- <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
- <D:prop xmlns:D="DAV:">
- <D:getetag />
- </D:prop>
- </C:calendar-query>""")
- assert status == 207
- assert "href>%s<" % event_path in answer
- def _report_sync_token(self, calendar_path, sync_token=None):
- sync_token_xml = (
- "<sync-token><![CDATA[%s]]></sync-token>" % sync_token
- if sync_token else "<sync-token />")
- status, _, answer = self.request(
- "REPORT", calendar_path,
- """<?xml version="1.0" encoding="utf-8" ?>
- <sync-collection xmlns="DAV:">
- <prop>
- <getetag />
- </prop>
- %s
- </sync-collection>""" % sync_token_xml)
- if sync_token and status == 412:
- return None, None
- assert status == 207
- xml = ET.fromstring(answer)
- sync_token = xml.find("{DAV:}sync-token").text.strip()
- assert sync_token
- return sync_token, xml
- def test_report_sync_collection_no_change(self):
- """Test sync-collection report without modifying the collection"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- assert xml.find("{DAV:}response") is not None
- new_sync_token, xml = self._report_sync_token(calendar_path,
- sync_token)
- assert sync_token == new_sync_token
- assert xml.find("{DAV:}response") is None
- def test_report_sync_collection_add(self):
- """Test sync-collection report with an added item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- assert xml.find("{DAV:}response") is not None
- assert xml.find("{DAV:}response/{DAV:}status") is None
- def test_report_sync_collection_delete(self):
- """Test sync-collection report with a deleted item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- status, _, _ = self.request("DELETE", event_path)
- assert status == 200
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- assert "404" in xml.find("{DAV:}response/{DAV:}status").text
- def test_report_sync_collection_create_delete(self):
- """Test sync-collection report with a created and deleted item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- status, _, _ = self.request("DELETE", event_path)
- assert status == 200
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- assert "404" in xml.find("{DAV:}response/{DAV:}status").text
- def test_report_sync_collection_modify_undo(self):
- """Test sync-collection report with a modified and changed back item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event1 = get_file_content("event1.ics")
- event2 = get_file_content("event2.ics")
- event_path = posixpath.join(calendar_path, "event1.ics")
- status, _, _ = self.request("PUT", event_path, event1)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- status, _, _ = self.request("PUT", event_path, event2)
- assert status == 201
- status, _, _ = self.request("PUT", event_path, event1)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- assert xml.find("{DAV:}response") is not None
- assert xml.find("{DAV:}response/{DAV:}status") is None
- def test_report_sync_collection_move(self):
- """Test sync-collection report a moved item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event1_path = posixpath.join(calendar_path, "event1.ics")
- event2_path = posixpath.join(calendar_path, "event2.ics")
- status, _, _ = self.request("PUT", event1_path, event)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- status, _, _ = self.request(
- "MOVE", event1_path, HTTP_DESTINATION=event2_path, HTTP_HOST="")
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- for response in xml.findall("{DAV:}response"):
- if response.find("{DAV:}status") is None:
- assert response.find("{DAV:}href").text == event2_path
- else:
- assert "404" in response.find("{DAV:}status").text
- assert response.find("{DAV:}href").text == event1_path
- def test_report_sync_collection_move_undo(self):
- """Test sync-collection report with a moved and moved back item"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- event = get_file_content("event1.ics")
- event1_path = posixpath.join(calendar_path, "event1.ics")
- event2_path = posixpath.join(calendar_path, "event2.ics")
- status, _, _ = self.request("PUT", event1_path, event)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- status, _, _ = self.request(
- "MOVE", event1_path, HTTP_DESTINATION=event2_path, HTTP_HOST="")
- assert status == 201
- status, _, _ = self.request(
- "MOVE", event2_path, HTTP_DESTINATION=event1_path, HTTP_HOST="")
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path, sync_token)
- if not sync_token:
- pytest.skip("storage backend does not support sync-token")
- created = deleted = 0
- for response in xml.findall("{DAV:}response"):
- if response.find("{DAV:}status") is None:
- assert response.find("{DAV:}href").text == event1_path
- created += 1
- else:
- assert "404" in response.find("{DAV:}status").text
- assert response.find("{DAV:}href").text == event2_path
- deleted += 1
- assert created == 1 and deleted == 1
- def test_report_sync_collection_invalid_sync_token(self):
- """Test sync-collection report with an invalid sync token"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- sync_token, xml = self._report_sync_token(
- calendar_path, "http://radicale.org/ns/sync/INVALID")
- assert not sync_token
- def test_propfind_sync_token(self):
- """Retrieve the sync-token with a propfind request"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- event = get_file_content("event1.ics")
- event_path = posixpath.join(calendar_path, "event.ics")
- status, _, _ = self.request("PUT", event_path, event)
- assert status == 201
- new_sync_token, xml = self._report_sync_token(calendar_path,
- sync_token)
- assert sync_token != new_sync_token
- def test_propfind_same_as_sync_collection_sync_token(self):
- """Compare sync-token property with sync-collection sync-token"""
- calendar_path = "/calendar.ics/"
- status, _, _ = self.request("MKCALENDAR", calendar_path)
- assert status == 201
- sync_token, xml = self._report_sync_token(calendar_path)
- new_sync_token, xml = self._report_sync_token(calendar_path,
- sync_token)
- assert sync_token == new_sync_token
- def test_calendar_getcontenttype(self):
- """Test report request on an item"""
- status, _, _ = self.request("MKCALENDAR", "/test/")
- assert status == 201
- for component in ("event", "todo", "journal"):
- event = get_file_content("{}1.ics".format(component))
- status, _, _ = self.request("PUT", "/test/test.ics", event)
- assert status == 201
- status, _, answer = self.request(
- "REPORT", "/test/",
- """<?xml version="1.0" encoding="utf-8" ?>
- <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
- <D:prop xmlns:D="DAV:">
- <D:getcontenttype />
- </D:prop>
- </C:calendar-query>""")
- assert status == 207
- assert ">text/calendar;charset=utf-8;component=V{}<".format(
- component.upper()) in answer
- def test_addressbook_getcontenttype(self):
- """Test report request on an item"""
- status, _, _ = self._create_addressbook("/test/")
- assert status == 201
- contact = get_file_content("contact1.vcf")
- status, _, _ = self.request("PUT", "/test/test.vcf", contact)
- assert status == 201
- status, _, answer = self.request(
- "REPORT", "/test/",
- """<?xml version="1.0" encoding="utf-8" ?>
- <C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
- <D:prop xmlns:D="DAV:">
- <D:getcontenttype />
- </D:prop>
- </C:calendar-query>""")
- assert status == 207
- assert ">text/vcard;charset=utf-8<" in answer
- def test_authorization(self):
- authorization = "Basic " + base64.b64encode(b"user:").decode()
- status, _, answer = self.request(
- "PROPFIND", "/",
- """<?xml version="1.0" encoding="utf-8"?>
- <propfind xmlns="DAV:">
- <prop>
- <current-user-principal />
- </prop>
- </propfind>""",
- HTTP_AUTHORIZATION=authorization)
- assert status == 207
- assert "href>/user/<" in answer
- def test_authentication(self):
- """Test if server sends authentication request."""
- self.configuration["auth"]["type"] = "htpasswd"
- self.configuration["auth"]["htpasswd_filename"] = os.devnull
- self.configuration["auth"]["htpasswd_encryption"] = "plain"
- self.configuration["rights"]["type"] = "owner_only"
- self.application = Application(self.configuration, self.logger)
- status, headers, _ = self.request("MKCOL", "/user/")
- assert status in (401, 403)
- assert headers.get("WWW-Authenticate")
- def test_principal_collection_creation(self):
- """Verify existence of the principal collection."""
- status, _, _ = self.request("PROPFIND", "/user/", HTTP_AUTHORIZATION=(
- "Basic " + base64.b64encode(b"user:").decode()))
- assert status == 207
- def test_existence_of_root_collections(self):
- """Verify that the root collection always exists."""
- # Use PROPFIND because GET returns message
- status, _, _ = self.request("PROPFIND", "/")
- assert status == 207
- # it should still exist after deletion
- status, _, _ = self.request("DELETE", "/")
- assert status == 200
- status, _, _ = self.request("PROPFIND", "/")
- assert status == 207
- def test_custom_headers(self):
- if not self.configuration.has_section("headers"):
- self.configuration.add_section("headers")
- self.configuration.set("headers", "test", "123")
- # Test if header is set on success
- status, headers, _ = self.request("OPTIONS", "/")
- assert status == 200
- assert headers.get("test") == "123"
- # Test if header is set on failure
- status, headers, _ = self.request(
- "GET", "/.well-known/does not exist")
- assert status == 404
- assert headers.get("test") == "123"
- def test_timezone_seconds(self):
- """Verify that timezones with minutes and seconds work."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event_timezone_seconds.ics")
- status, _, _ = self.request("PUT", "/calendar.ics/event.ics", event)
- assert status == 201
- def test_missing_uid(self):
- """Verify that missing UIDs are added in a stable manner."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event_without_uid = get_file_content("event1.ics").replace(
- "UID:event1\n", "")
- assert "UID" not in event_without_uid
- path = "/calendar.ics/event1.ics"
- status, _, _ = self.request("PUT", path, event_without_uid)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- uid = None
- for line in answer.split("\r\n"):
- if line.startswith("UID:"):
- uid = line[len("UID:"):]
- assert uid
- status, _, _ = self.request("PUT", path, event_without_uid)
- assert status == 201
- status, _, answer = self.request("GET", path)
- assert status == 200
- assert "UID:%s\r\n" % uid in answer
- class BaseFileSystemTest(BaseTest):
- """Base class for filesystem backend tests."""
- storage_type = None
- def setup(self):
- self.configuration = config.load()
- self.configuration["storage"]["type"] = self.storage_type
- self.colpath = tempfile.mkdtemp()
- self.configuration["storage"]["filesystem_folder"] = self.colpath
- # Disable syncing to disk for better performance
- self.configuration["storage"]["filesystem_fsync"] = "False"
- # Required on Windows, doesn't matter on Unix
- self.configuration["storage"]["filesystem_close_lock_file"] = "True"
- self.application = Application(self.configuration, self.logger)
- def teardown(self):
- shutil.rmtree(self.colpath)
- class TestMultiFileSystem(BaseFileSystemTest, BaseRequestsMixIn):
- """Test BaseRequests on multifilesystem."""
- storage_type = "multifilesystem"
- def test_fsync(self):
- """Create a directory and file with syncing enabled."""
- self.configuration["storage"]["filesystem_fsync"] = "True"
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- def test_hook(self):
- """Run hook."""
- self.configuration["storage"]["hook"] = (
- "mkdir %s" % os.path.join("collection-root", "created_by_hook"))
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- status, _, _ = self.request("PROPFIND", "/created_by_hook/")
- assert status == 207
- def test_hook_read_access(self):
- """Verify that hook is not run for read accesses."""
- self.configuration["storage"]["hook"] = (
- "mkdir %s" % os.path.join("collection-root", "created_by_hook"))
- status, _, _ = self.request("PROPFIND", "/")
- assert status == 207
- status, _, _ = self.request("PROPFIND", "/created_by_hook/")
- assert status == 404
- @pytest.mark.skipif(os.system("type flock") != 0,
- reason="flock command not found")
- def test_hook_storage_locked(self):
- """Verify that the storage is locked when the hook runs."""
- self.configuration["storage"]["hook"] = (
- "flock -n .Radicale.lock || exit 0; exit 1")
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- def test_hook_principal_collection_creation(self):
- """Verify that the hooks runs when a new user is created."""
- self.configuration["storage"]["hook"] = (
- "mkdir %s" % os.path.join("collection-root", "created_by_hook"))
- status, _, _ = self.request("PROPFIND", "/", HTTP_AUTHORIZATION=(
- "Basic " + base64.b64encode(b"user:").decode()))
- assert status == 207
- status, _, _ = self.request("PROPFIND", "/created_by_hook/")
- assert status == 207
- def test_hook_fail(self):
- """Verify that a request fails if the hook fails."""
- self.configuration["storage"]["hook"] = "exit 1"
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status != 201
- def test_item_cache_rebuild(self):
- """Delete the item cache and verify that it is rebuild."""
- status, _, _ = self.request("MKCALENDAR", "/calendar.ics/")
- assert status == 201
- event = get_file_content("event1.ics")
- path = "/calendar.ics/event1.ics"
- status, _, _ = self.request("PUT", path, event)
- assert status == 201
- status, _, answer1 = self.request("GET", path)
- assert status == 200
- cache_folder = os.path.join(self.colpath, "collection-root",
- "calendar.ics", ".Radicale.cache", "item")
- assert os.path.exists(os.path.join(cache_folder, "event1.ics"))
- shutil.rmtree(cache_folder)
- status, _, answer2 = self.request("GET", path)
- assert status == 200
- assert answer1 == answer2
- assert os.path.exists(os.path.join(cache_folder, "event1.ics"))
- class TestCustomStorageSystem(BaseFileSystemTest):
- """Test custom backend loading."""
- storage_type = "tests.custom.storage"
- def test_root(self):
- """A simple test to verify that the custom backend works."""
- BaseRequestsMixIn.test_root(self)
|