<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12575] CalendarServer/trunk/txdav/dps</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12575">12575</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-02-05 14:10:31 -0800 (Wed, 05 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Added DPS AMP test</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsclientpy">CalendarServer/trunk/txdav/dps/client.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsserverpy">CalendarServer/trunk/txdav/dps/server.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>CalendarServer/trunk/txdav/dps/test/</li>
<li><a href="#CalendarServertrunktxdavdpstest__init__py">CalendarServer/trunk/txdav/dps/test/__init__.py</a></li>
<li><a href="#CalendarServertrunktxdavdpstesttestxml">CalendarServer/trunk/txdav/dps/test/test.xml</a></li>
<li><a href="#CalendarServertrunktxdavdpstesttest_clientpy">CalendarServer/trunk/txdav/dps/test/test_client.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavdpsclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/client.py (12574 => 12575)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/client.py        2014-02-05 19:45:57 UTC (rev 12574)
+++ CalendarServer/trunk/txdav/dps/client.py        2014-02-05 22:10:31 UTC (rev 12575)
</span><span class="lines">@@ -14,27 +14,26 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx">
</span><del>-from twext.who.idirectory import RecordType
</del><ins>+import cPickle as pickle
+
</ins><span class="cx"> from twext.python.log import Logger
</span><del>-from twisted.internet import reactor
-from twext.who.directory import DirectoryService as BaseDirectoryService
</del><span class="cx"> from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
</span><del>-from twext.who.util import ConstantsContainer
</del><ins>+from twext.who.directory import DirectoryService as BaseDirectoryService
+from twext.who.idirectory import RecordType
</ins><span class="cx"> import twext.who.idirectory
</span><del>-import txdav.who.idirectory
-
-from zope.interface import implementer
-
</del><ins>+from twext.who.util import ConstantsContainer
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.protocol import ClientCreator
+from twisted.protocols import amp
</ins><span class="cx"> from txdav.dps.commands import (
</span><span class="cx"> RecordWithShortNameCommand, RecordWithUIDCommand,
</span><span class="cx"> RecordWithGUIDCommand, RecordsWithRecordTypeCommand,
</span><span class="cx"> RecordsWithEmailAddressCommand
</span><span class="cx"> )
</span><ins>+import txdav.who.idirectory
+from zope.interface import implementer
</ins><span class="cx">
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.internet.protocol import ClientCreator
-from twisted.protocols import amp
-import cPickle as pickle
</del><span class="cx">
</span><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="lines">@@ -93,6 +92,9 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _getConnection(self):
</span><ins>+ # TODO: make socket patch configurable
+ # TODO: reconnect if needed
+
</ins><span class="cx"> # path = config.DirectoryProxy.SocketPath
</span><span class="cx"> path = "data/Logs/state/directory-proxy.sock"
</span><span class="cx"> if getattr(self, "_connection", None) is None:
</span><span class="lines">@@ -104,77 +106,55 @@
</span><span class="cx"> returnValue(self._connection)
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordWithShortName(self, recordType, shortName):
</del><ins>+ @inlineCallbacks
+ def _call(self, command, postProcess, **kwds):
+ ampProto = (yield self._getConnection())
+ results = (yield ampProto.callRemote(command, **kwds))
+ returnValue(postProcess(results))
</ins><span class="cx">
</span><del>- def _call(ampProto):
- return ampProto.callRemote(
- RecordWithShortNameCommand,
- recordType=recordType.description.encode("utf-8"),
- shortName=shortName.encode("utf-8")
- )
</del><span class="cx">
</span><del>- d = self._getConnection()
- d.addCallback(_call)
- d.addCallback(self._processSingleRecord)
- return d
</del><ins>+ def recordWithShortName(self, recordType, shortName):
+ return self._call(
+ RecordWithShortNameCommand,
+ self._processSingleRecord,
+ recordType=recordType.description.encode("utf-8"),
+ shortName=shortName.encode("utf-8")
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordWithUID(self, uid):
</span><ins>+ return self._call(
+ RecordWithUIDCommand,
+ self._processSingleRecord,
+ uid=uid.encode("utf-8")
+ )
</ins><span class="cx">
</span><del>- def _call(ampProto):
- return ampProto.callRemote(
- RecordWithUIDCommand,
- uid=uid.encode("utf-8")
- )
</del><span class="cx">
</span><del>- d = self._getConnection()
- d.addCallback(_call)
- d.addCallback(self._processSingleRecord)
- return d
-
-
</del><span class="cx"> def recordWithGUID(self, guid):
</span><ins>+ return self._call(
+ RecordWithGUIDCommand,
+ self._processSingleRecord,
+ guid=guid.encode("utf-8")
+ )
</ins><span class="cx">
</span><del>- def _call(ampProto):
- return ampProto.callRemote(
- RecordWithGUIDCommand,
- guid=guid.encode("utf-8")
- )
</del><span class="cx">
</span><del>- d = self._getConnection()
- d.addCallback(_call)
- d.addCallback(self._processSingleRecord)
- return d
-
-
</del><span class="cx"> def recordsWithRecordType(self, recordType):
</span><ins>+ return self._call(
+ RecordsWithRecordTypeCommand,
+ self._processMultipleRecords,
+ recordType=recordType.description.encode("utf-8")
+ )
</ins><span class="cx">
</span><del>- def _call(ampProto):
- return ampProto.callRemote(
- RecordsWithRecordTypeCommand,
- recordType=recordType.description.encode("utf-8")
- )
</del><span class="cx">
</span><del>- d = self._getConnection()
- d.addCallback(_call)
- d.addCallback(self._processMultipleRecords)
- return d
-
-
</del><span class="cx"> def recordsWithEmailAddress(self, emailAddress):
</span><ins>+ return self._call(
+ RecordsWithEmailAddressCommand,
+ self._processMultipleRecords,
+ emailAddress=emailAddress
+ )
</ins><span class="cx">
</span><del>- def _call(ampProto):
- return ampProto.callRemote(
- RecordsWithEmailAddressCommand,
- emailAddress=emailAddress
- )
</del><span class="cx">
</span><del>- d = self._getConnection()
- d.addCallback(_call)
- d.addCallback(self._processMultipleRecords)
- return d
</del><span class="cx">
</span><del>-
</del><span class="cx"> class DirectoryRecord(BaseDirectoryRecord):
</span><span class="cx"> pass
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpsserverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/server.py (12574 => 12575)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/server.py        2014-02-05 19:45:57 UTC (rev 12574)
+++ CalendarServer/trunk/txdav/dps/server.py        2014-02-05 22:10:31 UTC (rev 12575)
</span><span class="lines">@@ -14,28 +14,29 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx">
</span><ins>+import cPickle as pickle
+import uuid
+
+from twext.python.log import Logger
</ins><span class="cx"> from twext.who.idirectory import RecordType
</span><ins>+from twext.who.opendirectory import DirectoryService as ODDirectoryService
+from twisted.application import service
+from twisted.application.strports import service as strPortsService
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.protocol import Factory
+from twisted.plugin import IPlugin
</ins><span class="cx"> from twisted.protocols import amp
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
-from twext.python.log import Logger
-import uuid
-import cPickle as pickle
</del><ins>+from twisted.python.filepath import FilePath
+from twisted.python.usage import Options, UsageError
+from twistedcaldav.config import config
+from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</ins><span class="cx"> from txdav.dps.commands import (
</span><span class="cx"> RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
</span><span class="cx"> RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
</span><span class="cx"> # UpdateRecordsCommand, RemoveRecordsCommand
</span><span class="cx"> )
</span><del>-from twisted.internet.protocol import Factory
-from twisted.python.usage import Options, UsageError
-from twistedcaldav.config import config
-from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</del><ins>+from txdav.who.xml import DirectoryService as XMLDirectoryService
</ins><span class="cx"> from zope.interface import implementer
</span><del>-from twisted.plugin import IPlugin
-from twisted.application import service
-from twext.who.opendirectory import DirectoryService as ODDirectoryService
-from txdav.who.xml import DirectoryService as XMLDirectoryService
-from twisted.python.filepath import FilePath
-from twisted.application.strports import service as strPortsService
</del><span class="cx">
</span><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="lines">@@ -285,7 +286,8 @@
</span><span class="cx"> elif directoryType == "LDAP":
</span><span class="cx"> pass
</span><span class="cx"> elif directoryType == "XML":
</span><del>- directory = XMLDirectoryService(FilePath("foo.xml"))
</del><ins>+ path = "txdav/dps/test/test.xml"
+ directory = XMLDirectoryService(FilePath(path))
</ins><span class="cx"> else:
</span><span class="cx"> log.error("Invalid DirectoryType: {dt}", dt=directoryType)
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpstest__init__py"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/test/__init__.py (0 => 12575)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/test/__init__.py         (rev 0)
+++ CalendarServer/trunk/txdav/dps/test/__init__.py        2014-02-05 22:10:31 UTC (rev 12575)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+##
+# Copyright (c) 2013-2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
</ins></span></pre></div>
<a id="CalendarServertrunktxdavdpstesttestxml"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/test/test.xml (0 => 12575)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/test/test.xml         (rev 0)
+++ CalendarServer/trunk/txdav/dps/test/test.xml        2014-02-05 22:10:31 UTC (rev 12575)
</span><span class="lines">@@ -0,0 +1,116 @@
</span><ins>+<?xml version="1.0" encoding="utf-8"?>
+
+<directory realm="xyzzy">
+
+ <record type="user">
+ <uid>__wsanchez__</uid>
+ <short-name>wsanchez</short-name>
+ <short-name>wilfredo_sanchez</short-name>
+ <full-name>Wilfredo Sanchez</full-name>
+ <password>zehcnasw</password>
+ <email>wsanchez@bitbucket.calendarserver.org</email>
+ <email>wsanchez@devnull.twistedmatrix.com</email>
+ </record>
+
+ <record type="user">
+ <uid>__glyph__</uid>
+ <short-name>glyph</short-name>
+ <full-name>Glyph Lefkowitz</full-name>
+ <password>hpylg</password>
+ <email>glyph@bitbucket.calendarserver.org</email>
+ <email>glyph@devnull.twistedmatrix.com</email>
+ </record>
+
+ <record type="user">
+ <uid>__sagen__</uid>
+ <short-name>sagen</short-name>
+ <full-name>Morgen Sagen</full-name>
+ <password>negas</password>
+ <email>sagen@bitbucket.calendarserver.org</email>
+ <email>shared@example.com</email>
+ </record>
+
+ <record type="user">
+ <uid>__cdaboo__</uid>
+ <short-name>cdaboo</short-name>
+ <full-name>Cyrus Daboo</full-name>
+ <password>suryc</password>
+ <email>cdaboo@bitbucket.calendarserver.org</email>
+ </record>
+
+ <record type="user">
+ <uid>__dre__</uid>
+ <guid>A3B1158F-0564-4F5B-81E4-A89EA5FF81B0</guid>
+ <short-name>dre</short-name>
+ <full-name>Andre LaBranche</full-name>
+ <password>erd</password>
+ <email>dre@bitbucket.calendarserver.org</email>
+ <email>shared@example.com</email>
+ </record>
+
+ <record type="user">
+ <uid>__exarkun__</uid>
+ <short-name>exarkun</short-name>
+ <full-name>Jean-Paul Calderone</full-name>
+ <password>nucraxe</password>
+ <email>exarkun@devnull.twistedmatrix.com</email>
+ </record>
+
+ <record type="user">
+ <uid>__dreid__</uid>
+ <short-name>dreid</short-name>
+ <full-name>David Reid</full-name>
+ <password>dierd</password>
+ <email>dreid@devnull.twistedmatrix.com</email>
+ </record>
+
+ <record> <!-- type defaults to "user" -->
+ <uid>__joe__</uid>
+ <short-name>joe</short-name>
+ <full-name>Joe Schmoe</full-name>
+ <password>eoj</password>
+ <email>joe@example.com</email>
+ </record>
+
+ <record> <!-- type defaults to "user" -->
+ <uid>__alyssa__</uid>
+ <short-name>alyssa</short-name>
+ <full-name>Alyssa P. Hacker</full-name>
+ <password>assyla</password>
+ <email>alyssa@example.com</email>
+ </record>
+
+ <record type="group">
+ <uid>__calendar-dev__</uid>
+ <short-name>calendar-dev</short-name>
+ <full-name>Calendar Server developers</full-name>
+ <email>dev@bitbucket.calendarserver.org</email>
+ <member-uid>__wsanchez__</member-uid>
+ <member-uid>__glyph__</member-uid>
+ <member-uid>__sagen__</member-uid>
+ <member-uid>__cdaboo__</member-uid>
+ <member-uid>__dre__</member-uid>
+ </record>
+
+ <record type="group">
+ <uid>__twisted__</uid>
+ <short-name>twisted</short-name>
+ <full-name>Twisted Matrix Laboratories</full-name>
+ <email>hack@devnull.twistedmatrix.com</email>
+ <member-uid>__wsanchez__</member-uid>
+ <member-uid>__glyph__</member-uid>
+ <member-uid>__exarkun__</member-uid>
+ <member-uid>__dreid__</member-uid>
+ <member-uid>__dre__</member-uid>
+ </record>
+
+ <record type="group">
+ <uid>__developers__</uid>
+ <short-name>developers</short-name>
+ <full-name>All Developers</full-name>
+ <member-uid>__calendar-dev__</member-uid>
+ <member-uid>__twisted__</member-uid>
+ <member-uid>__alyssa__</member-uid>
+ </record>
+
+</directory>
</ins></span></pre></div>
<a id="CalendarServertrunktxdavdpstesttest_clientpy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/test/test_client.py (0 => 12575)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/test/test_client.py         (rev 0)
+++ CalendarServer/trunk/txdav/dps/test/test_client.py        2014-02-05 22:10:31 UTC (rev 12575)
</span><span class="lines">@@ -0,0 +1,91 @@
</span><ins>+#
+# Copyright (c) 2013-2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import os
+
+from twext.who.idirectory import RecordType
+from twisted.internet.defer import inlineCallbacks, succeed
+from twisted.protocols.amp import AMP
+from twisted.python.filepath import FilePath
+from twisted.test.testutils import returnConnected
+from twisted.trial import unittest
+from txdav.dps.client import DirectoryService
+from txdav.dps.server import DirectoryProxyAMPProtocol
+from txdav.who.xml import DirectoryService as XMLDirectoryService
+
+
+
+
+class DPSClientTest(unittest.TestCase):
+
+ def setUp(self):
+ path = os.path.join(os.path.dirname(__file__), "test.xml")
+ remoteDirectory = XMLDirectoryService(FilePath(path))
+ client = AMP()
+ server = DirectoryProxyAMPProtocol(remoteDirectory)
+ pump = returnConnected(server, client)
+ self.directory = DirectoryService(None)
+
+ self.patch(self.directory, "_getConnection", lambda: succeed(client))
+
+ origCall = self.directory._call
+
+ def newCall(*args, **kwds):
+ d = origCall(*args, **kwds)
+ pump.flush()
+ return d
+
+ self.patch(self.directory, "_call", newCall)
+
+
+ @inlineCallbacks
+ def test_uid(self):
+ record = (yield self.directory.recordWithUID("__dre__"))
+ self.assertEquals(record.shortNames, [u"dre"])
+
+
+ @inlineCallbacks
+ def test_shortName(self):
+ record = (yield self.directory.recordWithShortName(
+ RecordType.user,
+ "wsanchez"
+ ))
+ self.assertEquals(record.shortNames, [u'wsanchez', u'wilfredo_sanchez'])
+
+
+ @inlineCallbacks
+ def test_guid(self):
+ record = (yield self.directory.recordWithGUID(
+ "A3B1158F-0564-4F5B-81E4-A89EA5FF81B0"
+ ))
+ self.assertEquals(record.shortNames, [u'dre'])
+
+
+ @inlineCallbacks
+ def test_recordType(self):
+ records = (yield self.directory.recordsWithRecordType(
+ RecordType.user
+ ))
+ self.assertEquals(len(records), 9)
+
+
+ @inlineCallbacks
+ def test_emailAddress(self):
+ records = (yield self.directory.recordsWithEmailAddress(
+ "cdaboo@bitbucket.calendarserver.org"
+ ))
+ self.assertEquals(len(records), 1)
+ self.assertEquals(records[0].shortNames, [u"cdaboo"])
</ins></span></pre>
</div>
</div>
</body>
</html>