[CalendarServer-changes] [10782] CalendarServer/trunk/twext/who/test/test_xml.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 21 17:04:21 PST 2013
Revision: 10782
http://trac.calendarserver.org//changeset/10782
Author: wsanchez at apple.com
Date: 2013-02-21 17:04:21 -0800 (Thu, 21 Feb 2013)
Log Message:
-----------
Break XML DirectoryService tests into separate classes.
Modified Paths:
--------------
CalendarServer/trunk/twext/who/test/test_xml.py
Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-22 00:45:57 UTC (rev 10781)
+++ CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-22 01:04:21 UTC (rev 10782)
@@ -20,6 +20,7 @@
from time import sleep
+from twisted.trial import unittest
from twisted.python.filepath import FilePath
from twisted.internet.defer import inlineCallbacks
@@ -154,13 +155,20 @@
-class BaseTest(object):
+class BaseTest(unittest.TestCase):
def service(self, xmlData=None):
return xmlService(self.mktemp(), xmlData)
+ def assertRecords(self, records, uids):
+ self.assertEquals(
+ frozenset((record.uid for record in records)),
+ frozenset((uids)),
+ )
-class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest):
+
+
+class DirectoryServiceBaseTest(BaseTest, test_directory.DirectoryServiceTest):
def test_repr(self):
service = self.service()
@@ -169,13 +177,85 @@
self.assertEquals(repr(service), "<TestService 'xyzzy'>")
- def assertRecords(self, records, uids):
- self.assertEquals(
- frozenset((record.uid for record in records)),
- frozenset((uids)),
+ @inlineCallbacks
+ def test_recordWithUID(self):
+ service = self.service()
+
+ record = (yield service.recordWithUID("__null__"))
+ self.assertEquals(record, None)
+
+ record = (yield service.recordWithUID("__wsanchez__"))
+ self.assertEquals(record.uid, "__wsanchez__")
+
+
+ @inlineCallbacks
+ def test_recordWithGUID(self):
+ service = self.service()
+ record = (yield service.recordWithGUID("6C495FCD-7E78-4D5C-AA66-BC890AD04C9D"))
+ self.assertEquals(record, None)
+
+ @inlineCallbacks
+ def test_recordsWithRecordType(self):
+ service = self.service()
+
+ records = (yield service.recordsWithRecordType(object()))
+ self.assertEquals(set(records), set())
+
+ records = (yield service.recordsWithRecordType(service.recordType.user))
+ self.assertRecords(records,
+ (
+ "__wsanchez__",
+ "__glyph__",
+ "__sagen__",
+ "__cdaboo__",
+ "__dre__",
+ "__exarkun__",
+ "__dreid__",
+ "__alyssa__",
+ "__joe__",
+ ),
)
+ records = (yield service.recordsWithRecordType(service.recordType.group))
+ self.assertRecords(records,
+ (
+ "__calendar-dev__",
+ "__twisted__",
+ "__developers__",
+ ),
+ )
+
+ @inlineCallbacks
+ def test_recordWithShortName(self):
+ service = self.service()
+
+ record = (yield service.recordWithShortName(service.recordType.user, "null"))
+ self.assertEquals(record, None)
+
+ record = (yield service.recordWithShortName(service.recordType.user, "wsanchez"))
+ self.assertEquals(record.uid, "__wsanchez__")
+
+ record = (yield service.recordWithShortName(service.recordType.user, "wilfredo_sanchez"))
+ self.assertEquals(record.uid, "__wsanchez__")
+
+
+ @inlineCallbacks
+ def test_recordsWithEmailAddress(self):
+ service = self.service()
+
+ records = (yield service.recordsWithEmailAddress("wsanchez at bitbucket.calendarserver.org"))
+ self.assertRecords(records, ("__wsanchez__",))
+
+ records = (yield service.recordsWithEmailAddress("wsanchez at devnull.twistedmatrix.com"))
+ self.assertRecords(records, ("__wsanchez__",))
+
+ records = (yield service.recordsWithEmailAddress("shared at example.com"))
+ self.assertRecords(records, ("__sagen__", "__dre__"))
+
+
+
+class DirectoryServiceRealmTest(BaseTest):
def test_realmNameImmutable(self):
def setRealmName():
service = self.service()
@@ -184,6 +264,8 @@
self.assertRaises(AssertionError, setRealmName)
+
+class DirectoryServiceParsingTest(BaseTest):
def test_reloadInterval(self):
service = self.service()
@@ -248,84 +330,30 @@
raise AssertionError
- @inlineCallbacks
- def test_recordWithUID(self):
+ def test_unknownFieldElementsClean(self):
service = self.service()
+ self.assertEquals(set(service.unknownFieldElements), set())
- record = (yield service.recordWithUID("__null__"))
- self.assertEquals(record, None)
- record = (yield service.recordWithUID("__wsanchez__"))
- self.assertEquals(record.uid, "__wsanchez__")
+ def test_unknownFieldElementsDirty(self):
+ service = self.service(xmlData=
+"""<?xml version="1.0" encoding="utf-8"?>
-
- @inlineCallbacks
- def test_recordWithGUID(self):
- service = self.service()
- record = (yield service.recordWithGUID("6C495FCD-7E78-4D5C-AA66-BC890AD04C9D"))
- self.assertEquals(record, None)
-
- @inlineCallbacks
- def test_recordsWithRecordType(self):
- service = self.service()
-
- records = (yield service.recordsWithRecordType(object()))
- self.assertEquals(set(records), set())
-
- records = (yield service.recordsWithRecordType(service.recordType.user))
- self.assertRecords(records,
- (
- "__wsanchez__",
- "__glyph__",
- "__sagen__",
- "__cdaboo__",
- "__dre__",
- "__exarkun__",
- "__dreid__",
- "__alyssa__",
- "__joe__",
- ),
+<directory realm="Unknown Record Types">
+ <record type="user">
+ <uid>__wsanchez__</uid>
+ <short-name>wsanchez</short-name>
+ <political-affiliation>Community and Freedom Party</political-affiliation>
+ </record>
+</directory>
+"""
)
+ self.assertEquals(set(service.unknownFieldElements), set(("political-affiliation",)))
- records = (yield service.recordsWithRecordType(service.recordType.group))
- self.assertRecords(records,
- (
- "__calendar-dev__",
- "__twisted__",
- "__developers__",
- ),
- )
+class DirectoryServiceQueryTest(BaseTest):
@inlineCallbacks
- def test_recordWithShortName(self):
- service = self.service()
-
- record = (yield service.recordWithShortName(service.recordType.user, "null"))
- self.assertEquals(record, None)
-
- record = (yield service.recordWithShortName(service.recordType.user, "wsanchez"))
- self.assertEquals(record.uid, "__wsanchez__")
-
- record = (yield service.recordWithShortName(service.recordType.user, "wilfredo_sanchez"))
- self.assertEquals(record.uid, "__wsanchez__")
-
-
- @inlineCallbacks
- def test_recordsWithEmailAddress(self):
- service = self.service()
-
- records = (yield service.recordsWithEmailAddress("wsanchez at bitbucket.calendarserver.org"))
- self.assertRecords(records, ("__wsanchez__",))
-
- records = (yield service.recordsWithEmailAddress("wsanchez at devnull.twistedmatrix.com"))
- self.assertRecords(records, ("__wsanchez__",))
-
- records = (yield service.recordsWithEmailAddress("shared at example.com"))
- self.assertRecords(records, ("__sagen__", "__dre__"))
-
-
- @inlineCallbacks
def test_queryAnd(self):
service = self.service()
records = yield service.recordsFromQuery(
@@ -651,27 +679,8 @@
self.assertEquals(set(service.unknownRecordTypes), set(("camera",)))
- def test_unknownFieldElementsClean(self):
- service = self.service()
- self.assertEquals(set(service.unknownFieldElements), set())
-
- def test_unknownFieldElementsDirty(self):
- service = self.service(xmlData=
-"""<?xml version="1.0" encoding="utf-8"?>
-
-<directory realm="Unknown Record Types">
- <record type="user">
- <uid>__wsanchez__</uid>
- <short-name>wsanchez</short-name>
- <political-affiliation>Community and Freedom Party</political-affiliation>
- </record>
-</directory>
-"""
- )
- self.assertEquals(set(service.unknownFieldElements), set(("political-affiliation",)))
-
-
+class DirectoryServiceMutableTest(BaseTest):
@inlineCallbacks
def test_updateRecord(self):
service = self.service()
@@ -804,6 +813,23 @@
+class QueryMixIn(object):
+ def query(self, field, value, matchType=MatchType.equals, flags=None):
+ name = getattr(self.fieldName, field)
+ assert name is not None
+ return MatchExpression(
+ name, value,
+ matchType = matchType,
+ flags = flags,
+ )
+
+
+
+class TestService(DirectoryService, QueryMixIn):
+ pass
+
+
+
def xmlService(tmp, xmlData=None):
if xmlData is None:
xmlData = testXMLConfig
@@ -811,14 +837,4 @@
filePath = FilePath(tmp)
filePath.setContent(xmlData)
- class TestService(DirectoryService):
- def query(self, field, value, matchType=MatchType.equals, flags=None):
- name = getattr(self.fieldName, field)
- assert name is not None
- return MatchExpression(
- name, value,
- matchType = matchType,
- flags = flags,
- )
-
return TestService(filePath)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130221/4ed69d98/attachment-0001.html>
More information about the calendarserver-changes
mailing list