Monotone-Parent: d4ae79e2dc00eec1dd763ab6509e41b4ec5a709a

Monotone-Revision: a17c467b0c0d4f1aa961b8c26c0c1bc8b4eaea0a

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-01-18T11:27:11
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2010-01-18 11:27:11 +00:00
parent 3bd64092ae
commit ef3cb1dae0
4 changed files with 121 additions and 98 deletions

View File

@@ -1,5 +1,8 @@
2010-01-18 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Tests/utilities.py: new module implementing utility classes and
methods that are used in different test cases.
* Main/sogod.m (main): set the "GNUSTEP_STRING_ENCODING"
environment variable to NSUTF8StringEncoding to properly decode
the user defaults strings in UTF8.

View File

@@ -7,6 +7,8 @@ import unittest
import webdavlib
import time
import utilities
# TODO:
# - cal: complete test for "modify": "respond to" causes a 204 but no actual
# modification should occur
@@ -19,27 +21,15 @@ import time
# originally
# - test "current-user-acl-set"
def fetchUserEmail(login):
client = webdavlib.WebDAVClient(hostname, port,
username, password)
resource = '/SOGo/dav/%s/' % login
propfind = webdavlib.WebDAVPROPFIND(resource,
["{urn:ietf:params:xml:ns:caldav}calendar-user-address-set"],
0)
propfind.xpath_namespace = { "D": "DAV:",
"C": "urn:ietf:params:xml:ns:caldav" }
client.execute(propfind)
nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/C:calendar-user-address-set/D:href',
None)
return nodes[0].childNodes[0].nodeValue
class DAVAclTest(unittest.TestCase):
resource = None
def setUp(self):
def __init__(self, arg):
self.client = webdavlib.WebDAVClient(hostname, port,
username, password)
unittest.TestCase.__init__(self, arg)
def setUp(self):
delete = webdavlib.WebDAVDELETE(self.resource)
self.client.execute(delete)
mkcol = webdavlib.WebDAVMKCOL(self.resource)
@@ -55,22 +45,6 @@ class DAVAclTest(unittest.TestCase):
delete = webdavlib.WebDAVDELETE(self.resource)
self.client.execute(delete)
def rightsToSOGoRights(self, rights):
self.fail("subclass must implement this method")
def setupRights(self, rights):
rights_str = "".join(["<%s/>" % x for x in self.rightsToSOGoRights(rights) ])
aclQuery = """<acl-query xmlns="urn:inverse:params:xml:ns:inverse-dav">
<set-roles user="%s">%s</set-roles>
</acl-query>""" % (subscriber_username, rights_str)
post = webdavlib.HTTPPOST(self.resource, aclQuery)
post.content_type = "application/xml"
self.client.execute(post)
self.assertEquals(post.response["status"], 204,
"rights modification: failure to set '%s' (status: %d)"
% (rights_str, post.response["status"]))
def _versitLine(self, line):
key, value = line.split(":")
semicolon = key.find(";")
@@ -122,10 +96,14 @@ class DAVCalendarAclTest(DAVAclTest):
resource = '/SOGo/dav/%s/Calendar/test-dav-acl/' % username
user_email = None
def __init__(self, arg):
DAVAclTest.__init__(self, arg)
self.acl_utility = utilities.TestCalendarACLUtility(self.client,
self.resource)
def setUp(self):
if self.user_email is None:
self.user_email = fetchUserEmail(username)
DAVAclTest.setUp(self)
self.user_email = self.acl_utility.fetchUserInfo(username)[0]
self.classToICSClass = { "pu": "PUBLIC",
"pr": "PRIVATE",
"co": "CONFIDENTIAL" }
@@ -197,35 +175,13 @@ class DAVCalendarAclTest(DAVAclTest):
% (filename, exp_status, delete.response["status"]))
def _testRights(self, rights):
self.setupRights(rights)
self.acl_utility.setupRights(subscriber_username, rights)
self._testCreate(rights)
self._testEventRight("pu", rights)
self._testEventRight("pr", rights)
self._testEventRight("co", rights)
self._testDelete(rights)
def rightsToSOGoRights(self, rights):
sogoRights = []
if rights.has_key("c") and rights["c"]:
sogoRights.append("ObjectCreator")
if rights.has_key("d") and rights["d"]:
sogoRights.append("ObjectEraser")
classes = { "pu": "Public",
"pr": "Private",
"co": "Confidential" }
rights_table = { "v": "Viewer",
"d": "DAndTViewer",
"m": "Modifier",
"r": "Responder" }
for k in classes.keys():
if rights.has_key(k):
right = rights[k]
sogo_right = "%s%s" % (classes[k], rights_table[right])
sogoRights.append(sogo_right)
return sogoRights
def _testCreate(self, rights):
if rights.has_key("c") and rights["c"]:
exp_code = 201
@@ -448,7 +404,7 @@ class DAVCalendarAclTest(DAVAclTest):
event = self._getEvent(event_class, True).replace("\r", "")
self.assertEquals(exp_event.strip(), event.strip(),
"'respond to' event does not match:\nreceived:\n"
"%s\nexpected:\n%s" % (event, exp_event))
"/%s/\nexpected:\n/%s/" % (event, exp_event))
# Addressbook:
# short rights notation: { "c": create,
@@ -571,6 +527,11 @@ NOTE:Remarque
X-AIM:pseudo aim
END:VCARD""" }
def __init__(self, arg):
DAVAclTest.__init__(self, arg)
self.acl_utility = utilities.TestAddressBookACLUtility(self.client,
self.resource)
def setUp(self):
DAVAclTest.setUp(self)
self._putCard(self.client, "old.vcf", 201)
@@ -616,20 +577,8 @@ END:VCARD""" }
self._testRights({ "d": True,
"e": True })
def rightsToSOGoRights(self, rights):
sogoRightsTable = { "c": "ObjectCreator",
"d": "ObjectEraser",
"v": "ObjectViewer",
"e": "ObjectEditor" }
sogoRights = []
for k in rights.keys():
sogoRights.append(sogoRightsTable[k])
return sogoRights
def _testRights(self, rights):
self.setupRights(rights)
self.acl_utility.setupRights(subscriber_username, rights)
self._testCreate(rights)
self._testView(rights)
self._testEdit(rights)

