[Zope-CVS] CVS: Products/AdaptableStorage/gateway_sql/tests - testZope2SQL.py:1.4.2.1
Christian Zagrodnick
cz@gocept.com
Mon, 13 Jan 2003 14:16:11 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_sql/tests
In directory cvs.zope.org:/tmp/cvs-serv19124/tests
Modified Files:
Tag: zagy-patches
testZope2SQL.py
Log Message:
merging HEAD into zagy-patches branch
=== Products/AdaptableStorage/gateway_sql/tests/testZope2SQL.py 1.4 => 1.4.2.1 ===
--- Products/AdaptableStorage/gateway_sql/tests/testZope2SQL.py:1.4 Fri Jan 3 17:04:20 2003
+++ Products/AdaptableStorage/gateway_sql/tests/testZope2SQL.py Mon Jan 13 14:16:09 2003
@@ -11,45 +11,30 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Test of storing folders in a Postgres database via ZODB
+"""Test of storing objects in relational databases via ZODB
$Id$
"""
-import os
import unittest
-from ZODB import Persistent
-from Persistence import PersistentMapping
-from OFS.Folder import Folder
-from OFS.SimpleItem import SimpleItem
-
+from Products.AdaptableStorage.gateway_sql.public import PsycopgConnection
from Products.AdaptableStorage.zodb.ASDB import ASDB
from Products.AdaptableStorage.zodb.ASStorage import ASStorage
from Products.AdaptableStorage.zodb.StaticResource import StaticResource
-from Products.AdaptableStorage.Zope2SQL import createMapperPlus
-
-
-class TestFolder(Folder):
-
- meta_type = 'Zope2SQL Test Folder'
+from Products.AdaptableStorage.Zope2SQL import createSQLMapper
- def __init__(self, title):
- self.title = title
+from Products.AdaptableStorage.tests.Zope2TestBase import Zope2TestBase
-class TestFile(SimpleItem):
+class Zope2SQLTests (unittest.TestCase, Zope2TestBase):
- meta_type = 'Zope2SQL Test File'
-
- def __init__(self, content):
- self.content = content
-
-
-class Zope2SQLTests (unittest.TestCase):
+ def openConnection(self):
+ return PsycopgConnection('', 'test_temp')
def setUp(self):
- dm, conns, gws = createMapperPlus('', 'test_temp')
+ conn = self.openConnection()
+ dm, conns, gws = createSQLMapper(conn)
self.dm = dm
self.conns = conns
self.gws = gws
@@ -69,146 +54,6 @@
def tearDown(self):
self.clear()
self.db.close()
-
- 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 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()
-
if __name__ == '__main__':