Author Archive

Layered Functional Tests in Zope3

Testlayers minimize setup costs for functional tests in zope3. One can specify a zcml file which is loaded when a specific suite is run. This reduces startup time for the test a lot compared to functional tests which use the site wide ftesting.zcml configuration file, which may include packages the test don’t need at all.

Steps to set up a layered functional test for your package:

create a ftests.py file in your package directory with the following contents:

from zope.app.testing import functional

functional.defineLayer('TestLayer', 'ftesting.zcml')

def test_suite():
suite = functional.FunctionalDocFileSuite(
'README.txt',
)
suite.layer = TestLayer
return suite

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

Where ‘README.txt’ is a normal REST file which contains the tests.

Then create the ‘ftesting.zcml’ file wher you can do your setup for the specific test.

Here is a basic example which sets up security etc.

<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
<include package="zope.app" />
<include package="zope.app.server" />
<include package="zope.app.authentication" />
<include package="zope.app.securitypolicy" file="meta.zcml" />
<securityPolicy
component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
<include package="zope.app.securitypolicy" />
<!-- we ought to use this for the tests
<include package="zope.app.i18n.tests" />
-->

<role id="zope.Anonymous" title="Everybody"
description="All users have this role implicitly" />
<role id="zope.Manager" title="Site Manager" />
<role id="zope.Member" title="Site Member" />
<grantAll role="zope.Manager" />

<principal
id="zope.manager"
title="Administrator"
login="mgr"
password="mgrpw" />

<grant
role="zope.Manager"
principal="zope.manager"
/>

</configure>

You can now run the test from your instance_home:

./bin/test -fs your.package

Technorati Tags: , ,

Checking out PGStorage on my mac book

Just tested PGStorage with zope2 on my mac book. PGStorage pickles objects into a postgresql database. The huge advantage is that you don’t need zeo or zrs, you can connect multiple zope instances to the same postgres server and use postgres based replication. I uploaded a 600MB+ iso image to my pgstorage based instance and it worked. But i also got some uncatched deadlocks when uploading a huge directory via webdav, hopefully the next release will fix this issues.

Installation on macos x

Use darwinports to install postgres python etc. Get it from here

After installing darwinorts install needed packages:

sudo port install python24 py-psycopg2 postgresql81-server

To create a database instance, after install do:

sudo mkdir -p /opt/local/var/db/postgresql81/defaultdb
sudo chown postgres81:postgres /opt/local/var/db/postgresql81/defaultdb
sudo su postgres81 -c '/opt/local/lib/postgresql81/bin/initdb -D /opt/local/var/db/postgresql81/defaultdb'

Create a new zope instance and edit /path/to/instance/etc/zope.conf and replace the zodb_db main section with this lines:

%import ZODB.PGStorage
<zodb_db main>
  connection-class ZODB.PGStorage.PGConnection
  mount-point /
  <pgstorage>
  </pgstorage>
</zodb_db>

Download PGStorage from http://hathawaymix.org/Software/PGStorage/PGStorage-0.1.tar.gz and extract it to your $SOFTWARE_HOME/lib/python/ZODB. Hm, this is a little bit odd, because you have to write in the zope installation directory.

Start postgres:

sudo su postgres81 -c '/opt/local/lib/postgresql81/bin/postmaster -D /opt/local/var/db/postgresql81/defaultdb'

Create a postgres database and user with the name of the user the zope instance runs as:

su - postgres81
/opt/local/lib/postgresql81/bin/createuser  zopeuser
/opt/local/lib/postgresql81/bin/createdb zopeuser

And now start your instance and enjoy the massive amount of log messages filling up the terminal.

/path/to/instance/bin/zopectl fg

Trying out zope3

Seems that PGStorage does not handle zope3 undo stuff correctly, see my comment on http://hathawaymix.org/Weblog/2006-02-11

Technorati Tags: , , ,