From 1194f07ed3ae90128be35646793d5dd628092964 Mon Sep 17 00:00:00 2001 From: Wolfgang Steitz Date: Sun, 18 Dec 2016 19:19:00 +0100 Subject: [PATCH] tests: basic carddav tests --- test/README.md | 2 +- test/test_caldav.py | 2 +- test/test_carddav.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/test_carddav.py diff --git a/test/README.md b/test/README.md index 170702ed..8e962020 100644 --- a/test/README.md +++ b/test/README.md @@ -10,7 +10,7 @@ start-up a vagrant box install test requirements - pip install pytest caldav + pip install pytest caldav pycarddav run the tests diff --git a/test/test_caldav.py b/test/test_caldav.py index 32594e11..bea4e698 100644 --- a/test/test_caldav.py +++ b/test/test_caldav.py @@ -7,7 +7,7 @@ from common import random_id def connect(): - url = "https://" + TEST_DOMAIN + "/cloud/remote.php/dav/calendars/me@mailinabox.lan/personal/" + url = "https://" + TEST_DOMAIN + "/cloud/remote.php/dav/calendars/" + TEST_ADDRESS + "/personal/" client = caldav.DAVClient(url, username=TEST_ADDRESS, password=TEST_PASSWORD, ssl_verify_cert=False) principal = client.principal() calendars = principal.calendars() diff --git a/test/test_carddav.py b/test/test_carddav.py new file mode 100644 index 00000000..a19b1435 --- /dev/null +++ b/test/test_carddav.py @@ -0,0 +1,50 @@ +import pytest +from pycarddav import carddav +from time import sleep + +from settings import * +from common import random_id + + +test_vcf = """ +BEGIN:VCARD +VERSION:3.0 +EMAIL;TYPE=PREF:foo@example.com +N:John Doe;;;; +FN:John Doe +REV:2012-08-02T21:16:14+00:00 +PRODID:-//ownCloud//NONSGML Contacts 0.2//EN +UID:c292c7212b +END:VCARD +""" + +def connect(): + url = "https://" + TEST_DOMAIN + "/cloud/remote.php/carddav/addressbooks/" + TEST_ADDRESS + "/contacts/" + return carddav.PyCardDAV(url, user=TEST_ADDRESS, passwd=TEST_PASSWORD, verify=False, write_support=True) + + +def test_adddelete_contact(): + c = connect() + abook = c.get_abook() + prev_len = len(abook) + + url, etag = c.upload_new_card(test_vcf) + abook = c.get_abook() + assert len(abook) == prev_len + 1 + + c.delete_vcard(url, etag) + abook = c.get_abook() + assert len(abook) == prev_len + + +def test_update_contact(): + c = connect() + url, etag = c.upload_new_card(test_vcf) + + card = c.get_vcard(url) + new_card = card.replace("John Doe", "Jane Doe") + c.update_vcard(new_card, url, etag) + + card = c.get_vcard(url) + assert "John Doe" not in card + assert "Jane Doe" in card