[CalendarServer-changes] [12133] twext/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:20:06 PDT 2014
Revision: 12133
http://trac.calendarserver.org//changeset/12133
Author: wsanchez at apple.com
Date: 2013-12-18 17:23:27 -0800 (Wed, 18 Dec 2013)
Log Message:
-----------
directory.DirectoryService now has an empty set of supported record types; subclasses must declare all supported record types explicitly.
Modified Paths:
--------------
twext/trunk/twext/who/directory.py
twext/trunk/twext/who/test/test_directory.py
twext/trunk/twext/who/test/test_index.py
twext/trunk/twext/who/test/test_xml.py
twext/trunk/twext/who/xml.py
Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py 2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/directory.py 2013-12-19 01:23:27 UTC (rev 12133)
@@ -35,7 +35,7 @@
IDirectoryService, IDirectoryRecord,
)
from .expression import CompoundExpression, Operand, MatchExpression
-from .util import uniqueResult, describe
+from .util import uniqueResult, describe, ConstantsContainer
@@ -87,7 +87,7 @@
a L{unicode}).
"""
- recordType = RecordType
+ recordType = ConstantsContainer(())
fieldName = FieldName
normalizedFields = {
@@ -302,9 +302,9 @@
service.recordType.iterconstants()
):
raise ValueError(
- "Record type must be one of {0!r}, not {1!r}.".format(
+ "Unknown record type: {0!r} is not in {1!r}.".format(
+ fields[FieldName.recordType],
tuple(service.recordType.iterconstants()),
- fields[FieldName.recordType],
)
)
Modified: twext/trunk/twext/who/test/test_directory.py
===================================================================
--- twext/trunk/twext/who/test/test_directory.py 2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_directory.py 2013-12-19 01:23:27 UTC (rev 12133)
@@ -35,17 +35,23 @@
)
from ..expression import CompoundExpression, Operand
from ..directory import DirectoryService, DirectoryRecord
+from ..util import ConstantsContainer
-class StubDirectoryService(DirectoryService):
+class TestDirectoryService(DirectoryService):
+ recordType = ConstantsContainer((RecordType,))
+
+
+
+class StubDirectoryService(TestDirectoryService):
"""
Stub directory service with some built-in records and an implementation
of C{recordsFromNonCompoundExpression}.
"""
def __init__(self, realmName):
- DirectoryService.__init__(self, realmName)
+ super(StubDirectoryService, self).__init__(realmName)
self.records = RecordStorage(self, DirectoryRecord)
@@ -53,7 +59,10 @@
def recordsFromExpression(self, expression):
self.seenExpressions = []
- return DirectoryService.recordsFromExpression(self, expression)
+ return (
+ super(StubDirectoryService, self)
+ .recordsFromExpression(expression)
+ )
def recordsFromNonCompoundExpression(self, expression, records=None):
@@ -80,8 +89,9 @@
break
return succeed(result)
- return DirectoryService.recordsFromNonCompoundExpression(
- self, expression, records=records
+ return (
+ super(StubDirectoryService, self)
+ .recordsFromNonCompoundExpression(expression, records=records)
)
@@ -103,7 +113,7 @@
class BaseDirectoryServiceTest(ServiceMixIn):
"""
- Tests for directory services.
+ Tests for L{DirectoryService} and subclasses.
"""
def test_interface(self):
@@ -260,15 +270,16 @@
class DirectoryServiceRecordsFromExpressionTest(
- unittest.TestCase,
- ServiceMixIn
+ unittest.TestCase, ServiceMixIn
):
"""
Tests for L{DirectoryService.recordsFromExpression}.
"""
+
serviceClass = StubDirectoryService
directoryRecordClass = DirectoryRecord
+
@inlineCallbacks
def test_recordsFromExpression_single(self):
"""
@@ -402,13 +413,13 @@
class DirectoryServiceConvenienceTest(
- unittest.TestCase,
- BaseDirectoryServiceTest
+ unittest.TestCase, BaseDirectoryServiceTest
):
"""
Tests for L{DirectoryService} convenience methods.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
@@ -520,13 +531,13 @@
class DirectoryServiceImmutableTest(
- unittest.TestCase,
- BaseDirectoryServiceImmutableTest,
+ unittest.TestCase, BaseDirectoryServiceImmutableTest,
):
"""
Tests for immutable L{DirectoryService}.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
@@ -598,7 +609,7 @@
fields = self.fields_wsanchez
if service is None:
service = self.service()
- return DirectoryRecord(service, fields)
+ return self.directoryRecordClass(service, fields)
def test_interface(self):
@@ -710,7 +721,7 @@
fields_glyphmod = self.fields_glyph.copy()
del fields_glyphmod[FieldName.emailAddresses]
- plugh = DirectoryService(u"plugh")
+ plugh = self.serviceClass(u"plugh")
wsanchez = self.makeRecord(self.fields_wsanchez)
wsanchezmod = self.makeRecord(self.fields_wsanchez, plugh)
@@ -809,9 +820,11 @@
"""
Tests for L{DirectoryRecord}.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
+
def test_members_group(self):
staff = self.makeRecord(self.fields_staff)
@@ -829,6 +842,7 @@
"""
Container for directory records.
"""
+
def __init__(self, service, recordClass):
self.service = service
self.recordClass = recordClass
@@ -938,6 +952,7 @@
service = self.service
fieldName = service.fieldName
recordType = service.recordType
+
self.records.append(self.recordClass(self.service, {
fieldName.recordType: recordType.user,
fieldName.uid: u"__{0}__".format(shortNames[0]),
Modified: twext/trunk/twext/who/test/test_index.py
===================================================================
--- twext/trunk/twext/who/test/test_index.py 2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_index.py 2013-12-19 01:23:27 UTC (rev 12133)
@@ -21,14 +21,23 @@
from twisted.trial import unittest
from twisted.internet.defer import inlineCallbacks, returnValue
-from ..idirectory import FieldName as BaseFieldName, QueryNotSupportedError
+from ..idirectory import (
+ FieldName as BaseFieldName, RecordType as BaseRecordType,
+ QueryNotSupportedError,
+)
from ..expression import MatchExpression, MatchType
from ..index import DirectoryService, DirectoryRecord
+from ..util import ConstantsContainer
from . import test_directory
from .test_directory import RecordStorage
+class TestDirectoryService(DirectoryService):
+ recordType = ConstantsContainer((BaseRecordType,))
+
+
+
def noLoadDirectoryService(superClass):
"""
Creates an indexed directory service that has a no-op implementation of
@@ -370,7 +379,8 @@
"""
Tests for L{DirectoryService}.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
@@ -386,7 +396,7 @@
"""
Getting the C{index} property calls C{loadRecords}.
"""
- class TestService(DirectoryService):
+ class TestService(self.serviceClass):
loaded = False
def loadRecords(self):
@@ -434,7 +444,8 @@
"""
Tests for immutable L{DirectoryService}.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
@@ -450,7 +461,8 @@
"""
Tests for L{DirectoryRecord}.
"""
- serviceClass = DirectoryService
+
+ serviceClass = TestDirectoryService
directoryRecordClass = DirectoryRecord
Modified: twext/trunk/twext/who/test/test_xml.py
===================================================================
--- twext/trunk/twext/who/test/test_xml.py 2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_xml.py 2013-12-19 01:23:27 UTC (rev 12133)
@@ -771,9 +771,11 @@
BaseTest,
test_index.BaseDirectoryRecordTest
):
+
serviceClass = DirectoryService
directoryRecordClass = DirectoryRecord
+
@inlineCallbacks
def test_members_group(self):
service = self.service()
Modified: twext/trunk/twext/who/xml.py
===================================================================
--- twext/trunk/twext/who/xml.py 2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/xml.py 2013-12-19 01:23:27 UTC (rev 12133)
@@ -47,6 +47,7 @@
DirectoryService as BaseDirectoryService,
DirectoryRecord, FieldName as IndexFieldName,
)
+from .util import ConstantsContainer
@@ -128,6 +129,8 @@
XML directory service.
"""
+ recordType = ConstantsContainer((RecordType.user, RecordType.group))
+
element = Element
attribute = Attribute
value = Value
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/4027426b/attachment.html>
More information about the calendarserver-changes
mailing list