View File

@@ -3,36 +3,24 @@
from config import hostname, port, username, password
import unittest
import utilities
import webdavlib
def fetchUserInfo(login):
client = webdavlib.WebDAVClient(hostname, port, username, password)
resource = "/SOGo/dav/%s/" % login
propfind = webdavlib.WebDAVPROPFIND(resource,
["displayname",
"{urn:ietf:params:xml:ns:caldav}calendar-user-address-set"],
0)
propfind.xpath_namespace = { "D": "DAV:",
"C": "urn:ietf:params:xml:ns:caldav" }
client.execute(propfind)
assert(propfind.response["status"] == 207)
name_nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/D:displayname',
None)
email_nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/C:calendar-user-address-set/D:href',
None)
return (name_nodes[0].childNodes[0].nodeValue, email_nodes[0].childNodes[0].nodeValue)
class WebDAVTest(unittest.TestCase):
def __init__(self, arg):
unittest.TestCase.__init__(self, arg)
self.client = webdavlib.WebDAVClient(hostname, port,
username, password)
self.dav_utility = utilities.TestUtility(self.client)
def testPrincipalCollectionSet(self):
"""property: 'principal-collection-set' on collection object"""
client = webdavlib.WebDAVClient(hostname, port, username, password)
resource = '/SOGo/dav/%s/' % username
propfind = webdavlib.WebDAVPROPFIND(resource,
["{DAV:}principal-collection-set"],
0)
propfind.xpath_namespace = { "D": "DAV:" }
client.execute(propfind)
self.client.execute(propfind)
self.assertEquals(propfind.response["status"], 207)
nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/D:principal-collection-set/D:href',
None)
@@ -48,13 +36,12 @@ class WebDAVTest(unittest.TestCase):
def testPrincipalCollectionSet2(self):
"""property: 'principal-collection-set' on non-collection object"""
client = webdavlib.WebDAVClient(hostname, port, username, password)
resource = '/SOGo/dav/%s/freebusy.ifb' % username
propfind = webdavlib.WebDAVPROPFIND(resource,
["{DAV:}principal-collection-set"],
0)
propfind.xpath_namespace = { "D": "DAV:" }
client.execute(propfind)
self.client.execute(propfind)
self.assertEquals(propfind.response["status"], 207)
nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/D:principal-collection-set/D:href',
None)
@@ -71,12 +58,11 @@ class WebDAVTest(unittest.TestCase):
def _testPropfindURL(self, resource):
resourceWithSlash = resource[-1] == '/'
client = webdavlib.WebDAVClient(hostname, port, username, password)
propfind = webdavlib.WebDAVPROPFIND(resource,
["{DAV:}displayname", "{DAV:}resourcetype"],
1)
propfind.xpath_namespace = { "D": "DAV:" }
client.execute(propfind)
self.client.execute(propfind)
self.assertEquals(propfind.response["status"], 207)
nodes = propfind.xpath_evaluate('/D:multistatus/D:response',
@@ -110,9 +96,8 @@ class WebDAVTest(unittest.TestCase):
# http://tools.ietf.org/html/rfc3253.html#section-3.8
def testExpandProperty(self):
"""expand-property"""
client = webdavlib.WebDAVClient(hostname, port, username, password)
resource = '/SOGo/dav/%s/' % username
userInfo = fetchUserInfo(username)
userInfo = self.dav_utility.fetchUserInfo(username)
query_props = {"owner": { "href": resource,
"displayname": userInfo[0]},
@@ -120,7 +105,7 @@ class WebDAVTest(unittest.TestCase):
"displayname": "SOGo"}}
query = webdavlib.WebDAVExpandProperty(resource, query_props.keys(),
["displayname"])
client.execute(query)
self.client.execute(query)
self.assertEquals(query.response["status"], 207)
topResponse = query.xpath_evaluate('/D:multistatus/D:response')[0]

