[CalendarServer-changes] [11922] CalendarServer/trunk/twext/who/test/test_directory.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:24:48 PDT 2014
Revision: 11922
http://trac.calendarserver.org//changeset/11922
Author: wsanchez at apple.com
Date: 2013-11-08 15:55:15 -0800 (Fri, 08 Nov 2013)
Log Message:
-----------
Updates to immutable services that are no-ops are allowed.
More docs.
Modified Paths:
--------------
CalendarServer/trunk/twext/who/test/test_directory.py
Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- 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)
@@ -185,7 +185,25 @@
test_recordsWithEmailAddress = _unimplemented
+ def test_updateRecordsEmpty(self):
+ """
+ Updating no records is not an error.
+ """
+ service = self.service()
+ for create in (True, False):
+ service.updateRecords((), create=create),
+
+ def test_removeRecordsEmpty(self):
+ """
+ Removing no records is allowed.
+ """
+ service = self.service()
+
+ service.removeRecords(())
+
+
+
class DirectoryServiceTest(unittest.TestCase, BaseDirectoryServiceTest):
@inlineCallbacks
def test_recordsFromExpression_single(self):
@@ -318,7 +336,11 @@
def test_recordWithUID(self):
+ """
+ C{recordWithUID} fails with L{QueryNotSupportedError}.
+ """
service = self.service()
+
self.assertFailure(
service.recordWithUID(u""),
QueryNotSupportedError
@@ -326,7 +348,11 @@
def test_recordWithGUID(self):
+ """
+ C{recordWithGUID} fails with L{QueryNotSupportedError}.
+ """
service = self.service()
+
self.assertFailure(
service.recordWithGUID(UUID(int=0)),
QueryNotSupportedError
@@ -334,7 +360,11 @@
def test_recordsWithRecordType(self):
+ """
+ C{recordsWithRecordType} fails with L{QueryNotSupportedError}.
+ """
service = self.service()
+
for recordType in RecordType.iterconstants():
self.assertFailure(
service.recordsWithRecordType(recordType),
@@ -343,7 +373,11 @@
def test_recordWithShortName(self):
+ """
+ C{recordWithShortName} fails with L{QueryNotSupportedError}.
+ """
service = self.service()
+
for recordType in RecordType.iterconstants():
self.assertFailure(
service.recordWithShortName(recordType, u""),
@@ -352,7 +386,11 @@
def test_recordsWithEmailAddress(self):
+ """
+ C{recordsWithEmailAddress} fails with L{QueryNotSupportedError}.
+ """
service = self.service()
+
self.assertFailure(
service.recordsWithEmailAddress("a at b"),
QueryNotSupportedError
@@ -361,7 +399,14 @@
class BaseDirectoryServiceImmutableTest(ServiceMixIn):
+ """
+ Immutable directory record tests.
+ """
+
def test_updateRecordsNotAllowed(self):
+ """
+ Updating records is not allowed.
+ """
service = self.service()
newRecord = DirectoryRecord(
@@ -373,21 +418,19 @@
}
)
- self.assertFailure(
- service.updateRecords((newRecord,), create=True),
- NotAllowedError,
- )
+ for create in (True, False):
+ self.assertFailure(
+ service.updateRecords((newRecord,), create=create),
+ NotAllowedError,
+ )
- self.assertFailure(
- service.updateRecords((newRecord,), create=False),
- NotAllowedError,
- )
-
def test_removeRecordsNotAllowed(self):
+ """
+ Removing records is not allowed.
+ """
service = self.service()
- service.removeRecords(())
self.assertFailure(
service.removeRecords((u"foo",)),
NotAllowedError,
@@ -444,6 +487,18 @@
def makeRecord(self, fields=None, service=None):
+ """
+ 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}
+ """
if fields is None:
fields = self.fields_wsanchez
if service is None:
@@ -452,6 +507,9 @@
def test_interface(self):
+ """
+ L{DirectoryRecord} complies with L{IDirectoryRecord}.
+ """
record = self.makeRecord()
try:
verifyObject(IDirectoryRecord, record)
@@ -460,6 +518,9 @@
def test_init(self):
+ """
+ L{DirectoryRecord} initialization sets service and fields.
+ """
service = self.service()
wsanchez = self.makeRecord(self.fields_wsanchez, service=service)
@@ -468,6 +529,9 @@
def test_initWithNoUID(self):
+ """
+ Directory records must have a UID.
+ """
fields = self.fields_wsanchez.copy()
del fields[FieldName.uid]
self.assertRaises(ValueError, self.makeRecord, fields)
@@ -478,6 +542,9 @@
def test_initWithNoRecordType(self):
+ """
+ Directory records must have a record type.
+ """
fields = self.fields_wsanchez.copy()
del fields[FieldName.recordType]
self.assertRaises(ValueError, self.makeRecord, fields)
@@ -487,7 +554,19 @@
self.assertRaises(ValueError, self.makeRecord, fields)
+ def test_initWithBogusRecordType(self):
+ """
+ Directory records must have a known record type.
+ """
+ fields = self.fields_wsanchez.copy()
+ fields[FieldName.recordType] = object()
+ self.assertRaises(ValueError, self.makeRecord, fields)
+
+
def test_initWithNoShortNames(self):
+ """
+ Directory records must have a short name.
+ """
fields = self.fields_wsanchez.copy()
del fields[FieldName.shortNames]
self.assertRaises(ValueError, self.makeRecord, fields)
@@ -505,13 +584,10 @@
self.assertRaises(ValueError, self.makeRecord, fields)
- def test_initWithBogusRecordType(self):
- fields = self.fields_wsanchez.copy()
- fields[FieldName.recordType] = object()
- self.assertRaises(ValueError, self.makeRecord, fields)
-
-
- def test_initNormalize(self):
+ def test_initNormalizeEmailLowercase(self):
+ """
+ Email addresses are normalized to lowercase.
+ """
sagen = self.makeRecord(self.fields_sagen)
self.assertEquals(
@@ -521,6 +597,9 @@
def test_compare(self):
+ """
+ Comparison of records.
+ """
fields_glyphmod = self.fields_glyph.copy()
del fields_glyphmod[FieldName.emailAddresses]
@@ -539,6 +618,9 @@
def test_attributeAccess(self):
+ """
+ Fields can be accessed as attributes.
+ """
wsanchez = self.makeRecord(self.fields_wsanchez)
self.assertEquals(
@@ -560,23 +642,34 @@
@inlineCallbacks
- def test_members(self):
+ def test_members_group(self):
+ """
+ Group members.
+ """
+ raise SkipTest("Subclasses should implement this test.")
+
+
+ def test_members_nonGroup(self):
+ """
+ Non-groups have no members.
+ """
wsanchez = self.makeRecord(self.fields_wsanchez)
self.assertEquals(
set((yield wsanchez.members())),
set()
)
- raise SkipTest("Subclasses should implement this test.")
-
def test_groups(self):
+ """
+ Group memberships.
+ """
raise SkipTest("Subclasses should implement this test.")
class DirectoryRecordTest(unittest.TestCase, BaseDirectoryRecordTest):
- def test_members(self):
+ def test_members_group(self):
wsanchez = self.makeRecord(self.fields_wsanchez)
self.assertEquals(
set((yield wsanchez.members())),
@@ -594,6 +687,11 @@
class StubDirectoryService(DirectoryService):
+ """
+ Stubn directory service with some built-in records and an implementation
+ of C{recordsFromNonCompoundExpression}.
+ """
+
def __init__(self):
DirectoryService.__init__(self, u"Stub")
@@ -602,6 +700,9 @@
def _addRecords(self):
+ """
+ Add a known set of records to this service.
+ """
self._addUser(
shortNames=[u"wsanchez", u"wilfredo_sanchez"],
fullNames=[u"Wilfredo S\xe1nchez Vega"],
@@ -680,6 +781,18 @@
def _addUser(self, shortNames, fullNames, emailAddresses=[]):
+ """
+ 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
+ """
self.records.append(DirectoryRecord(self, {
self.fieldName.recordType: self.recordType.user,
self.fieldName.uid: u"__{0}__".format(shortNames[0]),
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/952435de/attachment.html>
More information about the calendarserver-changes
mailing list