[CalendarServer-changes] [7631] CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 20 12:38:05 PDT 2011


Revision: 7631
          http://trac.macosforge.org/projects/calendarserver/changeset/7631
Author:   glyph at apple.com
Date:     2011-06-20 12:38:04 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
test for writeSequence / getPeer / getHost to round out ITransport compatibility.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py
    CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/util.py

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py	2011-06-20 19:23:23 UTC (rev 7630)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py	2011-06-20 19:38:04 UTC (rev 7631)
@@ -1608,6 +1608,24 @@
 
 
     @inlineCallbacks
+    def test_quotaTransportAddress(self):
+        """
+        Since L{IAttachmentStorageTransport} is a subinterface of L{ITransport},
+        it must provide peer and host addresses.
+        """
+        obj = yield self.calendarObjectUnderTest()
+        name = 'a-fun-attachment'
+        attachment = yield obj.createAttachmentWithName(name)
+        transport = attachment.store(MimeType("test", "x-something"))
+        peer = transport.getPeer()
+        host = transport.getHost()
+        self.assertIdentical(peer.attachment, attachment)
+        self.assertIdentical(host.attachment, attachment)
+        self.assertIn(name, repr(peer))
+        self.assertIn(name, repr(host))
+
+
+    @inlineCallbacks
     def exceedQuotaTest(self, getit):
         """
         If too many bytes are passed to the transport returned by
@@ -1619,9 +1637,10 @@
         attachment = yield getit() 
         t = attachment.store(MimeType("text", "x-fixture"))
         sample = "all work and no play makes jack a dull boy"
+        chunk = (sample * (home.quotaAllowedBytes() / len(sample)))
 
-        t.write(sample * (2 + (home.quotaAllowedBytes() /
-                               len(sample))))
+        t.write(chunk)
+        t.writeSequence([chunk, chunk])
 
         d = t.loseConnection()
         yield self.failUnlessFailure(d, QuotaExceeded)

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/util.py	2011-06-20 19:23:23 UTC (rev 7630)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/util.py	2011-06-20 19:38:04 UTC (rev 7631)
@@ -262,6 +262,36 @@
 
 
 
+class StorageTransportAddress(object):
+    """
+    Peer / host address for L{IAttachmentStorageTransport} implementations.
+
+    @ivar attachment: the L{IAttachment} being stored.
+
+    @type attachment: L{IAttachment} provider
+
+    @ivar isHost: is this a host address or peer address?
+
+    @type isHost: C{bool}
+    """
+
+    def __init__(self, attachment, isHost):
+        """
+        Initialize with the attachment being stored.
+        """
+        self.attachment = attachment
+        self.isHost = isHost
+
+
+    def __repr__(self):
+        if self.isHost:
+            host = " (host)"
+        else:
+            host = ""
+        return '<Storing Attachment: %r%s>' % (self.attachment.name(), host)
+
+
+
 class StorageTransportBase(object):
     """
     Base logic shared between file- and sql-based L{IAttachmentStorageTransport}
@@ -280,17 +310,14 @@
 
 
     def getPeer(self):
-        raise NotImplementedError()
-        return 'Storing attachment <%r>' % (self.attachment._path,)
+        return StorageTransportAddress(self._attachment, False)
 
 
     def getHost(self):
-        raise NotImplementedError()
-        return 'Storing attachment (host) <%r>' % (self.attachment._path,)
+        return StorageTransportAddress(self._attachment, True)
 
 
     def writeSequence(self, seq):
-        raise NotImplementedError()
         return self.write(''.join(seq))
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/b87b2e64/attachment-0001.html>


More information about the calendarserver-changes mailing list