[CalendarServer-changes] [13294] twext/trunk/twext/who

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 15 18:00:56 PDT 2014


Revision: 13294
          http://trac.calendarserver.org//changeset/13294
Author:   wsanchez at apple.com
Date:     2014-04-15 18:00:56 -0700 (Tue, 15 Apr 2014)
Log Message:
-----------
Change repr(record) to prefer <Record (recordType)shortName> as before if it can look up a shortname, otherwise go with <Record uid>.

Modified Paths:
--------------
    twext/trunk/twext/who/directory.py
    twext/trunk/twext/who/ldap/test/test_util.py
    twext/trunk/twext/who/test/test_directory.py

Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py	2014-04-15 22:36:02 UTC (rev 13293)
+++ twext/trunk/twext/who/directory.py	2014-04-16 01:00:56 UTC (rev 13294)
@@ -417,13 +417,21 @@
 
 
     def __repr__(self):
-        return (
-            "<{self.__class__.__name__} ({recordType}){uid}>".format(
-                self=self,
-                recordType=describe(self.recordType),
-                uid=self.uid,
+        try:
+            return (
+                "<{self.__class__.__name__} ({recordType}){shortName}>".format(
+                    self=self,
+                    recordType=describe(self.recordType),
+                    shortName=self.shortNames[0],
+                )
             )
-        )
+        except (AttributeError, IndexError):
+            return (
+                "<{self.__class__.__name__} {uid}>".format(
+                    self=self,
+                    uid=self.uid,
+                )
+            )
 
 
     def __hash__(self):

Modified: twext/trunk/twext/who/ldap/test/test_util.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_util.py	2014-04-15 22:36:02 UTC (rev 13293)
+++ twext/trunk/twext/who/ldap/test/test_util.py	2014-04-16 01:00:56 UTC (rev 13294)
@@ -48,7 +48,7 @@
     """
 
     def service(self):
-        # Use intentionally funky conenction info, since we don't expect
+        # Use intentionally funky connection info, since we don't expect
         # to connect.
         return DirectoryService(
             u"ldap://cretin/", u"o=plugh",

Modified: twext/trunk/twext/who/test/test_directory.py
===================================================================
--- twext/trunk/twext/who/test/test_directory.py	2014-04-15 22:36:02 UTC (rev 13293)
+++ twext/trunk/twext/who/test/test_directory.py	2014-04-16 01:00:56 UTC (rev 13294)
@@ -295,12 +295,14 @@
         result = yield service.recordsFromExpression("twistedmatrix.com")
 
         self.assertEquals(
-            set((
-                u"__wsanchez__",
-                u"__glyph__",
-                u"__exarkun__",
-                u"__dreid__",
-            )),
+            set(
+                (
+                    u"__wsanchez__",
+                    u"__glyph__",
+                    u"__exarkun__",
+                    u"__dreid__",
+                )
+            ),
             set((record.uid for record in result))
         )
 
@@ -324,15 +326,17 @@
         )
 
         self.assertEquals(
-            set((
-                u"__wsanchez__",
-                u"__glyph__",
-                u"__sagen__",
-                u"__cdaboo__",
-                u"__dre__",
-                u"__exarkun__",
-                u"__dreid__",
-            )),
+            set(
+                (
+                    u"__wsanchez__",
+                    u"__glyph__",
+                    u"__sagen__",
+                    u"__cdaboo__",
+                    u"__dre__",
+                    u"__exarkun__",
+                    u"__dreid__",
+                )
+            ),
             set((record.uid for record in result))
         )
 
@@ -356,10 +360,12 @@
         )
 
         self.assertEquals(
-            set((
-                u"__wsanchez__",
-                u"__glyph__",
-            )),
+            set(
+                (
+                    u"__wsanchez__",
+                    u"__glyph__",
+                )
+            ),
             set((record.uid for record in result))
         )
 
@@ -588,6 +594,17 @@
         FieldName.shortNames: (u"nobody",),
     }
 
+    fields_no_shortnames = {
+        FieldName.uid: u"UID:no_shortnames",
+        FieldName.recordType: RecordType.user,
+    }
+
+    fields_empty_shortnames = {
+        FieldName.uid: u"UID:empty_shortnames",
+        FieldName.recordType: RecordType.user,
+        FieldName.shortNames: (),
+    }
+
     fields_none_password = {
         FieldName.uid: u"UID:nobody",
         FieldName.recordType: RecordType.user,
@@ -822,18 +839,42 @@
     )
 
 
-    def test_repr(self):
+    def test_reprWithShortName(self):
         """
-        L{DirectoryRecord.repr} returns the expected string.
+        L{DirectoryRecord.repr} returns a string using short name.
         """
         wsanchez = self.makeRecord(self.fields_wsanchez)
 
         self.assertEquals(
-            "<DirectoryRecord (user)UID:wsanchez>",
+            "<DirectoryRecord (user)wsanchez>",
             repr(wsanchez)
         )
 
 
+    def test_reprWithoutShortName(self):
+        """
+        L{DirectoryRecord.repr} returns a string using UID.
+        """
+        wsanchez = self.makeRecord(self.fields_no_shortnames)
+
+        self.assertEquals(
+            "<DirectoryRecord UID:no_shortnames>",
+            repr(wsanchez)
+        )
+
+
+    def test_reprEmptyShortName(self):
+        """
+        L{DirectoryRecord.repr} returns a string using UID.
+        """
+        wsanchez = self.makeRecord(self.fields_empty_shortnames)
+
+        self.assertEquals(
+            "<DirectoryRecord UID:empty_shortnames>",
+            repr(wsanchez)
+        )
+
+
     def test_compare(self):
         """
         Comparison of records.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140415/4d9eae21/attachment.html>


More information about the calendarserver-changes mailing list