Skip to content

Commit

Permalink
unit test for #103
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Jun 13, 2020
1 parent c07d70a commit 52abc3f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .proxy import ProxyHandler, NonThreadingHTTPServer
from . import compatibility_issues

from caldav.davclient import DAVClient
from caldav.davclient import DAVClient, DAVResponse
from caldav.objects import (Principal, Calendar, Event, DAVObject,
CalendarSet, FreeBusy, Todo)
from caldav.lib.url import URL
Expand Down Expand Up @@ -1231,6 +1231,37 @@ def testRequestNonAscii(self, mocked):
assert_equal(response.status, 200)
assert(response.tree is None)

def testAbsoluteURL(self):
"""Version 0.7.0 does not handle responses with absolute URLs very well, ref https://github.com/python-caldav/caldav/pull/103"""
## none of this should initiate any communication
client = DAVClient(url='http://cal.example.com/')
principal = Principal(client=client, url='http://cal.example.com/home/bernard/')
## now, ask for the calendar_home_set, but first we need to mock up client.propfind
mocked_response = mock.MagicMock()
mocked_response.status_code = 207
mocked_response.reason = 'multistatus'
mocked_response.headers = {}
mocked_response.content = """
<xml>
<d:multistatus xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:response>
<d:href>http://cal.example.com/home/bernard/</d:href>
<d:propstat>
<d:prop>
<c:calendar-home-set>
<d:href>http://cal.example.com/home/bernard/calendars/</d:href>
</c:calendar-home-set>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>
</xml>"""
mocked_davresponse = DAVResponse(mocked_response)
client.propfind = mock.MagicMock(return_value=mocked_davresponse)
bernards_calendars = principal.calendar_home_set
assert_equal(bernards_calendars.url, URL('http://cal.example.com/home/bernard/calendars/'))

def testCalendar(self):
"""
Principal.calendar() and CalendarSet.calendar() should create
Expand Down

0 comments on commit 52abc3f

Please sign in to comment.