mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-20 02:52:11 +00:00
test: start testing caldav
This commit is contained in:
parent
670c96b0b5
commit
de791511bf
@ -8,9 +8,9 @@ start-up a vagrant box
|
|||||||
|
|
||||||
vagrant up
|
vagrant up
|
||||||
|
|
||||||
install pytest
|
install test requirements
|
||||||
|
|
||||||
pip install pytest
|
pip install pytest caldav
|
||||||
|
|
||||||
run the tests
|
run the tests
|
||||||
|
|
||||||
|
5
test/common.py
Normal file
5
test/common.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
def random_id():
|
||||||
|
return uuid.uuid4().hex[:8]
|
66
test/test_caldav.py
Normal file
66
test/test_caldav.py
Normal file
@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
import uuid
|
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
@ -9,12 +8,13 @@ import smtplib
|
|||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
from settings import *
|
from settings import *
|
||||||
|
from common import random_id
|
||||||
|
|
||||||
|
|
||||||
def new_message(from_email, to_email):
|
def new_message(from_email, to_email):
|
||||||
"""Creates an email (headers & body) with a random subject"""
|
"""Creates an email (headers & body) with a random subject"""
|
||||||
msg = MIMEText('Testing')
|
msg = MIMEText('Testing')
|
||||||
msg['Subject'] = uuid.uuid4().hex[:8]
|
msg['Subject'] = random_id()
|
||||||
msg['From'] = from_email
|
msg['From'] = from_email
|
||||||
msg['To'] = to_email
|
msg['To'] = to_email
|
||||||
return msg.as_string(), msg['subject']
|
return msg.as_string(), msg['subject']
|
||||||
|
Loading…
Reference in New Issue
Block a user