[CalendarServer-changes] [5393] CalendarServer/trunk/txdav/propertystore/test
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 24 20:03:45 PDT 2010
Revision: 5393
http://trac.macosforge.org/projects/calendarserver/changeset/5393
Author: wsanchez at apple.com
Date: 2010-03-24 20:03:45 -0700 (Wed, 24 Mar 2010)
Log Message:
-----------
Add base.py and uncomment tests
Modified Paths:
--------------
CalendarServer/trunk/txdav/propertystore/test/test_none.py
CalendarServer/trunk/txdav/propertystore/test/test_xattr.py
Added Paths:
-----------
CalendarServer/trunk/txdav/propertystore/test/base.py
Added: CalendarServer/trunk/txdav/propertystore/test/base.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/test/base.py (rev 0)
+++ CalendarServer/trunk/txdav/propertystore/test/base.py 2010-03-25 03:03:45 UTC (rev 5393)
@@ -0,0 +1,131 @@
+##
+# 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.
+##
+
+"""
+Generic property store tests.
+"""
+
+__all__ = [
+ "PropertyStoreTest",
+ "propertyName",
+ "propertyValue",
+]
+
+
+from zope.interface.verify import verifyObject, BrokenMethodImplementation
+
+from twisted.trial import unittest
+
+from twext.web2.dav import davxml
+
+from txdav.idav import IPropertyStore
+from txdav.propertystore.base import PropertyName
+
+
+class PropertyStoreTest(unittest.TestCase):
+ # Subclass must define self.propertyStore in setUp().
+
+ def test_interface(self):
+ try:
+ verifyObject(IPropertyStore, self.propertyStore)
+ except BrokenMethodImplementation, e:
+ self.fail(e)
+
+ def test_set_get_contains(self):
+ store = self.propertyStore
+
+ name = propertyName("test")
+ value = propertyValue("Hello, World!")
+
+ store[name] = value
+ self.assertEquals(store.get(name, None), value)
+ self.failUnless(name in store)
+
+ def test_delete_get_contains(self):
+ store = self.propertyStore
+
+ name = propertyName("test")
+ value = propertyValue("Hello, World!")
+
+ store[name] = value
+ del store[name]
+ self.assertEquals(store.get(name, None), None)
+ self.failIf(name in store)
+
+ def test_iteration(self):
+ store = self.propertyStore
+
+ value = propertyValue("Hello, World!")
+
+ names = set(propertyName(str(i)) for i in (1,2,3,4))
+
+ for name in names:
+ store[name] = value
+
+ self.assertEquals(set(store.keys()), names)
+ self.assertEquals(len(store), len(names))
+
+ # FIXME: Not done here
+
+
+
+ def test_flush(self):
+ store = self.propertyStore
+
+ name = propertyName("test")
+ value = propertyValue("Hello, World!")
+
+ #
+ # Set value flushes correctly
+ #
+ store[name] = value
+
+ store.flush()
+ store.abort()
+
+ self.assertEquals(store.get(name, None), value)
+ self.assertEquals(len(store), 1)
+
+ #
+ # Deleted value flushes correctly
+ #
+ del store[name]
+
+ store.flush()
+ store.abort()
+
+ self.assertEquals(store.get(name, None), None)
+ self.assertEquals(len(store), 0)
+
+ def test_abort(self):
+ store = self.propertyStore
+
+ name = propertyName("test")
+ value = propertyValue("Hello, World!")
+
+ store[name] = value
+
+ store.abort()
+
+ self.assertEquals(store.get(name, None), None)
+ self.assertEquals(len(store), 0)
+
+
+def propertyName(name):
+ return PropertyName("http://calendarserver.org/ns/test/", name)
+
+def propertyValue(value):
+ return davxml.ResponseDescription(value)
Modified: CalendarServer/trunk/txdav/propertystore/test/test_none.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/test/test_none.py 2010-03-25 03:02:53 UTC (rev 5392)
+++ CalendarServer/trunk/txdav/propertystore/test/test_none.py 2010-03-25 03:03:45 UTC (rev 5393)
@@ -18,40 +18,40 @@
Property store tests.
"""
-# from txdav.idav import PropertyChangeNotAllowedError
-# from txdav.propertystore.none import PropertyStore
-# from txdav.propertystore.test.base import propertyName, propertyValue
+from txdav.idav import PropertyChangeNotAllowedError
+from txdav.propertystore.none import PropertyStore
+from txdav.propertystore.test.base import propertyName, propertyValue
-# from txdav.propertystore.test import base
+from txdav.propertystore.test import base
-# class PropertyStoreTest(base.PropertyStoreTest):
-# def setUp(self):
-# self.propertyStore = PropertyStore()
+class PropertyStoreTest(base.PropertyStoreTest):
+ def setUp(self):
+ self.propertyStore = PropertyStore()
-# def test_flush(self):
-# store = self.propertyStore
+ def test_flush(self):
+ store = self.propertyStore
-# # Flushing no changes is ok
-# store.flush()
+ # Flushing no changes is ok
+ store.flush()
-# name = propertyName("test")
-# value = propertyValue("Hello, World!")
+ name = propertyName("test")
+ value = propertyValue("Hello, World!")
-# store[name] = value
+ store[name] = value
-# # Flushing changes isn't allowed
-# self.assertRaises(PropertyChangeNotAllowedError, store.flush)
+ # Flushing changes isn't allowed
+ self.assertRaises(PropertyChangeNotAllowedError, store.flush)
-# # Changes are still here
-# self.assertEquals(store.get(name, None), value)
+ # Changes are still here
+ self.assertEquals(store.get(name, None), value)
-# # Flushing no changes is ok
-# del store[name]
-# store.flush()
+ # Flushing no changes is ok
+ del store[name]
+ store.flush()
-# self.assertEquals(store.get(name, None), None)
+ self.assertEquals(store.get(name, None), None)
-# def test_abort(self):
-# super(PropertyStoreTest, self).test_abort()
-# self.assertEquals(self.propertyStore.modified, {})
+ def test_abort(self):
+ super(PropertyStoreTest, self).test_abort()
+ self.assertEquals(self.propertyStore.modified, {})
Modified: CalendarServer/trunk/txdav/propertystore/test/test_xattr.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/test/test_xattr.py 2010-03-25 03:02:53 UTC (rev 5392)
+++ CalendarServer/trunk/txdav/propertystore/test/test_xattr.py 2010-03-25 03:03:45 UTC (rev 5393)
@@ -18,44 +18,45 @@
Property store tests.
"""
-# from twext.python.filepath import FilePath
+from twext.python.filepath import FilePath
-# from txdav.propertystore.base import PropertyName
-# from txdav.propertystore.test.base import propertyName
+from txdav.propertystore.base import PropertyName
+from txdav.propertystore.test.base import propertyName
-# from txdav.propertystore.test import base
+from txdav.propertystore.test import base
-# try:
-# from txdav.propertystore.xattr import PropertyStore
-# from xattr import xattr
-# except ImportError, e:
-# PropertyStore = None
-# importErrorMessage = str(e)
+try:
+ from txdav.propertystore.xattr import PropertyStore
+ from xattr import xattr
+except ImportError, e:
+ PropertyStore = None
+ importErrorMessage = str(e)
-# class PropertyStoreTest(base.PropertyStoreTest):
-# def setUp(self):
-# tempDir = FilePath(self.mktemp())
-# tempDir.makedirs()
-# tempFile = tempDir.child("test")
-# tempFile.touch()
-# self.propertyStore = PropertyStore(tempFile)
+class PropertyStoreTest(base.PropertyStoreTest):
+ def setUp(self):
+ tempDir = FilePath(self.mktemp())
+ tempDir.makedirs()
+ tempFile = tempDir.child("test")
+ tempFile.touch()
+ self.propertyStore = PropertyStore(tempFile)
-# def test_init(self):
-# store = self.propertyStore
-# self.failUnless(isinstance(store.attrs, xattr))
-# self.assertEquals(store.removed, set())
-# self.assertEquals(store.modified, {})
+ def test_init(self):
+ store = self.propertyStore
+ self.failUnless(isinstance(store.attrs, xattr))
+ self.assertEquals(store.removed, set())
+ self.assertEquals(store.modified, {})
-# def test_abort(self):
-# super(PropertyStoreTest, self).test_abort()
-# store = self.propertyStore
-# self.assertEquals(store.removed, set())
-# self.assertEquals(store.modified, {})
+ def test_abort(self):
+ super(PropertyStoreTest, self).test_abort()
+ store = self.propertyStore
+ self.assertEquals(store.removed, set())
+ self.assertEquals(store.modified, {})
-# if PropertyStore is None:
-# PropertyStoreTest.skip = importErrorMessage
+if PropertyStore is None:
+ PropertyStoreTest.skip = importErrorMessage
-# def propertyName(name):
-# return PropertyName("http://calendarserver.org/ns/test/", name)
+
+def propertyName(name):
+ return PropertyName("http://calendarserver.org/ns/test/", name)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100324/51c4d294/attachment.html>
More information about the calendarserver-changes
mailing list