86
Tests/utilities.py Normal file
View File

@@ -0,0 +1,86 @@
#!/usr/bin/python
import unittest
import webdavlib
class TestUtility(unittest.TestCase):
def __init__(self, client):
self.client = client
self.userInfo = {}
def fetchUserInfo(self, login):
if not self.userInfo.has_key(login):
resource = "/SOGo/dav/%s/" % login
propfind = webdavlib.WebDAVPROPFIND(resource,
["displayname",
"{urn:ietf:params:xml:ns:caldav}calendar-user-address-set"],
0)
propfind.xpath_namespace = { "D": "DAV:",
"C": "urn:ietf:params:xml:ns:caldav" }
self.client.execute(propfind)
assert(propfind.response["status"] == 207)
name_nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/D:displayname',
None)
email_nodes = propfind.xpath_evaluate('/D:multistatus/D:response/D:propstat/D:prop/C:calendar-user-address-set/D:href',
None)
self.userInfo[login] = (name_nodes[0].childNodes[0].nodeValue,
email_nodes[0].childNodes[0].nodeValue)
return self.userInfo[login]
class TestACLUtility(TestUtility):
def __init__(self, client, resource):
TestUtility.__init__(self, client)
self.resource = resource
def rightsToSOGoRights(self, rights):
self.fail("subclass must implement this method")
def setupRights(self, username, rights):
rights_str = "".join(["<%s/>" % x for x in self.rightsToSOGoRights(rights) ])
aclQuery = """<acl-query xmlns="urn:inverse:params:xml:ns:inverse-dav">
<set-roles user="%s">%s</set-roles>
</acl-query>""" % (username, rights_str)
post = webdavlib.HTTPPOST(self.resource, aclQuery)
post.content_type = "application/xml"
self.client.execute(post)
self.assertEquals(post.response["status"], 204,
"rights modification: failure to set '%s' (status: %d)"
% (rights_str, post.response["status"]))
class TestCalendarACLUtility(TestACLUtility):
def rightsToSOGoRights(self, rights):
sogoRights = []
if rights.has_key("c") and rights["c"]:
sogoRights.append("ObjectCreator")
if rights.has_key("d") and rights["d"]:
sogoRights.append("ObjectEraser")
classes = { "pu": "Public",
"pr": "Private",
"co": "Confidential" }
rights_table = { "v": "Viewer",
"d": "DAndTViewer",
"m": "Modifier",
"r": "Responder" }
for k in classes.keys():
if rights.has_key(k):
right = rights[k]
sogo_right = "%s%s" % (classes[k], rights_table[right])
sogoRights.append(sogo_right)
return sogoRights
class TestAddressBookACLUtility(TestACLUtility):
def rightsToSOGoRights(self, rights):
sogoRightsTable = { "c": "ObjectCreator",
"d": "ObjectEraser",
"v": "ObjectViewer",
"e": "ObjectEditor" }
sogoRights = []
for k in rights.keys():
sogoRights.append(sogoRightsTable[k])
return sogoRights