[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/RDB/tests - testDSNParser.py:1.1 testSQLCommand.py:1.1 testZopeDatabaseAdapter.py:1.1 testRow.py:1.2 testZopeConnection.py:1.2

Stephan Richter srichter@cbu.edu
Wed, 10 Jul 2002 19:37:27 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB/tests
In directory cvs.zope.org:/tmp/cvs-serv2804/tests

Modified Files:
	testRow.py testZopeConnection.py 
Added Files:
	testDSNParser.py testSQLCommand.py testZopeDatabaseAdapter.py 
Log Message:
Finished the initial implementation of the RDB package. The only thing left
is the TypeInfoConverter, which I have not yet attacked.


=== Added File Zope3/lib/python/Zope/App/RDB/tests/testDSNParser.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""
$Id: testDSNParser.py,v 1.1 2002/07/10 23:37:26 srichter Exp $
"""
import unittest
from Zope.App.RDB.ZopeDatabaseAdapter import parseDSN


class TestDSNParser(unittest.TestCase):

    def testDBNameOnly(self):
        dsn = 'dbi://test'
        result = {'parameters': {}, 'dbname': 'test', 'username': '',
                  'password': '', 'host': '', 'port': ''}
        self.assertEqual(result, parseDSN(dsn))

    def testDBNameAndParams(self):
        dsn = 'dbi://test;param1=value1;param2=value2'
        result = {'parameters': {'param1': 'value1', 'param2': 'value2'},
                  'dbname': 'test', 'username': '', 'password': '',
                  'host': '', 'port': ''}
        self.assertEqual(result, parseDSN(dsn))

    def testUserPassword(self):
        dsn = 'dbi://mike:muster/test'
        result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
                  'password': 'muster', 'host': '', 'port': ''}
        self.assertEqual(result, parseDSN(dsn))

    def testUserPasswordAndParams(self):
        dsn = 'dbi://mike:muster/test;param1=value1;param2=value2'
        result = {'parameters': {'param1': 'value1', 'param2': 'value2'},
                  'dbname': 'test', 'username': 'mike', 'password': 'muster',
                  'host': '', 'port': ''}
        self.assertEqual(result, parseDSN(dsn))

    def testAllOptions(self):
        dsn = 'dbi://mike:muster@bohr:5432/test'
        result = {'parameters': {}, 'dbname': 'test', 'username': 'mike',
                  'password': 'muster', 'host': 'bohr', 'port': '5432'}
        self.assertEqual(result, parseDSN(dsn))

    def testAllOptionsAndParams(self):
        dsn = 'dbi://mike:muster@bohr:5432/test;param1=value1;param2=value2'
        result = {'parameters': {'param1': 'value1', 'param2': 'value2'},
                  'dbname': 'test', 'username': 'mike', 'password': 'muster',
                  'host': 'bohr', 'port': '5432'}
        self.assertEqual(result, parseDSN(dsn))

    def testFailures(self):
        self.assertRaises(AssertionError, parseDSN, None)
        self.assertRaises(AssertionError, parseDSN, 'dfi://')

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestDSNParser))
    return suite

if __name__ == '__main__':
    unittest.TextTestRunner().run(test_suite())



=== Added File Zope3/lib/python/Zope/App/RDB/tests/testSQLCommand.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""
$Id: testSQLCommand.py,v 1.1 2002/07/10 23:37:26 srichter Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from Zope.App.RDB.SQLCommand import SQLCommand
from Zope.App.RDB.IConnectionService import IConnectionService
from Zope.App.RDB.IZopeConnection import IZopeConnection
from Zope.App.RDB.IZopeCursor import IZopeCursor
import Zope.ComponentArchitecture
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture.GlobalServiceManager import \
     serviceManager as sm


# Make spme fixes, so that we overcome some of the natural ZODB properties
def getNextServiceManager(context):
    return sm

class CursorStub:

    __implements__ = IZopeCursor

    description = (('id', 'int'),)

    def execute(self, operation, parameters=None):
        self.result = {"SELECT id FROM Table": ((1,),)}[operation]

    def fetchall(self):
        return self.result


class ConnectionStub:

    __implements__ = IZopeConnection

    def cursor(self):
        return CursorStub()


class ConnectionServiceStub:

    __implements__ = IConnectionService

    def getConnection(self, name):
        return ConnectionStub()


class Test(TestCase, PlacelessSetup):


    def setUp(self):
        PlacelessSetup.setUp(self)
        sm.defineService('ConnectionService', IConnectionService)
        sm.provideService('ConnectionService', ConnectionServiceStub())
        self._old_getNextServiceManager = \
                              Zope.ComponentArchitecture.getNextServiceManager
        Zope.ComponentArchitecture.getNextServiceManager = \
                              getNextServiceManager

    def tearDown(self):
        Zope.ComponentArchitecture.getNextServiceManager = \
                              self._old_getNextServiceManager


    def testSimpleSQLCommand(self):
        command = SQLCommand("my_connection", "SELECT id FROM Table")
        result = command()
        self.assertEqual(result.names, ('id',))
        self.assertEqual(result[0].id, 1)


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')





=== Added File Zope3/lib/python/Zope/App/RDB/tests/testZopeDatabaseAdapter.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""
$Id: testZopeDatabaseAdapter.py,v 1.1 2002/07/10 23:37:26 srichter Exp $
"""
import unittest
from Zope.App.RDB.ZopeDatabaseAdapter import ZopeDatabaseAdapter
from Zope.App.RDB.ZopeConnection import ZopeConnection

class ConnectionStub:

    def close(self):
        pass


class DAStub(ZopeDatabaseAdapter):

    def _connection_factory(self):
        return ConnectionStub()


class TestZopeDatabaseAdapter(unittest.TestCase):

    def setUp(self):
        self._da = DAStub('dbi://test')
    
    def testSetGetDSN(self):
        da = self._da
        da.setDSN('dbi://foo')
        self.assertEqual('dbi://foo', da.dsn)
        self.assertEqual('dbi://foo', da.getDSN())

    def testConnect(self):
        da = self._da
        da.connect()
        self.assertEqual(ZopeConnection, da._v_connection.__class__)

    def testDisconnect(self):
        da = self._da
        da.disconnect()
        self.assertEqual(None, da._v_connection)

    def testIsConnected(self):
        da = self._da
        da.connect()
        self.assertEqual(1, da.isConnected())
        da.disconnect()
        self.assertEqual(0, da.isConnected())

    def testCall(self):
        da = self._da
        conn = da()
        self.assertEqual(ZopeConnection, conn.__class__)


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestZopeDatabaseAdapter))
    return suite

if __name__ == '__main__':
    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/App/RDB/tests/testRow.py 1.1 => 1.2 ===
 $Id$
 """
 
-from Zope.App.RDB.Row import row_class_factory
+from Zope.App.RDB.Row import RowClassFactory
 from Zope.Security.Proxy import ProxyFactory
 from Zope.Exceptions import ForbiddenAttribute
 
@@ -31,7 +31,7 @@
         columns = ('food', 'name')
         data = ('pizza', 'john')
         
-        klass = row_class_factory(columns)
+        klass = RowClassFactory(columns)
         ob = klass(data)
         
         self.failUnless(ob.food == 'pizza',
@@ -45,7 +45,7 @@
         columns = ('type', 'speed')
         data = ('airplane', '800km')
         
-        klass = row_class_factory(columns)
+        klass = RowClassFactory(columns)
 
         ob = klass(data)
 


=== Zope3/lib/python/Zope/App/RDB/tests/testZopeConnection.py 1.1 => 1.2 ===
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""XXX short summary goes here.
-
-XXX longer description goes here.
-
+"""
 $Id$
 """
 
@@ -69,7 +66,3 @@
 
 if __name__=='__main__':
     main(defaultTest='test_suite')
-
-
-
-