FAQ - Miscellaneous

Return to FAQ index

1   Testing

1.1   How do I run a particular test from a package?

Go to your $ZOPE3INSTANCE/etc, then:

$ cd $HOME/myzope/etc
$ ../bin/test.py -vpu --dir package/tests test_this_module

Here I assumed $HOME/myzope is your Zope3 instance directory. Replace 'package' with your package name.

1.2   How do I record a session?

You will need to download Shane Hathaways' excellent (and minimal) tcpwatch package. This will log ALL data flowing between client and server for you, and you can use this in developing tests.

To record a session:

$ mkdir record
$ tcpwatch.py -L8081:8080 -r record
# Note: use the "-s" option if you don't need a GUI (Tk).

1.3   How do I test file upload using zope.testbrowser?

Ref: http://mail.zope.org/pipermail/zope3-users/2006-July/003830.html

eg:-

>>> import StringIO
>>> myPhoto = StringIO.StringIO('my photo')
>>> control = user.getControl(name='photoForm.photo')
>>> fileControl = control.mech_control
>>> fileControl.add_file(myPhoto, filename='myPhoto.gif')
>>> user.getControl(name='photoForm.actions.add').click()
>>> imgTag =
'src="http://localhost/++skin++Application/000001/0001/1/photo"'
>>> imgTag in user.contents
True

2   Exceptions, Errors and Debugging

2.1   Why do I see ForbiddenAttribute exceptions/errors?

Ref: http://mail.zope.org/pipermail/zope3-users/2006-August/004027.html

ForbiddenAttribute? are always (ALWAYS!!!) an sign of missing security declarations, or of code accessing stuff it shouldn't. If you're accessing a known method, you're most definitely lacking a security declaration for it.

Zope, by default, is set to deny access for attributes and methods that don't have explicit declarations.

2.2   "order" attribute not in browser:menuItem directive:

Q. I want to add a new view tab in the ZMI to be able to edit object attributes of some objects. So I'm adding a new menuItem in the zmi_views menu via ZCML with:

<browser:menuItem
    action="properties.html"
    for=".mymodule.IMyClass"
    title="properties"
    menu="zmi_views"
    permission="zope.ManageContent"
    order="2" />

(MyClass? is just a derived Folder with custom attributes) The problem is: the new tab always appear in the first place. I would like to put it just after the "content" tab, not before. The "order" directive does not work for that. How can I reorder the tabs so that my new tab appears in the 2nd position?

The default implementation of menus sorts by interface first, and this item is most specific. See zope.app.publisher.browser.menu. If you do not like this behavior, you have to implement your own menu code.

2.3   utf-8 error in i18nfile

Q. Why do I always get an error when I try to add some utf-8 text into an i18nfile? I just add an i18nfile in the ZMI, then I chose a name and I set the contentType to "text/plain;charset=utf-8". If I enter some text with accents like "éà îî", I get a system error which says : UnicodeDecodeError?: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128). I don't get any error with a simple File object.

Okay, I18n file is a demo that is probably not well-developed. Don't use it. I will propose to not distribute it anymore. Noone is using it, so you are on your own finding the problem and providing a patch.

2.4   When running $instance/bin/runzope zlib import error appears?

Ref: http://mail.zope.org/pipermail/zope/2004-November/154739.html

When you compile Python, make sure you have installed zlib development library. In Debian 3.1 (Sarge) it is zlib1g-dev.

2.5   I get a Server Error page when doing something that should work. How do I debug this?

Here's a nicely formatted IRC log detailing how Steve Alexander found a particular bug; it gives lots of good advice on tracking bugs:

http://dev.zope.org/Members/spascoe/HowOneZope3BugWasFixed (Scott Pascoe)

Ken Manheimer wrote up an in-depth account of interactive Zope debugging using the python prompt - it was written for Zope 2, but many of the principles and some of the actual techniques should translate to Zope 3. It's at:

