[CalendarServer-changes] [13615] CalendarServer/trunk/contrib/od

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 6 14:07:05 PDT 2014


Revision: 13615
          http://trac.calendarserver.org//changeset/13615
Author:   sagen at apple.com
Date:     2014-06-06 14:07:05 -0700 (Fri, 06 Jun 2014)
Log Message:
-----------
Adding live OD service unit tests

Modified Paths:
--------------
    CalendarServer/trunk/contrib/od/setup_directory.py

Added Paths:
-----------
    CalendarServer/trunk/contrib/od/test/
    CalendarServer/trunk/contrib/od/test/__init__.py
    CalendarServer/trunk/contrib/od/test/test_live.py

Modified: CalendarServer/trunk/contrib/od/setup_directory.py
===================================================================
--- CalendarServer/trunk/contrib/od/setup_directory.py	2014-06-06 18:25:15 UTC (rev 13614)
+++ CalendarServer/trunk/contrib/od/setup_directory.py	2014-06-06 21:07:05 UTC (rev 13615)
@@ -115,6 +115,18 @@
             dsattributes.kDS1AttrPrimaryGroupID : ["20"],
         },
     ),
+    (
+        "anotherodtestamanda",
+        {
+            dsattributes.kDS1AttrFirstName : ["Amanda"],
+            dsattributes.kDS1AttrLastName  : ["Test"],
+            dsattributes.kDS1AttrDistinguishedName : ["Amanda Test"],
+            dsattributes.kDSNAttrEMailAddress : ["anotheramanda at example.com"],
+            dsattributes.kDS1AttrGeneratedUID : ["E7666814-6D92-49EC-8562-8C4C3D64A4B0"],
+            dsattributes.kDS1AttrUniqueID : ["33307"],
+            dsattributes.kDS1AttrPrimaryGroupID : ["20"],
+        },
+    ),
 ]
 
 masterGroups = [
@@ -137,6 +149,16 @@
             dsattributes.kDS1AttrPrimaryGroupID : ["33400"],
         },
     ),
+    (
+        "odtestgroupbetty",
+        {
+            dsattributes.kDS1AttrGeneratedUID : ["2A1F3ED9-D1B3-40F2-8FC4-05E197C1F90C"],
+            dsattributes.kDS1AttrDistinguishedName : ["OD Test Group Betty"],
+            dsattributes.kDSNAttrGroupMembers : [],
+            dsattributes.kDSNAttrNestedGroups : [],
+            dsattributes.kDS1AttrPrimaryGroupID : ["33403"],
+        },
+    ),
 ]
 
 localUsers = [
@@ -188,6 +210,18 @@
             dsattributes.kDS1AttrPrimaryGroupID : ["20"],
         },
     ),
+    (
+        "anotherodtestalbert",
+        {
+            dsattributes.kDS1AttrFirstName : ["Albert"],
+            dsattributes.kDS1AttrLastName  : ["Test"],
+            dsattributes.kDS1AttrDistinguishedName : ["Albert Test"],
+            dsattributes.kDSNAttrEMailAddress : ["anotheralbert at example.com"],
+            dsattributes.kDS1AttrGeneratedUID : ["8F059F1B-1CD0-42B5-BEA2-6A36C9B5620F"],
+            dsattributes.kDS1AttrUniqueID : ["33354"],
+            dsattributes.kDS1AttrPrimaryGroupID : ["20"],
+        },
+    ),
 ]
 
 localGroups = [
@@ -200,6 +234,15 @@
             dsattributes.kDS1AttrPrimaryGroupID : ["33402"],
         },
     ),
+    (
+        "odtestgroupalbert",
+        {
+            dsattributes.kDS1AttrGeneratedUID : ["3F4D01B8-FDFD-4805-A853-DE9879A2D951"],
+            dsattributes.kDS1AttrDistinguishedName : ["OD Test Group Albert"],
+            dsattributes.kDSNAttrGroupMembers : [],
+            dsattributes.kDS1AttrPrimaryGroupID : ["33404"],
+        },
+    ),
 ]
 
 

