[CalendarServer-changes] [5591] CalendarServer/branches/users/wsanchez/transations/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Wed May 12 12:41:42 PDT 2010
Revision: 5591
http://trac.macosforge.org/projects/calendarserver/changeset/5591
Author: glyph at apple.com
Date: 2010-05-12 12:41:39 -0700 (Wed, 12 May 2010)
Log Message:
-----------
Refactor tests to eliminate duplicate directory service & calendar resource setup.
Modified Paths:
--------------
CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_calendar.py
CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_guidchange.py
CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_xmlfile.py
CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py
CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/util.py
Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_calendar.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_calendar.py 2010-05-12 04:43:35 UTC (rev 5590)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_calendar.py 2010-05-12 19:41:39 UTC (rev 5591)
@@ -14,57 +14,25 @@
# limitations under the License.
##
-import os
-
from twisted.internet.defer import inlineCallbacks
from twext.web2.dav import davxml
from twext.web2.test.test_server import SimpleRequest
from twistedcaldav import caldavxml
-from twistedcaldav.directory import augment
-from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
-from twistedcaldav.directory.test.test_xmlfile import xmlFile, augmentsFile
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.static import CalendarHomeProvisioningFile
-import twistedcaldav.test.util
-from twistedcaldav.config import config
+from twistedcaldav.test.util import TestCase
-class ProvisionedCalendars (twistedcaldav.test.util.TestCase):
+class ProvisionedCalendars (TestCase):
"""
Directory service provisioned principals.
"""
def setUp(self):
super(ProvisionedCalendars, self).setUp()
-
- # Setup the initial directory
- self.xmlFile = os.path.join(config.DataRoot, "accounts.xml")
- fd = open(self.xmlFile, "w")
- fd.write(open(xmlFile.path, "r").read())
- fd.close()
- self.directoryService = XMLDirectoryService({'xmlFile' : "accounts.xml"})
- augment.AugmentService = augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,))
-
- # Set up a principals hierarchy for each service we're testing with
- name = "principals"
- url = "/" + name + "/"
- provisioningResource = DirectoryPrincipalProvisioningResource(url, self.directoryService)
-
- self.site.resource.putChild("principals", provisioningResource)
-
+ self.createStockDirectoryService()
self.setupCalendars()
- self.site.resource.setAccessControlList(davxml.ACL())
- def setupCalendars(self):
- calendarCollection = CalendarHomeProvisioningFile(
- os.path.join(self.docroot, "calendars"),
- self.directoryService,
- "/calendars/"
- )
- self.site.resource.putChild("calendars", calendarCollection)
-
def test_NonExistentCalendarHome(self):
def _response(resource):
Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_guidchange.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_guidchange.py 2010-05-12 04:43:35 UTC (rev 5590)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_guidchange.py 2010-05-12 19:41:39 UTC (rev 5591)
@@ -13,62 +13,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
-from twistedcaldav.static import CalendarHomeProvisioningFile
from twistedcaldav.directory.directory import DirectoryService
-import os
-
from twext.web2.dav import davxml
from twext.web2.dav.resource import AccessDeniedError
from twext.web2.test.test_server import SimpleRequest
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.directory.test.test_xmlfile import xmlFile, augmentsFile
+from twistedcaldav.test.util import TestCase, xmlFile
-import twistedcaldav.test.util
-from twistedcaldav.directory import augment
-
-class ProvisionedPrincipals (twistedcaldav.test.util.TestCase):
+class ProvisionedPrincipals(TestCase):
"""
Directory service provisioned principals.
"""
def setUp(self):
super(ProvisionedPrincipals, self).setUp()
-
- # Setup the initial directory
- self.xmlFile = os.path.abspath(self.mktemp())
- fd = open(self.xmlFile, "w")
- fd.write(open(xmlFile.path, "r").read())
- fd.close()
- self.directoryService = XMLDirectoryService({'xmlFile' : self.xmlFile})
- augment.AugmentService = augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,))
-
- # Set up a principals hierarchy for each service we're testing with
- name = "principals"
- url = "/" + name + "/"
- provisioningResource = DirectoryPrincipalProvisioningResource(url, self.directoryService)
-
- self.site.resource.putChild("principals", provisioningResource)
-
+ # Setup the initial directory
+ self.createStockDirectoryService()
self.setupCalendars()
self.site.resource.setAccessControlList(davxml.ACL())
- def setupCalendars(self):
- calendarCollection = CalendarHomeProvisioningFile(
- os.path.join(self.docroot, "calendars"),
- self.directoryService,
- "/calendars/"
- )
- self.site.resource.putChild("calendars", calendarCollection)
def resetCalendars(self):
del self.site.resource.putChildren["calendars"]
self.setupCalendars()
+
def test_guidchange(self):
"""
DirectoryPrincipalResource.proxies()
@@ -80,10 +52,9 @@
def privs1(result):
# Change GUID in record
- fd = open(self.xmlFile, "w")
- fd.write(open(xmlFile.path, "r").read().replace(oldUID, newUID))
- fd.close()
- fd = None
+ self.xmlFile.setContent(
+ xmlFile.getContent().replace(oldUID, newUID)
+ )
# Force re-read of records (not sure why _fileInfo has to be wiped here...)
self.directoryService._fileInfo = (0, 0)
Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_xmlfile.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_xmlfile.py 2010-05-12 04:43:35 UTC (rev 5590)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/directory/test/test_xmlfile.py 2010-05-12 19:41:39 UTC (rev 5591)
@@ -14,15 +14,13 @@
# limitations under the License.
##
-import os
-
from twext.python.filepath import CachingFilePath as FilePath
from twistedcaldav.directory import augment
from twistedcaldav.directory.directory import DirectoryService
import twistedcaldav.directory.test.util
from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.test.util import TestCase, xmlFile, augmentsFile, proxiesFile
+from twistedcaldav.test.util import TestCase, xmlFile, augmentsFile
# FIXME: Add tests for GUID hooey, once we figure out what that means here
@@ -100,7 +98,8 @@
"""
def service(self):
directory = XMLDirectoryService({'xmlFile' : self.xmlFile()}, alwaysStat=True)
- augment.AugmentService = augment.AugmentXMLDB(xmlFiles=(self.augmentsFile().path,))
+ self.patch(augment, "AugmentService",
+ augment.AugmentXMLDB(xmlFiles=(self.augmentsFile().path,)))
return directory
def test_changedXML(self):
Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py 2010-05-12 04:43:35 UTC (rev 5590)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/test_wrapping.py 2010-05-12 19:41:39 UTC (rev 5591)
@@ -19,16 +19,9 @@
from twisted.internet.defer import inlineCallbacks, returnValue
-from twext.python.filepath import CachingFilePath as FilePath
-from twext.web2.dav import davxml
-
from twistedcaldav.directory.calendar import uidsResourceName
-from twistedcaldav.directory.principal import (
- DirectoryPrincipalProvisioningResource)
from twistedcaldav.ical import Component as VComponent
-from twistedcaldav.static import CalendarHomeProvisioningFile
-
from twistedcaldav.test.util import TestCase
from txcaldav.calendarstore.file import CalendarStore, CalendarHome
@@ -52,16 +45,9 @@
# Setup the initial directory
self.createStockDirectoryService()
+ self.setupCalendars()
- calendarsPath = FilePath(self.docroot).child("calendars")
- calendarsPath.makedirs()
- self.calendarCollection = CalendarHomeProvisioningFile(
- calendarsPath, self.directoryService, "/calendars/"
- )
- self.site.resource.putChild("calendars", self.calendarCollection)
- self.site.resource.setAccessControlList(davxml.ACL())
-
def populateOneObject(self, objectName, objectText):
"""
Populate one calendar object in the test user's calendar.
Modified: CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/util.py 2010-05-12 04:43:35 UTC (rev 5590)
+++ CalendarServer/branches/users/wsanchez/transations/twistedcaldav/test/util.py 2010-05-12 19:41:39 UTC (rev 5591)
@@ -91,6 +91,21 @@
)
+ def setupCalendars(self):
+ """
+ Set up the resource at /calendars (a L{CalendarHomeProvisioningFile}),
+ and assign it as C{self.calendarCollection}.
+ """
+ path = self.site.resource.fp.child("calendars")
+ path.createDirectory()
+ self.calendarCollection = CalendarHomeProvisioningFile(
+ path,
+ self.directoryService,
+ "/calendars/"
+ )
+ self.site.resource.putChild("calendars", self.calendarCollection)
+
+
def setUp(self):
super(TestCase, self).setUp()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100512/0713d1c3/attachment-0001.html>
More information about the calendarserver-changes
mailing list