[Zope-Checkins] CVS: Products/AdaptableStorage/tests - Zope2TestBase.py:1.1 testZope2FS.py:1.13

Shane Hathaway shane@zope.com
Tue, 7 Jan 2003 00:07:44 -0500


Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv22801/tests

Modified Files:
	testZope2FS.py 
Added Files:
	Zope2TestBase.py 
Log Message:
- Added SQLUserList.  All tests pass again.

- Refactored Zope 2 tests to share a common implementation,
Zope2TestBase.


=== Added File Products/AdaptableStorage/tests/Zope2TestBase.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test of storing folders on the filesystem via ZODB

$Id: Zope2TestBase.py,v 1.1 2003/01/07 05:07:40 shane Exp $
"""

from Acquisition import aq_base
from ZODB import Persistent
from Persistence import PersistentMapping
from OFS.Folder import Folder
from OFS.ObjectManager import ObjectManager
from OFS.SimpleItem import SimpleItem
from AccessControl.User import User, UserFolder


class TestFolder(Folder):

    meta_type = 'Zope2FS Test Folder'

    def __init__(self, title):
        self.title = title


class TestObjectManager(ObjectManager):

    meta_type = 'Zope2FS Test ObjectManager'

    def __init__(self, title):
        self.title = title


class TestFile(SimpleItem):

    meta_type = 'Zope2FS Test File'

    def __init__(self, content):
        self.content = content


class Zope2TestBase:

    def testLoad(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            app.getId()
        finally:
            conn.close()

    def testStore(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            app._setObject(f.id, f, set_owner=0)
            get_transaction().commit()

            f2 = Folder()
            f2.id = 'Christmas'
            f._setObject(f2.id, f2, set_owner=0)
            get_transaction().commit()

            f3 = Folder()
            f3.id = 'Eve'
            f2._setObject(f3.id, f3, set_owner=0)
            get_transaction().commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                self.assert_(hasattr(app.Holidays, 'Christmas'))
                self.assert_(hasattr(app.Holidays.Christmas, 'Eve'))
            finally:
                conn2.close()

        finally:
            conn.close()

    def testAnyFolderishStorage(self):
        # Try to store a folderish object of an otherwise unknown class
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            app._setObject(f.id, f, set_owner=0)
            get_transaction().commit()

            f2 = TestFolder("New Year's Eve")
            f2.id = 'NewYear'
            f._setObject(f2.id, f2, set_owner=0)
            get_transaction().commit()

            # Verify the object is in its own database record
            self.assertNotEqual(f2._p_oid, None)
            f2._p_changed = None
            self.assert_(f2._p_changed is None)

            # Verify the ability to load it
            conn2 = self.db.open()
            try:
                app2 = conn2.root()['Application']
                ff = app2.Holidays.NewYear
                self.assertEqual(ff.title, "New Year's Eve")
                self.assertEqual(ff.__class__, TestFolder)
            finally:
                conn2.close()
        finally:
            conn.close()


    def testAnyFolderWithoutPropertiesStorage(self):
        # Try to store a folderish object that does not implement
        # PropertyManager (tests OptionalAspect)
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = TestObjectManager("* Holiday Calendar *")
            f.id = 'Holidays'
            app._setObject(f.id, f, set_owner=0)
            get_transaction().commit()

            # Verify the ability to load it
            conn2 = self.db.open()
            try:
                app2 = conn2.root()['Application']
                ff = app2.Holidays
                self.assertEqual(ff.title, "* Holiday Calendar *")
                self.assertEqual(ff.__class__, TestObjectManager)
            finally:
                conn2.close()
        finally:
            conn.close()


    def testAnyFileishStorage(self):
        # Try to store a fileish object of an otherwise unknown class
        conn = self.db.open()
        try:
            content = 'insert wise expression here'

            app = conn.root()['Application']
            f = TestFile(content)
            f.id = 'testitem'
            app._setObject(f.id, f, set_owner=0)
            get_transaction().commit()

            # Verify the object is in its own database record
            self.assertNotEqual(f._p_oid, None)
            f._p_changed = None
            self.assert_(f._p_changed is None)

            # Verify the ability to load it
            conn2 = self.db.open()
            try:
                app2 = conn2.root()['Application']
                ff = app2.testitem
                self.assertEqual(ff.content, content)
                self.assertEqual(ff.__class__, TestFile)
            finally:
                conn2.close()
        finally:
            conn.close()


    def testStoreProperties(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            f.title = 'Holiday Calendar'
            app._setObject(f.id, f, set_owner=0)
            get_transaction().commit()

            f._setProperty('pi', 3.14, 'float')
            f._setProperty('stuff', ['a', 'bc', 'd'], 'lines')
            get_transaction().commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                got = 0
                for k, v in app.Holidays.propertyItems():
                    if k == 'title':
                        got += 1
                        self.assertEqual(v, 'Holiday Calendar')
                    elif k == 'pi':
                        got += 1
                        self.assertEqual(v, 3.14)
                    elif k == 'stuff':
                        got += 1
                        self.assertEqual(v, ['a', 'bc', 'd'])
                self.assertEqual(got, 3)
            finally:
                conn2.close()

        finally:
            conn.close()


    def testStoreUserFolder(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = UserFolder()
            f.id = 'acl_users'
            app._setObject(f.id, f, set_owner=0)
            f._doAddUser('ned', 'abcdefg', ('Serf', 'Knight', 'King'), ())
            f._doAddUser('joe', '123', ('Geek',), ())
            get_transaction().commit()

            u = f.data['ned']
            self.assertEqual(u._p_oid, 'unmanaged')  # Be sure ZODB sees it
            u.roles = ('Knight', 'King')
            u.domains = ('localhost',)
            del f.data['joe']           # Test user deletion
            get_transaction().commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                ff = app.acl_users
                self.assert_(aq_base(app.__allow_groups__) is aq_base(ff))
                self.assertEqual(len(ff.data), 1)
                user = ff.data['ned']
                self.assertEqual(user.name, 'ned')
                self.assertEqual(user.roles, ('Knight', 'King'))
                self.assertEqual(user.domains, ('localhost',))
                self.assert_(user is not u)
            finally:
                conn2.close()

        finally:
            conn.close()



=== Products/AdaptableStorage/tests/testZope2FS.py 1.12 => 1.13 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.12	Mon Jan  6 18:17:53 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py	Tue Jan  7 00:07:40 2003
@@ -21,45 +21,15 @@
 import unittest
 from tempfile import mktemp
 
-from Acquisition import aq_base
-from ZODB import Persistent
-from Persistence import PersistentMapping
-from OFS.Folder import Folder
-from OFS.ObjectManager import ObjectManager
-from OFS.SimpleItem import SimpleItem
-from AccessControl.User import User, UserFolder
-
 from Products.AdaptableStorage.zodb.ASDB import ASDB
 from Products.AdaptableStorage.zodb.ASStorage import ASStorage
 from Products.AdaptableStorage.zodb.StaticResource import StaticResource
 from Products.AdaptableStorage.Zope2FS import createMapper
 
+from Zope2TestBase import Zope2TestBase, Folder
 
-class TestFolder(Folder):
-
-    meta_type = 'Zope2FS Test Folder'
-
-    def __init__(self, title):
-        self.title = title
-
-
-class TestObjectManager(ObjectManager):
-
-    meta_type = 'Zope2FS Test ObjectManager'
-
-    def __init__(self, title):
-        self.title = title
 
-
-class TestFile(SimpleItem):
-
-    meta_type = 'Zope2FS Test File'
-
-    def __init__(self, content):
-        self.content = content
-
-
-class Zope2FSTests (unittest.TestCase):
+class Zope2FSTests (unittest.TestCase, Zope2TestBase):
 
     def _createMapper(self, path):
         return createMapper(path)
@@ -82,48 +52,8 @@
         self.db.close()
         rmtree(self.path)
 
-    def testLoad(self):
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            app.getId()
-        finally:
-            conn.close()
-
-    def testStore(self):
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            f = Folder()
-            f.id = 'Holidays'
-            app._setObject(f.id, f, set_owner=0)
-            get_transaction().commit()
-
-            f2 = Folder()
-            f2.id = 'Christmas'
-            f._setObject(f2.id, f2, set_owner=0)
-            get_transaction().commit()
-
-            f3 = Folder()
-            f3.id = 'Eve'
-            f2._setObject(f3.id, f3, set_owner=0)
-            get_transaction().commit()
-
-            conn2 = self.db.open()
-            try:
-                app = conn2.root()['Application']
-                self.assert_(hasattr(app, 'Holidays'))
-                self.assert_(hasattr(app.Holidays, 'Christmas'))
-                self.assert_(hasattr(app.Holidays.Christmas, 'Eve'))
-            finally:
-                conn2.close()
-
-        finally:
-            conn.close()
-
     def testClassificationPreservation(self):
-        # Ensure that classification doesn't get forgotten, even though
-        # it's the container that writes it, not the object.
+        # Ensure that classification doesn't get forgotten.
         conn = self.db.open()
         try:
             app = conn.root()['Application']
@@ -149,165 +79,6 @@
                 self.assert_(text.find('meta_type=Folder') >= 0)
         finally:
             conn.close()
-
-
-    def testAnyFolderishStorage(self):
-        # Try to store a folderish object of an otherwise unknown class
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            f = Folder()
-            f.id = 'Holidays'
-            app._setObject(f.id, f, set_owner=0)
-            get_transaction().commit()
-
-            f2 = TestFolder("New Year's Eve")
-            f2.id = 'NewYear'
-            f._setObject(f2.id, f2, set_owner=0)
-            get_transaction().commit()
-
-            # Verify the object is in its own database record
-            self.assertNotEqual(f2._p_oid, None)
-            f2._p_changed = None
-            self.assert_(f2._p_changed is None)
-
-            # Verify the ability to load it
-            conn2 = self.db.open()
-            try:
-                app2 = conn2.root()['Application']
-                ff = app2.Holidays.NewYear
-                self.assertEqual(ff.title, "New Year's Eve")
-                self.assertEqual(ff.__class__, TestFolder)
-            finally:
-                conn2.close()
-        finally:
-            conn.close()
-
-
-    def testAnyFolderWithoutPropertiesStorage(self):
-        # Try to store a folderish object that does not implement
-        # PropertyManager (tests OptionalAspect)
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            f = TestObjectManager("* Holiday Calendar *")
-            f.id = 'Holidays'
-            app._setObject(f.id, f, set_owner=0)
-            get_transaction().commit()
-
-            # Verify the ability to load it
-            conn2 = self.db.open()
-            try:
-                app2 = conn2.root()['Application']
-                ff = app2.Holidays
-                self.assertEqual(ff.title, "* Holiday Calendar *")
-                self.assertEqual(ff.__class__, TestObjectManager)
-            finally:
-                conn2.close()
-        finally:
-            conn.close()
-
-
-    def testAnyFileishStorage(self):
-        # Try to store a fileish object of an otherwise unknown class
-        conn = self.db.open()
-        try:
-            content = 'insert wise expression here'
-
-            app = conn.root()['Application']
-            f = TestFile(content)
-            f.id = 'testitem'
-            app._setObject(f.id, f, set_owner=0)
-            get_transaction().commit()
-
-            # Verify the object is in its own database record
-            self.assertNotEqual(f._p_oid, None)
-            f._p_changed = None
-            self.assert_(f._p_changed is None)
-
-            # Verify the ability to load it
-            conn2 = self.db.open()
-            try:
-                app2 = conn2.root()['Application']
-                ff = app2.testitem
-                self.assertEqual(ff.content, content)
-                self.assertEqual(ff.__class__, TestFile)
-            finally:
-                conn2.close()
-        finally:
-            conn.close()
-
-
-    def testStoreProperties(self):
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            f = Folder()
-            f.id = 'Holidays'
-            f.title = 'Holiday Calendar'
-            app._setObject(f.id, f, set_owner=0)
-            get_transaction().commit()
-
-            f._setProperty('pi', 3.14, 'float')
-            f._setProperty('stuff', ['a', 'bc', 'd'], 'lines')
-            get_transaction().commit()
-
-            conn2 = self.db.open()
-            try:
-                app = conn2.root()['Application']
-                self.assert_(hasattr(app, 'Holidays'))
-                got = 0
-                for k, v in app.Holidays.propertyItems():
-                    if k == 'title':
-                        got += 1
-                        self.assertEqual(v, 'Holiday Calendar')
-                    elif k == 'pi':
-                        got += 1
-                        self.assertEqual(v, 3.14)
-                    elif k == 'stuff':
-                        got += 1
-                        self.assertEqual(v, ['a', 'bc', 'd'])
-                self.assertEqual(got, 3)
-            finally:
-                conn2.close()
-
-        finally:
-            conn.close()
-
-
-    def testStoreUserFolder(self):
-        conn = self.db.open()
-        try:
-            app = conn.root()['Application']
-            f = UserFolder()
-            f.id = 'acl_users'
-            app._setObject(f.id, f, set_owner=0)
-            f._doAddUser('ned', 'abcdefg', ('Serf', 'Knight', 'King'), ())
-            get_transaction().commit()
-
-            u = f.data['ned']
-            self.assertEqual(u._p_oid, 'unmanaged')  # Be sure ZODB sees it
-            u.roles = ('Knight', 'King')
-            get_transaction().commit()
-
-            conn2 = self.db.open()
-            try:
-                app = conn2.root()['Application']
-                ff = app.acl_users
-                self.assert_(aq_base(app.__allow_groups__) is aq_base(ff))
-                self.assert_(len(ff.data) == 1)
-                user = ff.data['ned']
-                self.assertEqual(user.name, 'ned')
-                self.assert_(user.domains == (), repr(user.domains))
-                self.assertEqual(user.roles, ('Knight', 'King'))
-                self.assert_(user is not u)
-            finally:
-                conn2.close()
-
-        finally:
-            conn.close()
-
-
 
 
 class Zope2FSUnderscoreTests (Zope2FSTests):