From de791511bfecf54943b5a9af271c5f08df4ce8e0 Mon Sep 17 00:00:00 2001 From: Wolfgang Steitz Date: Thu, 15 Dec 2016 23:50:08 +0100 Subject: [PATCH] test: start testing caldav --- test/README.md | 4 +-- test/common.py | 5 ++++ test/test_caldav.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ test/test_mail.py | 4 +-- 4 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 test/common.py create mode 100644 test/test_caldav.py diff --git a/test/README.md b/test/README.md index 6b1ee05a..170702ed 100644 --- a/test/README.md +++ b/test/README.md @@ -8,9 +8,9 @@ start-up a vagrant box vagrant up -install pytest +install test requirements - pip install pytest + pip install pytest caldav run the tests diff --git a/test/common.py b/test/common.py new file mode 100644 index 00000000..8c20a435 --- /dev/null +++ b/test/common.py @@ -0,0 +1,5 @@ +import uuid + + +def random_id(): + return uuid.uuid4().hex[:8] diff --git a/test/test_caldav.py b/test/test_caldav.py new file mode 100644 index 00000000..32594e11 --- /dev/null +++ b/test/test_caldav.py @@ -0,0 +1,66 @@ +import pytest +import caldav +from time import sleep + +from settings import * +from common import random_id + + +def connect(): + url = "https://" + TEST_DOMAIN + "/cloud/remote.php/dav/calendars/me@mailinabox.lan/personal/" + client = caldav.DAVClient(url, username=TEST_ADDRESS, password=TEST_PASSWORD, ssl_verify_cert=False) + principal = client.principal() + calendars = principal.calendars() + return client, calendars[0] + + +vcal = """BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Example Corp.//CalDAV Client//EN +BEGIN:VEVENT +UID:{} +DTSTAMP:20170510T182145Z +DTSTART:20170512T170000Z +DTEND:20170512T180000Z +SUMMARY: this is a sample event +END:VEVENT +END:VCALENDAR +""" + + +def create_event(): + uid = random_id() + event = vcal.format(uid) + return event, uid + + +def event_exists(uid): + c, cal = connect() + try: + event = cal.event(uid) + return True + except caldav.lib.error.NotFoundError: + return False + + +def test_addremove_event(): + c, cal = connect() + event, uid = create_event() + cal.add_event(event) + assert event_exists(uid) + + # now delete the event again + event = cal.event(uid) + event.delete() + sleep(3) + assert (not event_exists(uid)) + + +#def test_addremove_calendar(): +# c, cal = connect() +# cal_id = random_id() +# #c.principal().make_calendar(name="test", cal_id=cal_id) +# cal = caldav.Calendar(c, name="TEST", parent=c.principal(), id="12").save() + + + diff --git a/test/test_mail.py b/test/test_mail.py index 32fe0ad2..f4926561 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -1,5 +1,4 @@ from time import sleep -import uuid import requests import os import pytest @@ -9,12 +8,13 @@ import smtplib from email.mime.text import MIMEText from settings import * +from common import random_id def new_message(from_email, to_email): """Creates an email (headers & body) with a random subject""" msg = MIMEText('Testing') - msg['Subject'] = uuid.uuid4().hex[:8] + msg['Subject'] = random_id() msg['From'] = from_email msg['To'] = to_email return msg.as_string(), msg['subject']