http://www.zope.org/Members/klm/ZopeDebugging

Here is 'Using the Zope Debugger' from the Zope3 docs:

http://svn.zope.org/*checkout*/Zope3/trunk/doc/DEBUG.txt

2.6   I cannot see source when debugging eggified code

When you try to step into eggified code (libraries), you find that the source file referenced is invalid. Closer inspection reveals that the source path referenced has an invalid member like 'tmpXXXXX'.

The fix is easy, but first the reason why this happens:

When you install eggs with easy_install, it creates a temp directory, and byte compiles the python code. Hence, the .pyc files that are generated reference this (working, but temporary) path. Easy_install then copies the entire package into the right place, and so the .pyc files are stuck with invalid references to source files.

To solve this, simply remove all the ".pyc" files from any .egg paths that you have. On Unix, something like:

find . -name "*.pyc" | xargs rm

should do the trick.

2.7   How do I get more details about system errors, in the browser itself?

Ref: http://mail.zope.org/pipermail/zope3-users/2006-November/004881.html

Use the Debug skin via ++skin++Debug or via ++debug++errors (the latter is better if you still want to see your own skin).

2.8   How can I get a postmortem debugger prompt when a request raises an exception?

Edit your zope.conf and change the server type from HTTP (or whatever it is) to PostmortemDebuggingHTTP? or WSGI-PostmortemDebuggingHTTP?.:

<server>
  address 8080
  type PostmortemDebuggingHTTP
</server>

Restart the server in the foreground (you need an attached console to interact with the debugger).:

path/to/instance/control/script stop
path/to/instance/control/script fg

Now, when a request raises an exception, you'll be dropped into a post-mortem debugger at the point of the exception.

3   ZODB

3.1   What version of ZODB does Zope 3 use?

Right now Zope 3 is using ZODB 3. Zope 3.4 is using ZODB 3.8 .

ZODB 4 development has halted indefinitely because of lack of resources to support both versions. However, many ZODB 4 features have been back-ported to ZODB 3.

3.2   How do I use ZODB blob ?

Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2007-11-18.log.html

Create a directory under INSTANCE/var for storing blobs:

$ mkdir var/blobs

Then in your zope.conf change <zodb> definition like this:

<zodb>
  <blobstorage>
    <filestorage>
      path $DATADIR/Data.fs
    </filestorage>
    blob-dir $DATADIR/blobs
  </blobstorage>
</zodb>

The blob-dir specifies where you want to store blobs. You may use z3c.blobfile implementation for storing images and other normal files.

The next time you run your app, new .pyc files with correct references will be created, and presto - you're ok!

3.3   Do you have an example of CRUD (create/read/update/delete)?

Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004248.html

The Zope Object DataBase? (ZODB), available by default to your application, makes CRUD very simple:

Create:

   >>> from recipe import MyFolder, Recipe
   >>> folder = MyFolder()
   >>> recipe = Recipe()
   >>> folder['dead_chicken'] = recipe

Read:

   >>> folder['dead_chicken']
   <worldcookery.recipe.Recipe object at XXX>

Update:

   >>> recipe = folder['dead_chicken']
   >>> recipe.title = u'Dead chicken'
   >>> recipe.description = u'Beat it to death'

Delete:

   >>> del recipe['dead_chicken']

4   Other

4.1   Should I use __docformat___ = 'restructuredtext' in Zope3?

Yes, if you are using ReStructuredText? in docstrings, the default is still structured text.

4.2   Which psycopg works with Zope3?

Zope 3.1 and 3.2 works with Psycopg v1.0.

FIXME: What about Psycopg v2.0 support in 3.3?

4.3   Where is zope.app.workflow?

It has never been released with Zope 3, just as an add-on package. People are now encouraged to use zope.wfmc and zope.app.wfmc. There is also a z3lab extension specifically for document workflows.

Note: also check out the PyPI? site for egg versions.



( 97 subscribers )