[CalendarServer-changes] [10570] CalendarServer/branches/users/glyph/unshare-when-access-revoked
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jan 28 19:28:50 PST 2013
Revision: 10570
http://trac.calendarserver.org//changeset/10570
Author: glyph at apple.com
Date: 2013-01-28 19:28:50 -0800 (Mon, 28 Jan 2013)
Log Message:
-----------
Re-indent XML to avoid un-indented blocks; compare it as XML rather than text when the test calls for it.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/unshare-when-access-revoked/twistedcaldav/test/test_sharing.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/unshare-when-access-revoked/
Modified: CalendarServer/branches/users/glyph/unshare-when-access-revoked/twistedcaldav/test/test_sharing.py
===================================================================
--- CalendarServer/branches/users/glyph/unshare-when-access-revoked/twistedcaldav/test/test_sharing.py 2013-01-29 03:28:48 UTC (rev 10569)
+++ CalendarServer/branches/users/glyph/unshare-when-access-revoked/twistedcaldav/test/test_sharing.py 2013-01-29 03:28:50 UTC (rev 10570)
@@ -14,11 +14,13 @@
# limitations under the License.
##
+
from zope.interface import implements
-from twext.web2 import responsecode
from txdav.xml import element as davxml
+from txdav.xml.parser import WebDAVDocument
+from twext.web2 import responsecode
from twext.web2.http_headers import MimeType
from twext.web2.iweb import IResource
from twext.web2.stream import MemoryStream
@@ -39,6 +41,15 @@
+def normalize(x):
+ """
+ Normalize some XML by parsing it, collapsing whitespace, and
+ pretty-printing.
+ """
+ return WebDAVDocument.fromString(x).toxml()
+
+
+
class StubCollection(object):
def __init__(self):
@@ -300,14 +311,14 @@
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -330,15 +341,14 @@
def test_POSTaddInviteeNotAlreadyShared(self):
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-"""
- )
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -364,27 +374,27 @@
self.assertFalse(isShared)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
isShared = (yield self.resource.isShared(None))
self.assertTrue(isShared)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read/>
+ </CS:set>
+ </CS:share>
+ """)
isShared = (yield self.resource.isShared(None))
self.assertTrue(isShared)
@@ -408,25 +418,25 @@
self.assertFalse(isShared)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
isShared = (yield self.resource.isShared(None))
self.assertTrue(isShared)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user02 at example.com</D:href>
- </CS:remove>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user02 at example.com</D:href>
+ </CS:remove>
+ </CS:share>
+ """)
isShared = (yield self.resource.isShared(None))
self.assertFalse(isShared)
@@ -441,28 +451,28 @@
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user03 at example.com</D:href>
- <CS:summary>Your Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
- <CS:set>
- <D:href>mailto:user04 at example.com</D:href>
- <CS:summary>Your Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user03 at example.com</D:href>
+ <CS:summary>Your Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ <CS:set>
+ <D:href>mailto:user04 at example.com</D:href>
+ <CS:summary>Your Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -496,31 +506,31 @@
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
- <CS:set>
- <D:href>mailto:user03 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ <CS:set>
+ <D:href>mailto:user03 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user03 at example.com</D:href>
- </CS:remove>
- <CS:set>
- <D:href>mailto:user04 at example.com</D:href>
- <CS:summary>Your Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user03 at example.com</D:href>
+ </CS:remove>
+ <CS:set>
+ <D:href>mailto:user04 at example.com</D:href>
+ <CS:summary>Your Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -546,31 +556,31 @@
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
- <CS:set>
- <D:href>mailto:user03 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ <CS:set>
+ <D:href>mailto:user03 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user03 at example.com</D:href>
- </CS:remove>
- <CS:set>
- <D:href>mailto:user03 at example.com</D:href>
- <CS:summary>Your Shared Calendar</CS:summary>
- <CS:read/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user03 at example.com</D:href>
+ </CS:remove>
+ <CS:set>
+ <D:href>mailto:user03 at example.com</D:href>
+ <CS:summary>Your Shared Calendar</CS:summary>
+ <CS:read/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -602,36 +612,36 @@
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user02 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
- <CS:set>
- <D:href>mailto:user03 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user02 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ <CS:set>
+ <D:href>mailto:user03 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user03 at example.com</D:href>
- </CS:remove>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user03 at example.com</D:href>
+ </CS:remove>
+ </CS:share>
+ """)
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user02 at example.com</D:href>
- </CS:remove>
- <CS:remove>
- <D:href>mailto:user03 at example.com</D:href>
- </CS:remove>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user02 at example.com</D:href>
+ </CS:remove>
+ <CS:remove>
+ <D:href>mailto:user03 at example.com</D:href>
+ </CS:remove>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(propInvite, None)
@@ -641,46 +651,53 @@
def test_POSTaddInvalidInvitee(self):
self.resource.upgradeToShare()
- response = (yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:bogus at example.net</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""",
+ response = (yield self._doPOST(
+ """<?xml version="1.0" encoding="utf-8" ?>
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:bogus at example.net</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """,
responsecode.MULTI_STATUS
))
- self.assertEqual(
+ self.assertXMLEquals(
str(response.stream.read()).replace("\r\n", "\n"),
"""<?xml version='1.0' encoding='UTF-8'?>
-<multistatus xmlns='DAV:'>
- <response>
- <href>mailto:bogus at example.net</href>
- <status>HTTP/1.1 403 Forbidden</status>
- </response>
-</multistatus>"""
+ <multistatus xmlns='DAV:'>
+ <response>
+ <href>mailto:bogus at example.net</href>
+ <status>HTTP/1.1 403 Forbidden</status>
+ </response>
+ </multistatus>"""
)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
-
self.assertEquals(propInvite, None)
+ def assertXMLEquals(self, a, b):
+ """
+ Assert two strings are equivalent as XML.
+ """
+ self.assertEquals(normalize(a), normalize(b))
+
+
@inlineCallbacks
def test_POSTremoveInvalidInvitee(self):
self.resource.upgradeToShare()
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:set>
- <D:href>mailto:user01 at example.com</D:href>
- <CS:summary>My Shared Calendar</CS:summary>
- <CS:read-write/>
- </CS:set>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:set>
+ <D:href>mailto:user01 at example.com</D:href>
+ <CS:summary>My Shared Calendar</CS:summary>
+ <CS:read-write/>
+ </CS:set>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(self._clearUIDElementValue(propInvite), customxml.Invite(
@@ -709,12 +726,12 @@
))
yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?>
-<CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
- <CS:remove>
- <D:href>mailto:user01 at example.com</D:href>
- </CS:remove>
-</CS:share>
-""")
+ <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+ <CS:remove>
+ <D:href>mailto:user01 at example.com</D:href>
+ </CS:remove>
+ </CS:share>
+ """)
propInvite = (yield self.resource.readProperty(customxml.Invite, None))
self.assertEquals(propInvite, None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130128/7e83d162/attachment-0001.html>
More information about the calendarserver-changes
mailing list