[CalendarServer-changes] [12283] twext/trunk/twext

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:23:54 PDT 2014


Revision: 12283
          http://trac.calendarserver.org//changeset/12283
Author:   wsanchez at apple.com
Date:     2014-01-10 09:56:24 -0800 (Fri, 10 Jan 2014)
Log Message:
-----------
More tests

Modified Paths:
--------------
    twext/trunk/twext/application/masterchild.py
    twext/trunk/twext/who/ldap/test/test_util.py

Modified: twext/trunk/twext/application/masterchild.py
===================================================================
--- twext/trunk/twext/application/masterchild.py	2014-01-10 17:22:01 UTC (rev 12282)
+++ twext/trunk/twext/application/masterchild.py	2014-01-10 17:56:24 UTC (rev 12283)
@@ -635,16 +635,16 @@
 
 
 class ReportingProtocolWrapper(ProtocolWrapper, object):
-    # def __init__(self, *args, **kwargs):
-    #     try:
-    #         raise RuntimeError()
-    #     except RuntimeError:
-    #         from twisted.python.failure import Failure
-    #         f = Failure()
-    #         f.printTraceback()
-    #     return super(ReportingProtocolWrapper, self).__init__(
-    #         *args, **kwargs
-    #     )
+    def __init__(self, *args, **kwargs):
+        try:
+            raise RuntimeError()
+        except RuntimeError:
+            from twisted.python.failure import Failure
+            f = Failure()
+            f.printTraceback()
+        return super(ReportingProtocolWrapper, self).__init__(
+            *args, **kwargs
+        )
 
 
     def connectionLost(self, reason):

Modified: twext/trunk/twext/who/ldap/test/test_util.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_util.py	2014-01-10 17:22:01 UTC (rev 12282)
+++ twext/trunk/twext/who/ldap/test/test_util.py	2014-01-10 17:56:24 UTC (rev 12283)
@@ -26,6 +26,8 @@
 from .._service import DirectoryService
 from .._util import (
     ldapQueryStringFromMatchExpression,
+    ldapQueryStringFromCompoundExpression,
+    ldapQueryStringFromExpression,
 )
 
 
@@ -69,12 +71,10 @@
             queryString = ldapQueryStringFromMatchExpression(
                 expression, self.attrMap(service)
             )
