Skip to content

Commit

Permalink
add unit test and documentation for custom HTTP headers (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yau authored and tobixen committed May 22, 2023
1 parent ae585d8 commit 34ad014
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/basic_usage_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
caldav_url = "https://calendar.example.com/dav"
username = "somebody"
password = "hunter2"
headers = {"X-MY-CUSTOMER-HEADER" : "123"}


def run_examples():
Expand All @@ -30,7 +31,10 @@ def run_examples():
## so the credentials aren't validated.
## The client object can be used as a context manager, like this:
with caldav.DAVClient(
url=caldav_url, username=username, password=password
url=caldav_url,
username=username,
password=password,
headers = headers # Optional parameter to set HTTP headers on each request if needed
) as client:

## Typically the next step is to fetch a principal object.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ def testRequestNonAscii(self, mocked):
assert response.status == 200
assert response.tree is None

@mock.patch("caldav.davclient.requests.Session.request")
def testRequestCustomHeaders(self, mocked):
"""
ref https://github.com/python-caldav/caldav/issues/285
"""
mocked().status_code = 200
mocked().headers = {}
cal_url = "http://me:hunter2@calendar.møøh.example:80/"
client = DAVClient(url=cal_url, headers={"X-NC-CalDAV-Webcal-Caching": "On"})
assert client.headers["Content-Type"] == "text/xml"
assert client.headers["X-NC-CalDAV-Webcal-Caching"] == "On"

@mock.patch("caldav.davclient.requests.Session.request")
def testEmptyXMLNoContentLength(self, mocked):
"""
Expand Down

0 comments on commit 34ad014

Please sign in to comment.