[CalendarServer-changes] [5619] CalendarServer/branches/new-store/txcaldav/calendarstore/test
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 18 18:36:48 PDT 2010
Revision: 5619
http://trac.macosforge.org/projects/calendarserver/changeset/5619
Author: glyph at apple.com
Date: 2010-05-18 18:36:46 -0700 (Tue, 18 May 2010)
Log Message:
-----------
Begin pulling out tests which should apply to all implementations to make cross-functional testing easier.
Modified Paths:
--------------
CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_file.py
Added Paths:
-----------
CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_common.py
Added: CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_common.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_common.py (rev 0)
+++ CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_common.py 2010-05-19 01:36:46 UTC (rev 5619)
@@ -0,0 +1,142 @@
+# -*- test-case-name: txcaldav.calendarstore.test.test_file -*-
+##
+# Copyright (c) 2010 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.
+##
+"""
+Tests for common calendar store API functions.
+"""
+
+from txcaldav.icalendarstore import ICalendarStore, ICalendarStoreTransaction, \
+ ICalendarObject, ICalendarHome, ICalendar
+from twext.python.filepath import CachingFilePath as FilePath
+from zope.interface.verify import verifyObject
+from zope.interface.exceptions import BrokenMethodImplementation
+
+
+storePath = FilePath(__file__).parent().child("calendar_store")
+
+homeRoot = storePath.child("ho").child("me").child("home1")
+
+cal1Root = homeRoot.child("calendar_1")
+
+
+
+class CommonTests(object):
+ """
+ Tests for common functionality of interfaces defined in
+ L{txcaldav.icalendarstore}.
+ """
+
+ requirements = {
+ "home1": {
+ "calendar_1": {
+ "1.ics": cal1Root.child("1.ics").getContent(),
+ "2.ics": cal1Root.child("2.ics").getContent(),
+ "3.ics": cal1Root.child("3.ics").getContent()
+ },
+ "calendar_empty": {},
+ "not_a_calendar": None
+ },
+ "not_a_home": None
+ }
+
+ def storeUnderTest(self):
+ """
+ Subclasses must override this to return an L{ICalendarStore} provider
+ which adheres to the structure detailed by L{CommonTests.requirements}.
+ This attribute is a dict of dict of dicts; the outermost layer
+ representing UIDs mapping to calendar homes, then calendar names mapping
+ to calendar collections, and finally calendar object names mapping to
+ calendar object text.
+ """
+ raise NotImplementedError()
+
+
+ def homeUnderTest(self):
+ """
+ Get the calendar home detailed by C{requirements['home1']}.
+ """
+ return self.storeUnderTest().newTransaction().calendarHomeWithUID(
+ "home1")
+
+
+ def calendarUnderTest(self):
+ """
+ Get the calendar detailed by C{requirements['home1']['calendar_1']}.
+ """
+ return self.homeUnderTest().calendarWithName("calendar_1")
+
+
+ def calendarObjectUnderTest(self):
+ """
+ Get the calendar detailed by
+ C{requirements['home1']['calendar_1']['1.ics']}.
+ """
+ return self.calendarUnderTest().calendarObjectWithName("1.ics")
+
+
+ def assertProvides(self, interface, provider):
+ """
+ Verify that C{provider} properly provides C{interface}
+
+ @type interface: L{zope.interface.Interface}
+ @type provider: C{provider}
+ """
+ try:
+ verifyObject(interface, provider)
+ except BrokenMethodImplementation, e:
+ self.fail(e)
+
+
+ def test_calendarStoreProvides(self):
+ """
+ The calendar store provides L{ICalendarStore} and its required
+ attributes.
+ """
+ calendarStore = self.storeUnderTest()
+ self.assertProvides(ICalendarStore, calendarStore)
+
+
+ def test_transactionProvides(self):
+ """
+ The transactions generated by the calendar store provide
+ L{ICalendarStoreTransaction} and its required attributes.
+ """
+ self.assertProvides(ICalendarStoreTransaction,
+ self.storeUnderTest().newTransaction())
+
+
+ def test_homeProvides(self):
+ """
+ The calendar homes generated by the calendar store provide
+ L{ICalendarHome} and its required attributes.
+ """
+ self.assertProvides(ICalendarHome, self.homeUnderTest())
+
+
+ def test_calendarProvides(self):
+ """
+ The calendars generated by the calendar store provide L{ICalendar} and
+ its required attributes.
+ """
+ self.assertProvides(ICalendar, self.calendarUnderTest())
+
+
+ def test_calendarObjectProvides(self):
+ """
+ The calendar objects generated by the calendar store provide
+ L{ICalendarObject} and its required attributes.
+ """
+ self.assertProvides(ICalendarObject, self.calendarObjectUnderTest())
Modified: CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_file.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_file.py 2010-05-19 00:33:26 UTC (rev 5618)
+++ CalendarServer/branches/new-store/txcaldav/calendarstore/test/test_file.py 2010-05-19 01:36:46 UTC (rev 5619)
@@ -18,8 +18,6 @@
File calendar store tests.
"""
-from zope.interface.verify import verifyObject, BrokenMethodImplementation
-
from twext.python.filepath import CachingFilePath as FilePath
from twisted.trial import unittest
@@ -30,8 +28,6 @@
from txdav.idav import IPropertyStore
from txdav.propertystore.base import PropertyName
-from txcaldav.icalendarstore import ICalendarStore, ICalendarHome
-from txcaldav.icalendarstore import ICalendar, ICalendarObject
from txcaldav.icalendarstore import CalendarNameNotAllowedError
from txcaldav.icalendarstore import CalendarObjectNameNotAllowedError
from txcaldav.icalendarstore import CalendarAlreadyExistsError
@@ -44,6 +40,8 @@
from txcaldav.calendarstore.file import CalendarStore, CalendarHome
from txcaldav.calendarstore.file import Calendar, CalendarObject
+from txcaldav.calendarstore.test.test_common import CommonTests
+
storePath = FilePath(__file__).parent().child("calendar_store")
home1_calendarNames = (
@@ -190,16 +188,6 @@
setUpCalendarStore(self)
- def test_interface(self):
- """
- Interface is completed and conforming.
- """
- try:
- verifyObject(ICalendarStore, self.calendarStore)
- except BrokenMethodImplementation, e:
- self.fail(e)
-
-
def test_init(self):
"""
Ivars are correctly initialized.
@@ -272,16 +260,6 @@
setUpHome1(self)
- def test_interface(self):
- """
- Interface is completed and conforming.
- """
- try:
- verifyObject(ICalendarHome, self.home1)
- except BrokenMethodImplementation, e:
- self.fail(e)
-
-
def test_init(self):
"""
Ivars are correctly initialized.
@@ -435,16 +413,6 @@
setUpCalendar1(self)
- def test_interface(self):
- """
- Interface is completed and conforming.
- """
- try:
- verifyObject(ICalendar, self.calendar1)
- except BrokenMethodImplementation, e:
- self.fail(e)
-
-
def test_init(self):
"""
L{Calendar.__init__} sets private attributes to reflect its constructor
@@ -823,16 +791,6 @@
self.object1 = self.calendar1.calendarObjectWithName("1.ics")
- def test_interface(self):
- """
- Interface is completed and conforming.
- """
- try:
- verifyObject(ICalendarObject, self.object1)
- except BrokenMethodImplementation, e:
- self.fail(e)
-
-
def test_init(self):
"""
Ivars are correctly initialized.
@@ -940,3 +898,17 @@
self.object1.organizer(),
"mailto:wsanchez at apple.com"
)
+
+
+
+class FileStorageTests(unittest.TestCase, CommonTests):
+ """
+ File storage tests.
+ """
+
+ def storeUnderTest(self):
+ """
+ Create and return a L{CalendarStore} for testing.
+ """
+ setUpCalendarStore(self)
+ return self.calendarStore
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100518/e1cecc8e/attachment-0001.html>
More information about the calendarserver-changes
mailing list