This is a functional unit test to demonstrate a bug in sqlos in conjuction with a database registered as local utility. The bug will raise an exception in line 93 when the person container is added to the zodb tree. The added event will call the sqlobject factory to create the items contained in person container. Since sqlos is not capable to access local utilities correctly it will not use the set up local database and instead use the hard coded global utility/databse (in ftesting.zcml). Since there are no tables defined in the global database, a DatabaseError: no such table will show up. First we need to set up some folder structure to set up a site. >>> from zope.app import zapi >>> from zope.app.folder import Folder >>> from zope.app.container.contained import Contained >>> from sqlos.testing.sampleperson import SamplePersonContainer, createTestingTables >>> from zope.app.component import interfaces as componentInterfaces >>> from zope.app.component.site import LocalSiteManager,SiteManagerContainer >>> from sqlos.container import SQLObjectContainer >>> class LocalSitePersonContainer(SamplePersonContainer, SiteManagerContainer, Contained): ... pass >>> root = getRootFolder() >>> testsite = Folder() >>> root['testsite'] = testsite >>> componentInterfaces.ISite.providedBy(testsite) False >>> sm = LocalSiteManager(testsite) >>> testsite.setSiteManager(sm) >>> componentInterfaces.ISite.providedBy(testsite) True Now we set up a local database utility >>> from zope.app.rdb.interfaces import IZopeDatabaseAdapter >>> from zope.app.component.interfaces.registration import ActiveStatus,InactiveStatus >>> from sqlos.testing.testdb import SQLiteda >>> from zope.app.utility import UtilityRegistration >>> dbAdapter = SQLiteda(u'dbi://:memory:') >>> reg = UtilityRegistration('sqlite',IZopeDatabaseAdapter,dbAdapter) >>> default = sm['default'] >>> key = default.registrationManager.addRegistration(reg) >>> zapi.traverse(default.registrationManager, key).status = ActiveStatus >>> localUtility = sm.queryUtility(IZopeDatabaseAdapter,'sqlite') >>> localUtility >>> localUtility is dbAdapter True Ok. Now we have a site in root/testsite with a registered sqlite adapter. We make sure that our localUtility is not identical to the global sqlite utility that has been registered through ftesting.zcml. >>> gsm = zapi.getGlobalSiteManager() >>> globalUtility = gsm.queryUtility(IZopeDatabaseAdapter,'sqlite') >>> globalUtility is not localUtility True Now we populate testsite with data. We do this by using direct SQL, because there is currently no support for local sites in testcode. >>> from zope.component.interfaces import ISiteManager >>> cursor = localUtility().cursor() >>> cursor.execute( ... '''create table dog ( ... id integer primary key, ... fullname varchar(50) not null, ... owner varchar(20) not null)''') >>> cursor.execute( ... '''create table sample_isolated_person ( ... id integer primary key, ... domains text, ... fullname varchar(50) not null, ... username varchar(20) not null, ... password varchar(20) not null)''') >>> cursor.execute( ... '''create table sample_person ( ... id integer primary key, ... fullname varchar(50), ... username varchar(20), ... password varchar(20))''') Now that we have setup database tables we should be able to create the personcontainer without errors. >>> personcontainer = LocalSitePersonContainer() >>> testsite['personcontainer'] = personcontainer >>> localUtility2 = ISiteManager(personcontainer).queryUtility(IZopeDatabaseAdapter,'sqlite') >>> localUtility2 is localUtility True