-            self.assertEquals(
-                queryString,
-                u"({attribute}{expected})".format(
-                    attribute="shortNames", expected=expected
-                )
+            expected = u"({attribute}{expected})".format(
+                attribute="shortNames", expected=expected
             )
+            self.assertEquals(queryString, expected)
 
 
     def test_queryStringFromMatchExpression_match_not(self):
@@ -90,12 +90,10 @@
         queryString = ldapQueryStringFromMatchExpression(
             expression, self.attrMap(service)
         )
-        self.assertEquals(
-            queryString,
-            u"(!{attribute}=xyzzy)".format(
-                attribute="shortNames",
-            )
+        expected = u"(!{attribute}=xyzzy)".format(
+            attribute="shortNames",
         )
+        self.assertEquals(queryString, expected)
 
 
     def test_queryStringFromMatchExpression_match_caseInsensitive(self):
@@ -112,13 +110,12 @@
         queryString = ldapQueryStringFromMatchExpression(
             expression, self.attrMap(service)
         )
-        self.assertEquals(
-            queryString,
-            u"???????({attribute}=xyzzy)".format(
-                attribute="shortNames",
-            )
+        expected = u"???????({attribute}=xyzzy)".format(
+            attribute="shortNames",
         )
+        self.assertEquals(queryString, expected)
 
+
     test_queryStringFromMatchExpression_match_caseInsensitive.todo = (
         "unimplemented"
     )
@@ -137,83 +134,112 @@
         queryString = ldapQueryStringFromMatchExpression(
             expression, self.attrMap(service)
         )
-        self.assertEquals(
-            queryString,
-            u"({attribute}={expected})".format(
-                attribute="fullNames",
-                expected=(
-                    u"\\5Cxyzzy: a\\2Fb\\2F\\28c\\29\\2A "
-                    "\\7E\\7E \\3E\\3D\\3C \\7E\\7E \\26\\7C \\00!!"
+        expected= u"({attribute}={expected})".format(
+            attribute="fullNames",
+            expected=(
+                u"\\5Cxyzzy: a\\2Fb\\2F\\28c\\29\\2A "
+                "\\7E\\7E \\3E\\3D\\3C \\7E\\7E \\26\\7C \\00!!"
+            )
+        )
+        self.assertEquals(queryString, expected)
+
+
+    def test_queryStringFromCompoundExpression_single(self):
+        """
+        Compound expression with a single sub-expression.
+
+        Should result in the same query string as just the sub-expression
+        would.
+
+        The Operand shouldn't make any difference here, so we test AND and OR,
+        expecting the same result.
+        """
+        service = DirectoryService()
+
+        for operand in (Operand.AND, Operand.OR):
+            matchExpression = MatchExpression(
+                service.fieldName.shortNames, u"xyzzy"
+            )
+            compoundExpression = CompoundExpression(
+                [matchExpression],
+                operand
+            )
+            queryString = ldapQueryStringFromCompoundExpression(
+                compoundExpression, self.attrMap(service)
+            )
+            expected = u"{match}".format(
+                match=ldapQueryStringFromMatchExpression(
+                    matchExpression, self.attrMap(service)
                 )
             )
+            self.assertEquals(queryString, expected)
+
+
+    def test_queryStringFromCompoundExpression_multiple(self):
+        """
+        Compound expression with multiple sub-expressions.
+
+        The sub-expressions should be grouped with the given operand.
+        """
+        service = DirectoryService()
+
+        for (operand, token) in ((Operand.AND, u"&"), (Operand.OR, u"|")):
+            matchExpression1 = MatchExpression(
+                service.fieldName.shortNames, u"xyzzy"
+            )
+            matchExpression2 = MatchExpression(
+                service.fieldName.shortNames, u"plugh"
+            )
+            compoundExpression = CompoundExpression(
+                [matchExpression1, matchExpression2],
+                operand
+            )
+            queryString = ldapQueryStringFromCompoundExpression(
+                compoundExpression, self.attrMap(service)
+            )
+            expected = u"({op}{match1}{match2})".format(
+                op=token,
+                match1=ldapQueryStringFromMatchExpression(
+                    matchExpression1, self.attrMap(service)
+                ),
+                match2=ldapQueryStringFromMatchExpression(
+                    matchExpression2, self.attrMap(service)
+                ),
+            )
+            self.assertEquals(queryString, expected)
+
+
+    def test_queryStringFromExpression_match(self):
+        """
+        Match expression.
+        """
+        service = DirectoryService()
+
+        matchExpression = MatchExpression(
+            service.fieldName.shortNames, u"xyzzy"
         )
+        queryString = ldapQueryStringFromExpression(
+            matchExpression, self.attrMap(service)
+        )
+        expected = ldapQueryStringFromMatchExpression(
+            matchExpression, self.attrMap(service)
+        )
+        self.assertEquals(queryString, expected)
 
 
-    # def test_queryStringFromExpression(self):
-    #     service = DirectoryService()
+    def test_queryStringFromExpression_compound(self):
+        """
+        Compound expression.
+        """
+        raise NotImplementedError()
 
-    #     # CompoundExpressions
+    test_queryStringFromExpression_compound.todo = "unimplemented"
 
-    #     expression = CompoundExpression(
-    #         [
-    #             MatchExpression(
-    #                 service.fieldName.uid, u"a",
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.guid, u"b",
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.shortNames, u"c",
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.emailAddresses, u"d",
-    #                 matchType=MatchType.startsWith
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.fullNames, u"e",
-    #                 matchType=MatchType.equals
-    #             ),
-    #         ],
-    #         Operand.AND
-    #     )
-    #     queryString = service._queryStringFromExpression(expression)
-    #     self.assertEquals(
-    #         queryString,
-    #         (
-    #             u"(&(dsAttrTypeStandard:GeneratedUID=*a*)"
-    #             u"(dsAttrTypeStandard:GeneratedUID=*b*)"
-    #             u"(dsAttrTypeStandard:RecordName=*c*)"
-    #             u"(dsAttrTypeStandard:EMailAddress=d*)"
-    #             u"(dsAttrTypeStandard:RealName=e))"
-    #         )
-    #     )
 
-    #     expression = CompoundExpression(
-    #         [
-    #             MatchExpression(
-    #                 service.fieldName.shortNames, u"a",
-    #                 matchType=MatchType.contains
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.emailAddresses, u"b",
-    #                 matchType=MatchType.startsWith
-    #             ),
-    #             MatchExpression(
-    #                 service.fieldName.fullNames, u"c",
-    #                 matchType=MatchType.equals
-    #             ),
-    #         ],
-    #         Operand.OR
-    #     )
-    #     queryString = service._queryStringFromExpression(expression)
-    #     self.assertEquals(
-    #         queryString,
-    #         (
-    #             u"(|(dsAttrTypeStandard:RecordName=*a*)"
-    #             u"(dsAttrTypeStandard:EMailAddress=b*)"
-    #             u"(dsAttrTypeStandard:RealName=c))"
-    #         )
-    #     )
+    def test_queryStringFromExpression_unknown(self):
+        """
+        Unknown expression.
+        """
+        raise NotImplementedError()
+
+    test_queryStringFromExpression_unknown.todo = "unimplemented"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/10347dec/attachment.html>


More information about the calendarserver-changes mailing list