<!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>[11922] CalendarServer/trunk/twext/who/test/test_directory.py</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/11922">11922</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2013-11-08 15:55:15 -0800 (Fri, 08 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Updates to immutable services that are no-ops are allowed.
More docs.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwextwhotesttest_directorypy">CalendarServer/trunk/twext/who/test/test_directory.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwextwhotesttest_directorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twext/who/test/test_directory.py (11921 => 11922)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twext/who/test/test_directory.py        2013-11-08 23:22:22 UTC (rev 11921)
+++ CalendarServer/trunk/twext/who/test/test_directory.py        2013-11-08 23:55:15 UTC (rev 11922)
</span><span class="lines">@@ -185,7 +185,25 @@
</span><span class="cx">     test_recordsWithEmailAddress = _unimplemented
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_updateRecordsEmpty(self):
+        &quot;&quot;&quot;
+        Updating no records is not an error.
+        &quot;&quot;&quot;
+        service = self.service()
+        for create in (True, False):
+            service.updateRecords((), create=create),
</ins><span class="cx"> 
</span><ins>+
+    def test_removeRecordsEmpty(self):
+        &quot;&quot;&quot;
+        Removing no records is allowed.
+        &quot;&quot;&quot;
+        service = self.service()
+
+        service.removeRecords(())
+
+
+
</ins><span class="cx"> class DirectoryServiceTest(unittest.TestCase, BaseDirectoryServiceTest):
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_recordsFromExpression_single(self):
</span><span class="lines">@@ -318,7 +336,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_recordWithUID(self):
</span><ins>+        &quot;&quot;&quot;
+        C{recordWithUID} fails with L{QueryNotSupportedError}.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><ins>+
</ins><span class="cx">         self.assertFailure(
</span><span class="cx">             service.recordWithUID(u&quot;&quot;),
</span><span class="cx">             QueryNotSupportedError
</span><span class="lines">@@ -326,7 +348,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_recordWithGUID(self):
</span><ins>+        &quot;&quot;&quot;
+        C{recordWithGUID} fails with L{QueryNotSupportedError}.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><ins>+
</ins><span class="cx">         self.assertFailure(
</span><span class="cx">             service.recordWithGUID(UUID(int=0)),
</span><span class="cx">             QueryNotSupportedError
</span><span class="lines">@@ -334,7 +360,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_recordsWithRecordType(self):
</span><ins>+        &quot;&quot;&quot;
+        C{recordsWithRecordType} fails with L{QueryNotSupportedError}.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><ins>+
</ins><span class="cx">         for recordType in RecordType.iterconstants():
</span><span class="cx">             self.assertFailure(
</span><span class="cx">                 service.recordsWithRecordType(recordType),
</span><span class="lines">@@ -343,7 +373,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_recordWithShortName(self):
</span><ins>+        &quot;&quot;&quot;
+        C{recordWithShortName} fails with L{QueryNotSupportedError}.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><ins>+
</ins><span class="cx">         for recordType in RecordType.iterconstants():
</span><span class="cx">             self.assertFailure(
</span><span class="cx">                 service.recordWithShortName(recordType, u&quot;&quot;),
</span><span class="lines">@@ -352,7 +386,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_recordsWithEmailAddress(self):
</span><ins>+        &quot;&quot;&quot;
+        C{recordsWithEmailAddress} fails with L{QueryNotSupportedError}.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><ins>+
</ins><span class="cx">         self.assertFailure(
</span><span class="cx">             service.recordsWithEmailAddress(&quot;a@b&quot;),
</span><span class="cx">             QueryNotSupportedError
</span><span class="lines">@@ -361,7 +399,14 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class BaseDirectoryServiceImmutableTest(ServiceMixIn):
</span><ins>+    &quot;&quot;&quot;
+    Immutable directory record tests.
+    &quot;&quot;&quot;
+
</ins><span class="cx">     def test_updateRecordsNotAllowed(self):
</span><ins>+        &quot;&quot;&quot;
+        Updating records is not allowed.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><span class="cx"> 
</span><span class="cx">         newRecord = DirectoryRecord(
</span><span class="lines">@@ -373,21 +418,19 @@
</span><span class="cx">             }
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        self.assertFailure(
-            service.updateRecords((newRecord,), create=True),
-            NotAllowedError,
-        )
</del><ins>+        for create in (True, False):
+            self.assertFailure(
+                service.updateRecords((newRecord,), create=create),
+                NotAllowedError,
+            )
</ins><span class="cx"> 
</span><del>-        self.assertFailure(
-            service.updateRecords((newRecord,), create=False),
-            NotAllowedError,
-        )
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def test_removeRecordsNotAllowed(self):
</span><ins>+        &quot;&quot;&quot;
+        Removing records is not allowed.
+        &quot;&quot;&quot;
</ins><span class="cx">         service = self.service()
</span><span class="cx"> 
</span><del>-        service.removeRecords(())
</del><span class="cx">         self.assertFailure(
</span><span class="cx">             service.removeRecords((u&quot;foo&quot;,)),
</span><span class="cx">             NotAllowedError,
</span><span class="lines">@@ -444,6 +487,18 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def makeRecord(self, fields=None, service=None):
</span><ins>+        &quot;&quot;&quot;
+        Create a directory record from fields and a service.
+
+        @param fields: Record fields.
+        @type fields: L{dict} with L{FieldName} keys
+
+        @param service: Directory service.
+        @type service: L{DirectoryService}
+
+        @return: A directory record.
+        @rtype: L{DirectoryRecord}
+        &quot;&quot;&quot;
</ins><span class="cx">         if fields is None:
</span><span class="cx">             fields = self.fields_wsanchez
</span><span class="cx">         if service is None:
</span><span class="lines">@@ -452,6 +507,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_interface(self):
</span><ins>+        &quot;&quot;&quot;
+        L{DirectoryRecord} complies with L{IDirectoryRecord}.
+        &quot;&quot;&quot;
</ins><span class="cx">         record = self.makeRecord()
</span><span class="cx">         try:
</span><span class="cx">             verifyObject(IDirectoryRecord, record)
</span><span class="lines">@@ -460,6 +518,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_init(self):
</span><ins>+        &quot;&quot;&quot;
+        L{DirectoryRecord} initialization sets service and fields.
+        &quot;&quot;&quot;
</ins><span class="cx">         service  = self.service()
</span><span class="cx">         wsanchez = self.makeRecord(self.fields_wsanchez, service=service)
</span><span class="cx"> 
</span><span class="lines">@@ -468,6 +529,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_initWithNoUID(self):
</span><ins>+        &quot;&quot;&quot;
+        Directory records must have a UID.
+        &quot;&quot;&quot;
</ins><span class="cx">         fields = self.fields_wsanchez.copy()
</span><span class="cx">         del fields[FieldName.uid]
</span><span class="cx">         self.assertRaises(ValueError, self.makeRecord, fields)
</span><span class="lines">@@ -478,6 +542,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_initWithNoRecordType(self):
</span><ins>+        &quot;&quot;&quot;
+        Directory records must have a record type.
+        &quot;&quot;&quot;
</ins><span class="cx">         fields = self.fields_wsanchez.copy()
</span><span class="cx">         del fields[FieldName.recordType]
</span><span class="cx">         self.assertRaises(ValueError, self.makeRecord, fields)
</span><span class="lines">@@ -487,7 +554,19 @@
</span><span class="cx">         self.assertRaises(ValueError, self.makeRecord, fields)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def test_initWithBogusRecordType(self):
+        &quot;&quot;&quot;
+        Directory records must have a known record type.
+        &quot;&quot;&quot;
+        fields = self.fields_wsanchez.copy()
+        fields[FieldName.recordType] = object()
+        self.assertRaises(ValueError, self.makeRecord, fields)
+
+
</ins><span class="cx">     def test_initWithNoShortNames(self):
</span><ins>+        &quot;&quot;&quot;
+        Directory records must have a short name.
+        &quot;&quot;&quot;
</ins><span class="cx">         fields = self.fields_wsanchez.copy()
</span><span class="cx">         del fields[FieldName.shortNames]
</span><span class="cx">         self.assertRaises(ValueError, self.makeRecord, fields)
</span><span class="lines">@@ -505,13 +584,10 @@
</span><span class="cx">         self.assertRaises(ValueError, self.makeRecord, fields)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def test_initWithBogusRecordType(self):
-        fields = self.fields_wsanchez.copy()
-        fields[FieldName.recordType] = object()
-        self.assertRaises(ValueError, self.makeRecord, fields)
-
-
-    def test_initNormalize(self):
</del><ins>+    def test_initNormalizeEmailLowercase(self):
+        &quot;&quot;&quot;
+        Email addresses are normalized to lowercase.
+        &quot;&quot;&quot;
</ins><span class="cx">         sagen = self.makeRecord(self.fields_sagen)
</span><span class="cx"> 
</span><span class="cx">         self.assertEquals(
</span><span class="lines">@@ -521,6 +597,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_compare(self):
</span><ins>+        &quot;&quot;&quot;
+        Comparison of records.
+        &quot;&quot;&quot;
</ins><span class="cx">         fields_glyphmod = self.fields_glyph.copy()
</span><span class="cx">         del fields_glyphmod[FieldName.emailAddresses]
</span><span class="cx"> 
</span><span class="lines">@@ -539,6 +618,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_attributeAccess(self):
</span><ins>+        &quot;&quot;&quot;
+        Fields can be accessed as attributes.
+        &quot;&quot;&quot;
</ins><span class="cx">         wsanchez = self.makeRecord(self.fields_wsanchez)
</span><span class="cx"> 
</span><span class="cx">         self.assertEquals(
</span><span class="lines">@@ -560,23 +642,34 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def test_members(self):
</del><ins>+    def test_members_group(self):
+        &quot;&quot;&quot;
+        Group members.
+        &quot;&quot;&quot;
+        raise SkipTest(&quot;Subclasses should implement this test.&quot;)
+
+
+    def test_members_nonGroup(self):
+        &quot;&quot;&quot;
+        Non-groups have no members.
+        &quot;&quot;&quot;
</ins><span class="cx">         wsanchez = self.makeRecord(self.fields_wsanchez)
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             set((yield wsanchez.members())),
</span><span class="cx">             set()
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        raise SkipTest(&quot;Subclasses should implement this test.&quot;)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def test_groups(self):
</span><ins>+        &quot;&quot;&quot;
+        Group memberships.
+        &quot;&quot;&quot;
</ins><span class="cx">         raise SkipTest(&quot;Subclasses should implement this test.&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryRecordTest(unittest.TestCase, BaseDirectoryRecordTest):
</span><del>-    def test_members(self):
</del><ins>+    def test_members_group(self):
</ins><span class="cx">         wsanchez = self.makeRecord(self.fields_wsanchez)
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             set((yield wsanchez.members())),
</span><span class="lines">@@ -594,6 +687,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class StubDirectoryService(DirectoryService):
</span><ins>+    &quot;&quot;&quot;
+    Stubn directory service with some built-in records and an implementation
+    of C{recordsFromNonCompoundExpression}.
+    &quot;&quot;&quot;
+
</ins><span class="cx">     def __init__(self):
</span><span class="cx">         DirectoryService.__init__(self, u&quot;Stub&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -602,6 +700,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _addRecords(self):
</span><ins>+        &quot;&quot;&quot;
+        Add a known set of records to this service.
+        &quot;&quot;&quot;
</ins><span class="cx">         self._addUser(
</span><span class="cx">             shortNames=[u&quot;wsanchez&quot;, u&quot;wilfredo_sanchez&quot;],
</span><span class="cx">             fullNames=[u&quot;Wilfredo S\xe1nchez Vega&quot;],
</span><span class="lines">@@ -680,6 +781,18 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _addUser(self, shortNames, fullNames, emailAddresses=[]):
</span><ins>+        &quot;&quot;&quot;
+        Add a user record with the given field information.
+
+        @param shortNames: Record short names.
+        @type shortNames: L{list} of L{unicode}s
+
+        @param fullNames: Record full names.
+        @type fullNames: L{list} of L{unicode}s
+
+        @param emailAddresses: Record email addresses.
+        @type emailAddresses: L{list} of L{unicode}s
+        &quot;&quot;&quot;
</ins><span class="cx">         self.records.append(DirectoryRecord(self, {
</span><span class="cx">             self.fieldName.recordType: self.recordType.user,
</span><span class="cx">             self.fieldName.uid: u&quot;__{0}__&quot;.format(shortNames[0]),
</span></span></pre>
</div>
</div>

</body>
</html>