[Zope-CVS] CVS: Packages/GadflyDA/tests - __init__.py:1.1 testAdapter.py:1.1

Albertas Agejevas alga@codeworks.lt
Wed, 7 Aug 2002 06:54:19 -0400


Update of /cvs-repository/Packages/GadflyDA/tests
In directory cvs.zope.org:/tmp/cvs-serv15715/tests

Added Files:
	__init__.py testAdapter.py 
Log Message:
Initial implementation of Gadfly DA.
Includes the patched gadfly version from Zope 2 ZGadflyDA

=== Added File Packages/GadflyDA/tests/__init__.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.
# 
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: __init__.py,v 1.1 2002/08/07 10:54:18 alga Exp $
"""


=== Added File Packages/GadflyDA/tests/testAdapter.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.
#
##############################################################################
"""Gadfly database adapter unit tests.

$Id: testAdapter.py,v 1.1 2002/08/07 10:54:18 alga Exp $
"""

import os
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.GadflyDA.Adapter import GadflyAdapter
from Zope.App.RDB.ZopeDatabaseAdapter import DatabaseAdapterError

class TestGadflyAdapter(TestCase):
    def test__connection_factory_nonexistent(self):
        "Should raise an exception on nonexistent dirs."
        a = GadflyAdapter("dbi://demo;dir=nonexistent")
        self.assertRaises(DatabaseAdapterError, a._connection_factory)

    def test__connection_factory_bad_dsn(self):
        "Should raise an exception on nonexistent d"
        a = GadflyAdapter("dbi://user:pass/demo;dir=nonexistent")
        self.assertRaises(DatabaseAdapterError, a._connection_factory)

        a = GadflyAdapter("dbi://localhost:1234/demo;dir=nonexistent")
        self.assertRaises(DatabaseAdapterError, a._connection_factory)

class TestGadflyAdapterNew(TestCase):
    def test__connection_factory_create(self):
        "Should create a database if the directory is empty."
        
        a = GadflyAdapter("dbi://demo;dir=test")
        conn = a._connection_factory()
        conn.rollback()         # is it really a connection?

    def test__connection_factory_existing(self):
        "Should fail gracefully if the directory is a file."

        open("gadfly/regular", "w").close()
        a = GadflyAdapter("dbi://demo;dir=regular")
        self.assertRaises(DatabaseAdapterError, a._connection_factory)

    def setUp(self):
        "Create a directory for the database"
        try: os.mkdir("gadfly")
        except: pass
        os.mkdir("gadfly/test")

    def tearDown(self):
        "Remove the files and directories created"
        try: os.unlink("gadfly/test/demo.gfd")
        except: pass
        os.rmdir("gadfly/test")
        try: os.unlink("gadfly/regular")
        except: pass
        

class TestGadflyAdapterDefault(TestCase):
    def test__connection_factory_create(self):
        "Should create a database if the directory is empty."
        
        a = GadflyAdapter("dbi://demo")
        conn = a._connection_factory()
        conn.rollback()         # is it really a connection?

    def test__connection_factory_reopen(self):
        "Should open an existing database"
        
        a = GadflyAdapter("dbi://demo")
        conn = a._connection_factory()
        conn.rollback()         # is it really a connection?
        conn.close()

        conn = a._connection_factory() 
        conn.rollback()         # is it really a connection?


    def setUp(self):
        "Create a directory for the database"
        try: os.mkdir("gadfly")
        except: pass
        os.mkdir("gadfly/demo")

    def tearDown(self):
        "Remove the files and directories created"
        try: os.unlink("gadfly/demo/demo.gfd")
        except: pass
        os.rmdir("gadfly/demo")
        

def test_suite():
    return TestSuite((
        makeSuite(TestGadflyAdapter),
        makeSuite(TestGadflyAdapterNew),
        makeSuite(TestGadflyAdapterDefault),
        ))

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