[CalendarServer-changes] [8146] CalendarServer/branches/users/sagen/applepush/twistedcaldav/test/ test_applepush.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 5 10:38:45 PDT 2011
Revision: 8146
http://trac.macosforge.org/projects/calendarserver/changeset/8146
Author: sagen at apple.com
Date: 2011-10-05 10:38:43 -0700 (Wed, 05 Oct 2011)
Log Message:
-----------
More testing
Modified Paths:
--------------
CalendarServer/branches/users/sagen/applepush/twistedcaldav/test/test_applepush.py
Modified: CalendarServer/branches/users/sagen/applepush/twistedcaldav/test/test_applepush.py
===================================================================
--- CalendarServer/branches/users/sagen/applepush/twistedcaldav/test/test_applepush.py 2011-10-05 00:06:43 UTC (rev 8145)
+++ CalendarServer/branches/users/sagen/applepush/twistedcaldav/test/test_applepush.py 2011-10-05 17:38:43 UTC (rev 8146)
@@ -18,13 +18,14 @@
ApplePushNotifierService, APNProviderService
)
from twistedcaldav.test.util import TestCase
-from twisted.internet.defer import inlineCallbacks
+from twisted.internet.defer import inlineCallbacks, succeed
import struct
+import time
class ApplePushNotifierServiceTests(TestCase):
@inlineCallbacks
- def test_makeService(self):
+ def test_ApplePushNotifierService(self):
settings = {
"Service" : "twistedcaldav.applepush.ApplePushNotifierService",
@@ -46,32 +47,36 @@
"Topic" : "carddav_topic",
},
}
- service = (yield ApplePushNotifierService.makeService(settings, None))
+
+
+ # Add a subscription
+ store = StubStore()
+ txn = store.newTransaction()
+ token = "2d0d55cd7f98bcb81c6e24abcdc35168254c7846a43e2828b1ba5a8f82e219df"
+ key = "/CalDAV/calendars.example.com/user01/calendar/"
+ now = int(time.time())
+ guid = "D2256BCC-48E2-42D1-BD89-CBA1E4CCDFFB"
+ yield txn.addAPNSubscription(token, key, now, guid)
+
+ # Set up the service
+ service = (yield ApplePushNotifierService.makeService(settings, store,
+ testConnectorClass=TestConnector))
self.assertEquals(set(service.providers.keys()), set(["CalDAV","CardDAV"]))
self.assertEquals(set(service.feedbacks.keys()), set(["CalDAV","CardDAV"]))
-
-
- def test_provider(self):
- """
- Sending a notification writes to the transport
- """
- testConnector = TestConnector()
- service = APNProviderService("example.com", 1234, "caldav.cer",
- "caldav.pem", testConnector=testConnector)
service.startService()
- token = "b23b2d34 096f7f3c 7989970c 2d7a074f 50ebebfd 8702ed98 3657ada4 39432e23"
- key = "/CalDAV/user01/calendar"
- service.sendNotification(token, key)
+ # Notification arrives from calendar server
+ service.enqueue("update", "CalDAV|user01/calendar")
- # Verify data sent
- self.assertEquals(len(testConnector.transport.data), 80)
- data = struct.unpack("!BIIH32sH", testConnector.getData()[:45])
+ # Verify data sent to APN
+ rawData = service.providers["CalDAV"].testConnector.getData()
+ self.assertEquals(len(rawData), 103)
+ data = struct.unpack("!BIIH32sH", rawData[:45])
self.assertEquals(data[0], 1) # command
self.assertEquals(data[4].encode("hex"), token.replace(" ", "")) # token
payloadLength = data[5]
payload = struct.unpack("%ds" % (payloadLength,),
- testConnector.getData()[45:])
+ rawData[45:])
self.assertEquals(payload[0], '{"key" : "%s"}' % (key,))
@@ -94,3 +99,42 @@
def write(self, data):
self.data = data
+
+
+class StubStore(object):
+
+ def __init__(self):
+ self.subscriptions = []
+
+ def newTransaction(self):
+ return StubTransaction(self)
+
+
+class StubTransaction(object):
+
+ def __init__(self, store):
+ self.store = store
+
+ def apnSubscriptionsByKey(self, key):
+ matches = []
+ for subscription in self.store.subscriptions:
+ if subscription.key == key:
+ matches.append((subscription.token, subscription.guid))
+ return succeed(matches)
+
+ def addAPNSubscription(self, token, key, timestamp, guid):
+ subscription = Subscription(token, key, timestamp, guid)
+ self.store.subscriptions.append(subscription)
+ return succeed(None)
+
+ def commit(self):
+ pass
+
+
+class Subscription(object):
+
+ def __init__(self, token, key, timestamp, guid):
+ self.token = token
+ self.key = key
+ self.timestamp = timestamp
+ self.guid = guid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111005/4d9b1db0/attachment.html>
More information about the calendarserver-changes
mailing list