Added: CalendarServer/trunk/contrib/od/test/__init__.py
===================================================================
--- CalendarServer/trunk/contrib/od/test/__init__.py	                        (rev 0)
+++ CalendarServer/trunk/contrib/od/test/__init__.py	2014-06-06 21:07:05 UTC (rev 13615)
@@ -0,0 +1,15 @@
+##
+# Copyright (c) 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.
+##

Added: CalendarServer/trunk/contrib/od/test/test_live.py
===================================================================
--- CalendarServer/trunk/contrib/od/test/test_live.py	                        (rev 0)
+++ CalendarServer/trunk/contrib/od/test/test_live.py	2014-06-06 21:07:05 UTC (rev 13615)
@@ -0,0 +1,272 @@
+##
+# Copyright (c) 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.
+##
+
+"""
+OpenDirectory live service tests.
+"""
+
+from __future__ import print_function
+
+from itertools import chain
+from uuid import UUID
+
+from twisted.trial import unittest
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+
+
+try:
+    from twext.who.opendirectory import DirectoryService
+    moduleImported = True
+except:
+    moduleImported = False
+    print("Could not import OpenDirectory")
+
+if moduleImported:
+
+    from twext.who.expression import (
+        CompoundExpression, Operand, MatchExpression, MatchType, MatchFlags
+    )
+
+
+    LOCAL_SHORTNAMES = "odtestalbert odtestbill odtestcarl odtestdavid odtestsubgroupa".split()
+    NETWORK_SHORTNAMES = "odtestamanda odtestbetty odtestcarlene odtestdenise odtestsubgroupb odtestgrouptop".split()
+
+
+    def onlyIfPopulated(func):
+        """
+        Only run the decorated test method if the "odtestamanda" record exists
+        """
+        @inlineCallbacks
+        def checkThenRun(self):
+            record = yield self.service.recordWithShortName(self.service.recordType.user, u"odtestamanda")
+            if record is not None:
+                result = yield func(self)
+                returnValue(result)
+            else:
+                print("OD not populated, skipping {}".format(func.func_name))
+        return checkThenRun
+
+
+
+    class LiveOpenDirectoryServiceTestCase(unittest.TestCase):
+        """
+        Live service tests for L{DirectoryService}.
+        """
+
+        def setUp(self):
+            self.service = DirectoryService()
+
+
+        def verifyResults(self, records, expected, unexpected):
+            shortNames = []
+            for record in records:
+                for shortName in record.shortNames:
+                    shortNames.append(shortName)
+
+            for name in expected:
+                self.assertTrue(name in shortNames)
+            for name in unexpected:
+                self.assertFalse(name in shortNames)
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_shortNameStartsWith(self):
+            records = yield self.service.recordsFromExpression(
+                MatchExpression(
+                    self.service.fieldName.shortNames, u"odtest",
+                    matchType=MatchType.startsWith
+                )
+            )
+            self.verifyResults(
+                records,
+                chain(LOCAL_SHORTNAMES, NETWORK_SHORTNAMES),
+                ["anotherodtestamanda", "anotherodtestalbert"]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_uid(self):
+            for uid, name in (
+                (u"9DC04A71-E6DD-11DF-9492-0800200C9A66", u"odtestbetty"),
+                (u"9DC04A75-E6DD-11DF-9492-0800200C9A66", u"odtestbill"),
+            ):
+                record = yield self.service.recordWithUID(uid)
+                self.assertTrue(record is not None)
+                self.assertEquals(record.shortNames[0], name)
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_guid(self):
+            for guid, name in (
+                (UUID("9DC04A71-E6DD-11DF-9492-0800200C9A66"), u"odtestbetty"),
+                (UUID("9DC04A75-E6DD-11DF-9492-0800200C9A66"), u"odtestbill"),
+            ):
+                record = yield self.service.recordWithGUID(guid)
+                self.assertTrue(record is not None)
+                self.assertEquals(record.shortNames[0], name)
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_compoundWithoutRecordType(self):
+            expression = CompoundExpression(
+                [
+                    CompoundExpression(
+                        [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"be",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"be",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                    CompoundExpression(
+                        [
+                            MatchExpression(
+                                self.service.fieldName.fullNames, u"test",
+                                matchType=MatchType.contains
+                            ),
+                            MatchExpression(
+                                self.service.fieldName.emailAddresses, u"test",
+                                matchType=MatchType.startsWith
+                            ),
+                        ],
+                        Operand.OR
+                    ),
+                ],
+                Operand.AND
+            )
+            records = yield self.service.recordsFromExpression(expression)
+
+            # We should get back users and groups:
+            self.verifyResults(
+                records,
+                ["odtestbetty", "odtestalbert", "anotherodtestalbert", "odtestgroupbetty", "odtestgroupalbert"],
+                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb"]
+            )
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_compoundWithSingleRecordType(self):
+            expression = CompoundExpression(
+                [
+                    CompoundExpression(
+                        [
+                            CompoundExpression(
+                                [
+                                    MatchExpression(
+                                        self.service.fieldName.fullNames, u"be",
+                                        matchType=MatchType.contains
+                                    ),
+                                    MatchExpression(
+                                        self.service.fieldName.emailAddresses, u"be",
+                                        matchType=MatchType.startsWith
+                                    ),
+                                ],
+                                Operand.OR
+                            ),
+                            CompoundExpression(
+                                [
+                                    MatchExpression(
+                                        self.service.fieldName.fullNames, u"test",
+                                        matchType=MatchType.contains
+                                    ),
+                                    MatchExpression(
+                                        self.service.fieldName.emailAddresses, u"test",
+                                        matchType=MatchType.startsWith
+                                    ),
+                                ],
+                                Operand.OR
+                            ),
+                        ],
+                        Operand.AND
+                    ),
+                    MatchExpression(
+                        self.service.fieldName.recordType, self.service.recordType.user,
+                    ),
+                ],
+                Operand.AND
+            )
+            records = yield self.service.recordsFromExpression(expression)
+
+            # We should only get users back, not groups:
+            self.verifyResults(
+                records,
+                ["odtestbetty", "odtestalbert", "anotherodtestalbert"],
+                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb", "odtestgroupbetty", "odtestgroupalbert"]
+            )
+
+
+
+        @onlyIfPopulated
+        @inlineCallbacks
+        def test_compoundWithSingleRecordType(self):
+            expression = CompoundExpression(
+                [
+                    CompoundExpression(
+                        [
+                            CompoundExpression(
+                                [
+                                    MatchExpression(
+                                        self.service.fieldName.fullNames, u"be",
+                                        matchType=MatchType.contains
+                                    ),
+                                    MatchExpression(
+                                        self.service.fieldName.emailAddresses, u"be",
+                                        matchType=MatchType.startsWith
+                                    ),
+                                ],
+                                Operand.OR
+                            ),
+                            CompoundExpression(
+                                [
+                                    MatchExpression(
+                                        self.service.fieldName.fullNames, u"test",
+                                        matchType=MatchType.contains
+                                    ),
+                                    MatchExpression(
+                                        self.service.fieldName.emailAddresses, u"test",
+                                        matchType=MatchType.startsWith
+                                    ),
+                                ],
+                                Operand.OR
+                            ),
+                        ],
+                        Operand.AND
+                    ),
+                    MatchExpression(
+                        self.service.fieldName.recordType, self.service.recordType.user,
+                    ),
+                ],
+                Operand.AND
+            )
+            records = yield self.service.recordsFromExpression(expression)
+
+            # We should only get users back, not groups:
+            self.verifyResults(
+                records,
+                ["odtestbetty", "odtestalbert", "anotherodtestalbert"],
+                ["odtestamanda", "odtestbill", "odtestgroupa", "odtestgroupb", "odtestgroupbetty", "odtestgroupalbert"]
+            )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140606/aa156743/attachment-0001.html>


More information about the calendarserver-changes mailing list