<!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 = &quot;data/Logs/state/directory-proxy.sock&quot;
</span><span class="cx">         if getattr(self, &quot;_connection&quot;, 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(&quot;utf-8&quot;),
-                shortName=shortName.encode(&quot;utf-8&quot;)
-            )
</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(&quot;utf-8&quot;),
+            shortName=shortName.encode(&quot;utf-8&quot;)
+        )
</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(&quot;utf-8&quot;)
+        )
</ins><span class="cx"> 
</span><del>-        def _call(ampProto):
-            return ampProto.callRemote(
-                RecordWithUIDCommand,
-                uid=uid.encode(&quot;utf-8&quot;)
-            )
</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(&quot;utf-8&quot;)
+        )
</ins><span class="cx"> 
</span><del>-        def _call(ampProto):
-            return ampProto.callRemote(
-                RecordWithGUIDCommand,
-                guid=guid.encode(&quot;utf-8&quot;)
-            )
</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(&quot;utf-8&quot;)
+        )
</ins><span class="cx"> 
</span><del>-        def _call(ampProto):
-            return ampProto.callRemote(
-                RecordsWithRecordTypeCommand,
-                recordType=recordType.description.encode(&quot;utf-8&quot;)
-            )
</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 == &quot;LDAP&quot;:
</span><span class="cx">             pass
</span><span class="cx">         elif directoryType == &quot;XML&quot;:
</span><del>-            directory = XMLDirectoryService(FilePath(&quot;foo.xml&quot;))
</del><ins>+            path = &quot;txdav/dps/test/test.xml&quot;
+            directory = XMLDirectoryService(FilePath(path))
</ins><span class="cx">         else:
</span><span class="cx">             log.error(&quot;Invalid DirectoryType: {dt}&quot;, 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 &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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>+&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+
+&lt;directory realm=&quot;xyzzy&quot;&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__wsanchez__&lt;/uid&gt;
+    &lt;short-name&gt;wsanchez&lt;/short-name&gt;
+    &lt;short-name&gt;wilfredo_sanchez&lt;/short-name&gt;
+    &lt;full-name&gt;Wilfredo Sanchez&lt;/full-name&gt;
+    &lt;password&gt;zehcnasw&lt;/password&gt;
+    &lt;email&gt;wsanchez@bitbucket.calendarserver.org&lt;/email&gt;
+    &lt;email&gt;wsanchez@devnull.twistedmatrix.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__glyph__&lt;/uid&gt;
+    &lt;short-name&gt;glyph&lt;/short-name&gt;
+    &lt;full-name&gt;Glyph Lefkowitz&lt;/full-name&gt;
+    &lt;password&gt;hpylg&lt;/password&gt;
+    &lt;email&gt;glyph@bitbucket.calendarserver.org&lt;/email&gt;
+    &lt;email&gt;glyph@devnull.twistedmatrix.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__sagen__&lt;/uid&gt;
+    &lt;short-name&gt;sagen&lt;/short-name&gt;
+    &lt;full-name&gt;Morgen Sagen&lt;/full-name&gt;
+    &lt;password&gt;negas&lt;/password&gt;
+    &lt;email&gt;sagen@bitbucket.calendarserver.org&lt;/email&gt;
+    &lt;email&gt;shared@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__cdaboo__&lt;/uid&gt;
+    &lt;short-name&gt;cdaboo&lt;/short-name&gt;
+    &lt;full-name&gt;Cyrus Daboo&lt;/full-name&gt;
+    &lt;password&gt;suryc&lt;/password&gt;
+    &lt;email&gt;cdaboo@bitbucket.calendarserver.org&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__dre__&lt;/uid&gt;
+    &lt;guid&gt;A3B1158F-0564-4F5B-81E4-A89EA5FF81B0&lt;/guid&gt;
+    &lt;short-name&gt;dre&lt;/short-name&gt;
+    &lt;full-name&gt;Andre LaBranche&lt;/full-name&gt;
+    &lt;password&gt;erd&lt;/password&gt;
+    &lt;email&gt;dre@bitbucket.calendarserver.org&lt;/email&gt;
+    &lt;email&gt;shared@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__exarkun__&lt;/uid&gt;
+    &lt;short-name&gt;exarkun&lt;/short-name&gt;
+    &lt;full-name&gt;Jean-Paul Calderone&lt;/full-name&gt;
+    &lt;password&gt;nucraxe&lt;/password&gt;
+    &lt;email&gt;exarkun@devnull.twistedmatrix.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;uid&gt;__dreid__&lt;/uid&gt;
+    &lt;short-name&gt;dreid&lt;/short-name&gt;
+    &lt;full-name&gt;David Reid&lt;/full-name&gt;
+    &lt;password&gt;dierd&lt;/password&gt;
+    &lt;email&gt;dreid@devnull.twistedmatrix.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record&gt; &lt;!-- type defaults to &quot;user&quot; --&gt;
+    &lt;uid&gt;__joe__&lt;/uid&gt;
+    &lt;short-name&gt;joe&lt;/short-name&gt;
+    &lt;full-name&gt;Joe Schmoe&lt;/full-name&gt;
+    &lt;password&gt;eoj&lt;/password&gt;
+    &lt;email&gt;joe@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record&gt; &lt;!-- type defaults to &quot;user&quot; --&gt;
+    &lt;uid&gt;__alyssa__&lt;/uid&gt;
+    &lt;short-name&gt;alyssa&lt;/short-name&gt;
+    &lt;full-name&gt;Alyssa P. Hacker&lt;/full-name&gt;
+    &lt;password&gt;assyla&lt;/password&gt;
+    &lt;email&gt;alyssa@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;uid&gt;__calendar-dev__&lt;/uid&gt;
+    &lt;short-name&gt;calendar-dev&lt;/short-name&gt;
+    &lt;full-name&gt;Calendar Server developers&lt;/full-name&gt;
+    &lt;email&gt;dev@bitbucket.calendarserver.org&lt;/email&gt;
+    &lt;member-uid&gt;__wsanchez__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__glyph__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__sagen__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__cdaboo__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__dre__&lt;/member-uid&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;uid&gt;__twisted__&lt;/uid&gt;
+    &lt;short-name&gt;twisted&lt;/short-name&gt;
+    &lt;full-name&gt;Twisted Matrix Laboratories&lt;/full-name&gt;
+    &lt;email&gt;hack@devnull.twistedmatrix.com&lt;/email&gt;
+    &lt;member-uid&gt;__wsanchez__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__glyph__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__exarkun__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__dreid__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__dre__&lt;/member-uid&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;uid&gt;__developers__&lt;/uid&gt;
+    &lt;short-name&gt;developers&lt;/short-name&gt;
+    &lt;full-name&gt;All Developers&lt;/full-name&gt;
+    &lt;member-uid&gt;__calendar-dev__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__twisted__&lt;/member-uid&gt;
+    &lt;member-uid&gt;__alyssa__&lt;/member-uid&gt;
+  &lt;/record&gt;
+
+&lt;/directory&gt;
</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 &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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__), &quot;test.xml&quot;)
+        remoteDirectory = XMLDirectoryService(FilePath(path))
+        client = AMP()
+        server = DirectoryProxyAMPProtocol(remoteDirectory)
+        pump = returnConnected(server, client)
+        self.directory = DirectoryService(None)
+
+        self.patch(self.directory, &quot;_getConnection&quot;, lambda: succeed(client))
+
+        origCall = self.directory._call
+
+        def newCall(*args, **kwds):
+            d = origCall(*args, **kwds)
+            pump.flush()
+            return d
+
+        self.patch(self.directory, &quot;_call&quot;, newCall)
+
+
+    @inlineCallbacks
+    def test_uid(self):
+        record = (yield self.directory.recordWithUID(&quot;__dre__&quot;))
+        self.assertEquals(record.shortNames, [u&quot;dre&quot;])
+
+
+    @inlineCallbacks
+    def test_shortName(self):
+        record = (yield self.directory.recordWithShortName(
+            RecordType.user,
+            &quot;wsanchez&quot;
+        ))
+        self.assertEquals(record.shortNames, [u'wsanchez', u'wilfredo_sanchez'])
+
+
+    @inlineCallbacks
+    def test_guid(self):
+        record = (yield self.directory.recordWithGUID(
+            &quot;A3B1158F-0564-4F5B-81E4-A89EA5FF81B0&quot;
+        ))
+        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(
+            &quot;cdaboo@bitbucket.calendarserver.org&quot;
+        ))
+        self.assertEquals(len(records), 1)
+        self.assertEquals(records[0].shortNames, [u&quot;cdaboo&quot;])
</ins></span></pre>
</div>
</div>

</body>
</html>