Update Five to release 1.0.1.

parent 2dd2cf21
......@@ -2,11 +2,44 @@
Five Changes
============
Five 1.0 (2005-04-27)
=====================
Five 1.0.1 (2005-05-31)
=======================
This version is also included in Zope 2.8.
* Changed license headers to the ones used in the Zope.org repository.
This makes merging between the main development line of Five (hosted
on codespeak.net) and the version integrated into Zope 2.8 much
easier. The actual copyright ownership isn't affected because Five
had been contributed to the Zope project anyway (which was blessed
by all Five contributors).
* Made automatically generated add and edit forms unicode-aware.
ZPublisher does not automatically decode incoming form values to
unicode, so AddView and EditView emulate this behaviour themselves
now. They also take care of setting the right charset on the
outgoing form so that ZPublisher will encode it accordingly when
sending the response to the client. (In Zope 3, all charset
negotation between the client and the server takes place in the
publisher.)
* Added ``IHTTPCharset`` adapter for ``IHTTPRequest`` so that
application can find out the preferred character set of the HTTP
client (Zope 2 applications needs to take care of their own charset
header). The adapter is used for the automatically-generated forms
when determining encodings for unicode field content.
* Modified edit.pt to make sure editforms have only one body tag.
* Fixed the ``INameChooser`` adapter for ObjectManagers (e.g. Zope 2
folders) and added unit tests.
* Fixed small bug in BrowserDefault which caused an error if the class is
defaultViewable but the object's interfaces have no defaultView.
Five 1.0 (2005-04-27)
=====================
Features
--------
......
......@@ -27,6 +27,8 @@ Five contributors
- Dieter Maurer (dieter@handshake.de)
- Yvo Schubbe (y.2005-@wcm-solutions.de)
Thank you
---------
......
......@@ -43,7 +43,7 @@ For more information, see ``doc/features.txt``.
How to install Five
-------------------
Five should already be installed in Zope 2.8.
See ``INSTALL.txt``.
How to use Five
---------------
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Utils to be reused
$Id: ReuseUtils.py 12912 2005-05-31 09:58:59Z philikon $
"""
from new import function
def rebindFunction(f,rebindDir=None,**rebinds):
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Trusted expression
$Id: TrustedExpression.py 12912 2005-05-31 09:58:59Z philikon $
"""
from sys import modules
from Products.PageTemplates.PythonExpr import PythonExpr
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Initialize the Five product
$Id: __init__.py 10829 2005-04-18 19:18:27Z philikon $
$Id: __init__.py 12915 2005-05-31 10:23:19Z philikon $
"""
import Acquisition
from Globals import INSTANCE_HOME
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -65,7 +66,11 @@ class BasicAdding(Implicit, BrowserView):
name = chooser.chooseName(self.contentName or '', content)
elif name == '':
name = chooser.chooseName('', content)
chooser.checkName(name, container)
else:
# Invoke the name chooser even when we have a
# name. It'll do useful things with it like converting
# the incoming unicode to an ASCII string.
name = chooser.chooseName(name, container)
content.id = name
container._setObject(name, content)
......@@ -210,14 +215,27 @@ class ObjectManagerNameChooser:
self.context = context
def checkName(self, name, object):
# ObjectManager can only deal with ASCII names. Specially
# ObjectManager._checkId can only deal with strings.
try:
name = name.encode('ascii')
except UnicodeDecodeError:
raise UserError, "Id must contain only ASCII characters."
try:
self.context._checkId(name, allow_dup=False)
except BadRequest:
raise UserError, "Id is in use or invalid"
except BadRequest, e:
msg = ' '.join(e.args) or "Id is in use or invalid"
raise UserError, msg
def chooseName(self, name, object):
if not name:
name = object.__class__.__name__
else:
try:
name = name.encode('ascii')
except UnicodeDecodeError:
raise UserError, "Id must contain only ASCII characters."
dot = name.rfind('.')
if dot >= 0:
......@@ -227,18 +245,17 @@ class ObjectManagerNameChooser:
suffix = ''
n = name + suffix
i = 1
i = 0
while True:
i += 1
try:
container._getOb(n)
self.context._getOb(n)
except AttributeError:
pass
else:
break
i += 1
n = name + '-' + str(i) + suffix
# Make sure tha name is valid. We may have started with something bad.
# Make sure the name is valid. We may have started with
# something bad.
self.checkName(n, object)
return n
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,9 +13,8 @@
##############################################################################
""" Z2 -> Z3 bridge utilities.
$Id$
$Id: bridge.py 12915 2005-05-31 10:23:19Z philikon $
"""
from Interface._InterfaceClass import Interface as Z2_InterfaceClass
from Interface import Interface as Z2_Interface
from Interface import Attribute as Z2_Attribute
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,9 +13,8 @@
##############################################################################
"""Provide basic browser functionality
$Id: browser.py 10829 2005-04-18 19:18:27Z philikon $
$Id: browser.py 12915 2005-05-31 10:23:19Z philikon $
"""
# python
import sys
from datetime import datetime
......@@ -32,6 +32,9 @@ from interfaces import ITraversable
from zope.interface import implements
from zope.component import getViewProviding
from zope.app.traversing.browser.interfaces import IAbsoluteURL
from zope.publisher.browser import isCGI_NAME
from zope.i18n.interfaces import IUserPreferredCharsets
from zope.app.location.interfaces import ILocation
from zope.app.location import LocationProxy
from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges
......@@ -128,6 +131,7 @@ class EditView(BrowserView):
errors = ()
update_status = None
label = ''
charsets = None
# Fall-back field names computes from schema
fieldNames = property(lambda self: getFieldNamesInOrder(self.schema))
......@@ -136,6 +140,8 @@ class EditView(BrowserView):
def __init__(self, context, request):
BrowserView.__init__(self, context, request)
self._processInputs()
self._setPageEncoding()
self._setUpWidgets()
def _setUpWidgets(self):
......@@ -148,6 +154,36 @@ class EditView(BrowserView):
setUpEditWidgets(self, self.schema, source=self.adapted,
names=self.fieldNames)
# taken from zope.publisher.browser.BrowserRequest
def _decode(self, text):
"""Try to decode the text using one of the available charsets."""
if self.charsets is None:
envadapter = IUserPreferredCharsets(self.request)
self.charsets = envadapter.getPreferredCharsets() or ['utf-8']
for charset in self.charsets:
try:
text = unicode(text, charset)
break
except UnicodeError:
pass
return text
def _processInputs(self):
request = self.request
for name, value in request.form.items():
if (not (isCGI_NAME(name) or name.startswith('HTTP_'))
and isinstance(value, str)):
request.form[name] = self._decode(value)
def _setPageEncoding(self):
"""Set the encoding of the form page via the Content-Type header.
ZPublisher uses the value of this header to determine how to
encode unicode data for the browser."""
envadapter = IUserPreferredCharsets(self.request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
self.request.RESPONSE.setHeader(
'Content-Type', 'text/html; charset=%s' % charsets[0])
def setPrefix(self, prefix):
for widget in self.widgets():
widget.setPrefix(prefix)
......@@ -183,7 +219,7 @@ class EditView(BrowserView):
except WidgetsError, errors:
self.errors = errors
status = "An error occured."
transaction.get().abort()
transaction.abort()
else:
setUpEditWidgets(self, self.schema, source=self.adapted,
ignoreStickyValues=True,
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -15,7 +16,7 @@
Directives to emulate the 'http://namespaces.zope.org/browser'
namespace in ZCML known from zope.app.
$Id: browserconfigure.py 11479 2005-04-26 13:47:37Z dreamcatcher $
$Id: browserconfigure.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os
......
......@@ -7,6 +7,7 @@
<include file="interfaces.zcml" />
<include file="permissions.zcml" />
<include file="browser.zcml" />
<include file="i18n.zcml" />
<include package="zope.app.traversing" />
<include package="zope.app.form.browser" />
......
......@@ -32,8 +32,12 @@ system for us all.
Download
--------
2005-04-27 -- We have released Five 1.0! This is also the version that
will be included in Zope 2.8. Download it here:
2005-05-31 -- We have released Five 1.0.1! This is also the version
that will be included in Zope 2.8. Download it here:
http://codespeak.net/z3/five/release/Five-1.0.1.tgz
2005-04-27 -- We have released Five 1.0! Download it here:
http://codespeak.net/z3/five/release/Five-1.0.tgz
......
<tal:tag condition="view/update"/>
<html metal:use-macro="context/@@standard_macros/page">
<body metal:fill-slot="body">
<body>
<div metal:fill-slot="body">
<div metal:define-macro="body">
......@@ -59,6 +60,8 @@
</form>
</div>
</div>
</body>
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -14,9 +15,8 @@
Use 'structured monkey patching' to enable zope.app.container event sending for
Zope 2 objects.
$Id: eventconfigure.py 10337 2005-04-05 16:01:21Z philikon $
$Id: eventconfigure.py 12915 2005-05-31 10:23:19Z philikon $
"""
from Products.Five.fiveconfigure import isFiveMethod
from zope.event import notify
from zope.interface import implements
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -14,7 +15,7 @@
These directives are specific to Five and have no equivalents in Zope 3.
$Id: fiveconfigure.py 8255 2005-01-13 14:05:46Z regebro $
$Id: fiveconfigure.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Five ZCML directive schemas
$Id: fivedirectives.py 8255 2005-01-13 14:05:46Z regebro $
$Id: fivedirectives.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import Interface
from zope.app.publisher.browser.metadirectives import IBasicResourceInformation
......
<configure xmlns="http://namespaces.zope.org/zope">
<adapter
factory="zope.publisher.http.HTTPCharsets"
for="zope.publisher.interfaces.http.IHTTPRequest"
provides="zope.i18n.interfaces.IUserPreferredCharsets"
/>
</configure>
##############################################################################
#
# Copyright (c) 2000-2003 Zope Corporation and Contributors.
# Copyright (c) 2004 Five Contributors.
# All Rights Reserved.
# Copyright (c) 2000-2005 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -14,7 +12,7 @@
##############################################################################
"""Five interfaces
$Id: interfaces.py 12029 2005-05-06 17:04:32Z yuppie $
$Id: interfaces.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import Interface, Attribute
from zope.interface.interfaces import IInterface
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Generic Components ZCML Handlers
$Id: metaconfigure.py 5287 2004-06-25 11:42:27Z philikon $
$Id: metaconfigure.py 12915 2005-05-31 10:23:19Z philikon $
"""
from types import ModuleType
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,8 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
'''A 'PageTemplateFile' without security restrictions.'''
"""A 'PageTemplateFile' without security restrictions.
$Id: pagetemplatefile.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
# Zope 2
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -14,7 +15,6 @@
$Id: browser.py 5259 2004-06-23 15:59:52Z philikon $
"""
import os
import urllib
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Five security handling
$Id: security.py 8281 2005-01-14 18:20:18Z regebro $
$Id: security.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import implements
from zope.component import queryUtility, getUtility
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -13,7 +14,7 @@
"""Use structured monkey-patching to enable ``ISized`` adapters for
Zope 2 objects.
$Id: sizeconfigure.py 10365 2005-04-06 13:24:16Z philikon $
$Id: sizeconfigure.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.app.size.interfaces import ISized
from Products.Five.fiveconfigure import isFiveMethod
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Mimick the Zope 3 skinning system in Five.
$Id: skin.py 10830 2005-04-18 19:22:49Z philikon $
$Id: skin.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface.common.mapping import IItemMapping
from zope.interface import implements
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
# import this
============
Adding tests
============
ObjectManagerNameChooser
------------------------
First we need to import and setup some prerequisites:
>>> from zope.app.container.interfaces import INameChooser
>>> from Products.Five.tests.products.FiveTest.helpers import \
... manage_addFiveTraversableFolder
>>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
>>> chooser = INameChooser(self.folder)
Now we can start. ``INameChooser`` defines a ``checkName()`` method
that checks whether a given name is valid in the container or not.
Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
the object manager. Valid names/ids are those that aren't in use yet
and don't contain invalid characters.
>>> chooser.checkName('abc', object())
>>> chooser.checkName('testoid', object())
Traceback (most recent call last):
...
UserError: The id "testoid" is invalid - it is already in use.
>>> chooser.checkName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
``INameChooser`` also promises us a ``chooseName()`` method that
chooses a name for us in case we don't have one or that chooses a
different name in case the one we chose was invalid.
>>> chooser.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
>>> chooser.chooseName('abc', self.folder.testoid)
'abc'
>>> chooser.chooseName('testoid', self.folder.testoid)
'testoid-1'
Of course, if we start out with something bad, it isn't going to
become good automagically:
>>> chooser.chooseName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Dummy objects and views for the security tests
$Id: dummy.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import Interface, implements
from Products.Five import BrowserView
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Five test fixtures.
$Id: fivetest.py 12915 2005-05-31 10:23:19Z philikon $
"""
# ZopeTestCase was not designed to run tests as part of the
# Zope test suite proper. In particular, it intercepts product
# installation. We have to work around this for the Five tests
......
Testing forms
=============
Before we can begin, we need to setup a traversable folder.
Otherwise, Five won't get to to do its view lookup:
>>> from Products.Five.tests.products.FiveTest.helpers import \
... manage_addFiveTraversableFolder
>>> manage_addFiveTraversableFolder(self.folder, 'ftf')
Add forms
---------
We can add objects to containers (object managers) through add forms.
An unprotected form can be accessed with anonymously:
>>> print http(r"""
... GET /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
... """, handle_errors=False)
HTTP/1.1 200 OK
...
For a protected one we need a manager account:
>>> print http(r"""
... GET /test_folder_1_/ftf/+/protectedaddform.html HTTP/1.1
... Authorization: Basic manager:r00t
... """, handle_errors=False)
HTTP/1.1 200 OK
...
otherwise we will fail to access it:
>>> print http(r"""
... GET /test_folder_1_/ftf/+/protectedaddform.html HTTP/1.1
... Authorization: Basic viewer:secret
... """, handle_errors=False)
HTTP/1.1 401 Unauthorized
...
Now let's add a piece of our sample content object to test more things
on it:
>>> print http(r"""
... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
... Authorization: Basic manager:r00t
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 527
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... title
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Add
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="add_input_name"
...
... edittest
... -----------------------------968064918930967154199105236--
... """, handle_errors=False)
HTTP/1.1 302 Moved Temporarily
...
Location: http://localhost/test_folder_1_/ftf/manage_main
...
Having added this piece of content, we can access it under its URL:
>>> print http(r"""
... GET /test_folder_1_/ftf/edittest HTTP/1.1
... Authorization: Basic manager:r00t
... """, handle_errors=False)
HTTP/1.1 200 OK
...
We can also verify that the title was set correctly, and the not
specified attribute is the default value:
>>> edittest = self.folder.ftf.edittest
>>> edittest.title
u'title'
>>> edittest.description #XXX shouldn't we get a u'' here???
Edit forms
----------
First, it's important to note that forms validate user input.
Therefore, if we specify invalid data, our object won't change:
>>> print http(r"""
... POST /test_folder_1_/ftf/edittest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... BarDescription
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Change
... -----------------------------968064918930967154199105236--
... """, handle_errors=False)
HTTP/1.1 200 OK
...
There are <strong>1</strong> input errors.
...
We will see that nothing has changed:
>>> edittest.title
u'title'
>>> edittest.description #XXX shouldn't we get a u'' here???
However, when we specify the correct fields:
>>> print http(r"""
... POST /test_folder_1_/ftf/edittest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 426
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... FooTitle
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... FooDescription
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Change
... -----------------------------968064918930967154199105236--
... """, handle_errors=False)
HTTP/1.1 200 OK
...
We will see that nothing has changed:
>>> edittest.title
u'FooTitle'
>>> edittest.description
u'FooDescription'
Unicode-safety of forms
-----------------------
Even though ZPublisher does not support unicode, automatically
generated forms do. In the following we will enter the following two
chinese sequences (How do you do? and I'm doing good) in forms
(they're encoded in UTF-8 here):
>>> ni_hao = '\xe4\xbd\xa0\xe5\xa5\xbd'
>>> wo_hen_hao = '\346\210\221\345\276\210\345\245\275'
First, it's imaginable that we make a mistake and enter one of the
phrases in the integer field:
>>> print http(r"""
... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... ChineseTitle
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... ChineseDescription
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Add
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="add_input_name"
...
... unicodetest
... -----------------------------968064918930967154199105236--
... """ % ni_hao, handle_errors=False)
HTTP/1.1 200 OK
...
There are <strong>1</strong> input errors.
...
When we enter the unicode data in the right fields (the text fields),
the form will submit correctly and create the object:
>>> print http(r"""
... POST /test_folder_1_/ftf/+/addfieldcontent.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... 0
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Add
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="add_input_name"
...
... unicodetest
... -----------------------------968064918930967154199105236--
... """ % (ni_hao, wo_hen_hao), handle_errors=False)
HTTP/1.1 302 Moved Temporarily
...
Location: http://localhost/test_folder_1_/ftf/manage_main
...
We can test the object has the correct values, as unicode strings, of
course:
>>> unicodetest = self.folder.ftf.unicodetest
>>> unicodetest.title == ni_hao.decode('utf-8')
True
>>> unicodetest.description == wo_hen_hao.decode('utf-8')
True
>>> unicodetest.somenumber
0
Of course, the same should apply to edit forms. First, we happen to
again make the mistake of entering unicode data in the integer field:
>>> print http(r"""
... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... ChineseTitle
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... ChineseDescription
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Change
... -----------------------------968064918930967154199105236--
... """ % ni_hao, handle_errors=False)
HTTP/1.1 200 OK
...
There are <strong>1</strong> input errors.
...
We see that the object hasn't changed:
>>> unicodetest.title == ni_hao.decode('utf-8')
True
>>> unicodetest.description == wo_hen_hao.decode('utf-8')
True
>>> unicodetest.somenumber
0
Now we provide some valid form data:
>>> print http(r"""
... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... 1
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Change
... -----------------------------968064918930967154199105236--
... """ % (wo_hen_hao, ni_hao), handle_errors=False)
HTTP/1.1 200 OK
...
We see that the object's data has changed:
>>> unicodetest.title == wo_hen_hao.decode('utf-8')
True
>>> unicodetest.description == ni_hao.decode('utf-8')
True
>>> unicodetest.somenumber
1
Let's also not forget about List widgets. Let's see if we can add an
element to the list:
>>> print http(r"""
... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... 1
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somelist.add"
...
... Add
... -----------------------------968064918930967154199105236--
... """ % (wo_hen_hao, ni_hao), handle_errors=False)
HTTP/1.1 200 OK
...
...<input class="textType" id="field.somelist.0." name="field.somelist.0." size="20" type="text" value="" />...
...
Now, let's enter some more Chinese:
>>> de_guo = '\345\276\267\345\233\275'
>>> print http(r"""
... POST /test_folder_1_/ftf/unicodetest/@@edit.html HTTP/1.1
... Authorization: Basic manager:r00t
... Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
... Content-Type: multipart/form-data; boundary=---------------------------968064918930967154199105236
... Content-Length: 418
...
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.title"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.description"
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somenumber"
...
... 1
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="field.somelist.0."
...
... %s
... -----------------------------968064918930967154199105236
... Content-Disposition: form-data; name="UPDATE_SUBMIT"
...
... Change
... -----------------------------968064918930967154199105236--
... """ % (wo_hen_hao, ni_hao, de_guo), handle_errors=False)
HTTP/1.1 200 OK
...
The object's data will have changed accordingly:
>>> unicodetest.somelist == [de_guo.decode('utf-8')]
True
Object widget:
--------------
A little more complex is the ``ObjectWidget``. Here we simply test
that the edit form works:
>>> from Products.Five.tests.products.FiveTest.schemacontent import \
... manage_addComplexSchemaContent
>>> n = manage_addComplexSchemaContent(self.folder.ftf, 'objecttest')
>>> print http(r"""
... GET /test_folder_1_/ftf/objecttest/@@edit.html HTTP/1.1
... """, handle_errors=False)
HTTP/1.1 200 OK
...
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
#import simplecontent
#import fancycontent
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Browser views for tests.
$Id: browser.py 12915 2005-05-31 10:23:19Z philikon $
"""
from Products.Five import BrowserView
from Products.Five import StandardMacros as BaseMacros
from simplecontent import FieldSimpleContent
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Adapter test classes.
$Id: classes.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import implements
from interfaces import IAdaptable, IAdapted, IOrigin, IDestination
......
......@@ -355,7 +355,7 @@
<browser:addform
schema=".interfaces.IFieldSimpleContent"
content_factory=".simplecontent.FieldSimpleContent"
name="addsimplecontent.html"
name="addfieldcontent.html"
permission="zope2.Public"
/>
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Fancy content
$Id: fancycontent.py 12915 2005-05-31 10:23:19Z philikon $
"""
import Acquisition
from AccessControl import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test helpers
$Id: helpers.py 12915 2005-05-31 10:23:19Z philikon $
"""
import urllib
def add_and_edit(self, id, REQUEST):
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,8 +11,12 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test product interfaces
$Id: interfaces.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import Interface
from zope.schema import Text, TextLine, Object
from zope.schema import Text, TextLine, Object, Int, List
class IAdaptable(Interface):
"""This is a Zope 3 interface.
......@@ -50,18 +55,33 @@ class IFancyContent(Interface):
pass
class IFieldSimpleContent(ISimpleContent):
title = TextLine(
title=u"Title",
description=u"A short description of the event.",
default=u"",
required=True)
required=True
)
description = Text(
title=u"Description",
description=u"A long description of the event.",
default=u"",
required=False)
required=False
)
somenumber = Int(
title=u"Some number",
default=0,
required=False
)
somelist = List(
title=u"Some List",
value_type=TextLine(title=u"Some item"),
default=[],
required=False
)
class IComplexSchemaContent(Interface):
......@@ -76,4 +96,3 @@ class IComplexSchemaContent(Interface):
schema=IFieldSimpleContent,
description=u"The fishy object",
required=True)
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -14,7 +15,6 @@
$Id: metaconfigure.py 5287 2004-06-25 11:42:27Z philikon $
"""
from zope.interface import Interface
from zope.configuration.fields import GlobalObject
from zope.schema import TextLine
......
##############################################################################
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Schema content implementation
$Id: schemacontent.py 12915 2005-05-31 10:23:19Z philikon $
"""
from OFS.SimpleItem import SimpleItem
from Globals import InitializeClass
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Simple content implementationm
$Id: simplecontent.py 12915 2005-05-31 10:23:19Z philikon $
"""
from OFS.SimpleItem import SimpleItem
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
......
##############################################################################
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Size adapters
$Id: size.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zope.interface import implements
from zope.app.size.interfaces import ISized
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Event test fixtures
$Id: subscriber.py 12915 2005-05-31 10:23:19Z philikon $
"""
class EventCatcher:
def __init__(self):
self._events = []
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
# Runs all tests in the current directory
#
# Execute like:
......
##############################################################################
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Test adding views
$Id: test_adding.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import Products.Five.tests.fivetest # starts Zope, loads Five, etc.
def test_suite():
from Testing.ZopeTestCase import ZopeDocFileSuite
return ZopeDocFileSuite('adding.txt',
package="Products.Five.tests")
if __name__ == '__main__':
framework()
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,81 +11,57 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test forms
$Id$
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
from Products.Five.tests.fivetest import *
import Products.Five.tests.fivetest # starts Zope, loads Five, etc.
import unittest
from Testing.ZopeTestCase import ZopeDocTestSuite
from Testing.ZopeTestCase import FunctionalDocFileSuite
from AccessControl import Unauthorized
from zope.app.form.browser.submit import Update
def test_get_widgets_for_schema_fields():
"""
>>> from zope.schema import Choice, TextLine
>>> salutation = Choice(title=u'Salutation',
... values=("Mr.", "Mrs.", "Captain", "Don"))
>>> contactname = TextLine(title=u'Name')
>>> from Products.Five.traversable import FakeRequest
>>> request = FakeRequest()
>>> salutation = salutation.bind(request)
>>> contactname = contactname.bind(request)
from Products.Five.tests.products.FiveTest.simplecontent import manage_addFieldSimpleContent
from Products.Five.tests.products.FiveTest.helpers import manage_addFiveTraversableFolder
from Products.Five.tests.products.FiveTest.schemacontent import manage_addComplexSchemaContent
>>> from zope.app import zapi
>>> from zope.app.form.interfaces import IInputWidget
>>> from zope.app.form.browser.textwidgets import TextWidget
>>> from zope.app.form.browser.itemswidgets import DropdownWidget
>>> view1 = zapi.getViewProviding(contactname, IInputWidget, request)
>>> view1.__class__ == TextWidget
True
class EditFormTest(Functional, FiveTestCase):
>>> view2 = zapi.getViewProviding(salutation, IInputWidget, request)
>>> view2.__class__ == DropdownWidget
True
"""
def afterSetUp(self):
manage_addFieldSimpleContent(self.folder, 'edittest', 'Test')
def setUpForms(self):
uf = self.folder.acl_users
uf._doAddUser('viewer', 'secret', [], [])
uf._doAddUser('manager', 'r00t', ['Manager'], [])
def test_editform(self):
response = self.publish('/test_folder_1_/edittest/edit.html',
basic='manager:r00t')
# we're using a GET request to post variables, but seems to be
# the easiest..
response = self.publish(
'/test_folder_1_/edittest/edit.html?%s=1&field.title=FooTitle&field.description=FooDescription' % Update,
basic='manager:r00t')
self.assertEquals('FooTitle', self.folder.edittest.title)
self.assertEquals('FooDescription', self.folder.edittest.description)
def test_editform_invalid(self):
# missing title, which is required
self.folder.edittest.description = ''
response = self.publish(
'/test_folder_1_/edittest/edit.html?%s=1&field.title=&field.description=BarDescription' % Update,
basic='manager:r00t')
# we expect that we get a 200 Ok
self.assertEqual(200, response.getStatus())
self.assertEquals('Test', self.folder.edittest.title)
self.assertEquals('', self.folder.edittest.description)
def test_addform(self):
manage_addFiveTraversableFolder(self.folder, 'ftf')
self.folder = self.folder.ftf
response = self.publish('/test_folder_1_/ftf/+/addsimplecontent.html',
basic='manager:r00t')
self.assertEquals(200, response.getStatus())
# we're using a GET request to post variables, but seems to be
# the easiest..
response = self.publish(
'/test_folder_1_/ftf/+/addsimplecontent.html?%s=1&add_input_name=alpha&field.title=FooTitle&field.description=FooDescription' % Update,
basic='manager:r00t')
# we expect to get a 302 (redirect)
self.assertEquals(302, response.getStatus())
# we expect the object to be there with the right id
self.assertEquals('alpha', self.folder.alpha.id)
self.assertEquals('FooTitle', self.folder.alpha.title)
self.assertEquals('FooDescription', self.folder.alpha.description)
def test_objectWidget(self):
manage_addComplexSchemaContent(self.folder, 'csc')
response = self.publish('/test_folder_1_/csc/edit.html',
basic='manager:r00t')
self.assertEquals(200, response.getStatus())
def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(EditFormTest))
return suite
return unittest.TestSuite((
ZopeDocTestSuite(),
FunctionalDocFileSuite(
'forms.txt',
package="Products.Five.tests",
setUp=setUpForms),
))
if __name__ == '__main__':
framework()
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,8 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# test events triggered by Five
"""Test events triggered by Five
$Id: test_event.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
......@@ -61,7 +64,7 @@ class EventTest(FiveTestCase):
manage_addSimpleContent(self.folder, 'foo', 'Foo')
# somehow we need to at least commit a subtransaction to make
# renaming succeed
transaction.get().commit(1)
transaction.commit(1)
self.folder.manage_renameObject('foo', 'bar')
bar = self.folder.bar
events = objectEventCatcher.getEvents()
......@@ -95,7 +98,7 @@ class EventTest(FiveTestCase):
manage_addSimpleContent(folder1, 'foo', 'Foo')
foo = folder1.foo
# need to trigger subtransaction before copy/paste can work
transaction.get().commit(1)
transaction.commit(1)
cb = folder1.manage_cutObjects(['foo'])
folder2.manage_pasteObjects(cb)
newfoo = folder2.foo
......@@ -125,7 +128,7 @@ class EventTest(FiveTestCase):
manage_addNoVerifyPasteFolder(self.folder, 'folder1')
folder1 = self.folder.folder1
# need to trigger subtransaction before copy/paste can work
transaction.get().commit(1)
transaction.commit(1)
cb = self.folder.manage_copyObjects(['foo'])
folder1.manage_pasteObjects(cb)
foo_copy = folder1.foo
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Five tests.
$Id: test_five.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test security induced by ZCML
$Id: test_security.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,6 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test security from restricted Python interpreter
$Id: test_security2.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
......@@ -214,7 +219,7 @@ class PublishTest(Functional, FiveTestCase):
manage_addFiveTraversableFolder(self.folder, 'ftf')
# Unprotected as anonymous
response = self.publish('/test_folder_1_/ftf/+/addsimplecontent.html')
response = self.publish('/test_folder_1_/ftf/+/addfieldcontent.html')
self.assertEqual(response.getStatus(), 200)
# Protected as manager
......
##############################################################################
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Unit tests for the viewable module.
$Id: test_viewable.py 12948 2005-05-31 20:24:58Z philikon $
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import Products.Five.tests.fivetest # starts Zope, loads Five, etc.
def test_defaultView():
"""
Take a class Foo and an interface I1::
>>> class Foo:
... pass
>>> from zope.interface import Interface
>>> class I1(Interface):
... pass
Set up a default view for I1::
>>> from zope.app import zapi
>>> pres = zapi.getGlobalService('Presentation')
>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> pres.setDefaultViewName(I1, IBrowserRequest, 'foo.html')
and a BrowserDefault for an instance of Foo::
>>> foo = Foo()
>>> from Products.Five.viewable import BrowserDefault
>>> bd = BrowserDefault(foo)
You'll see that no default view is returned::
>>> request = self.app.REQUEST
>>> obj, path = bd.defaultView(request)
>>> obj is foo
True
>>> path is None
True
unless you mark the object with I1::
>>> from zope.interface import directlyProvides
>>> directlyProvides(foo, I1)
>>> obj, path = bd.defaultView(request)
>>> obj is foo
True
>>> path
['foo.html']
"""
def test_suite():
from Testing.ZopeTestCase import ZopeDocTestSuite
return ZopeDocTestSuite()
if __name__ == '__main__':
framework()
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -10,11 +11,13 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Load zope.conf for tests.
$Id: zopeconf.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os
from os.path import join, abspath, dirname, split, exists
def process():
"""Read in zope.conf configuration file.
......@@ -35,5 +38,5 @@ def process():
_config = join(_prefix, 'etc', 'zope.conf')
if exists(_config):
from Zope2 import configure
from Zope import configure
configure(_config)
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""Machinery for making things traversable through adaptation
$Id: traversable.py 9786 2005-03-15 12:53:39Z efge $
$Id: traversable.py 12915 2005-05-31 10:23:19Z philikon $
"""
from zExceptions import NotFound
from zope.exceptions import NotFoundError
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,9 +13,8 @@
##############################################################################
"""Machinery for making things viewable
$Id: traversable.py 5763 2004-07-28 20:15:11Z dreamcatcher $
$Id: viewable.py 12915 2005-05-31 10:23:19Z philikon $
"""
import inspect
from zExceptions import NotFound
from zope.exceptions import NotFoundError
......@@ -104,9 +104,8 @@ class BrowserDefault(object):
def defaultView(self, request):
context = self.context
name = None
try:
name = getDefaultViewName(context, request)
except ComponentLookupError:
pass
return context, [name,]
except ComponentLookupError:
return context, None
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
......@@ -12,7 +13,7 @@
##############################################################################
"""ZCML machinery
$Id: zcml.py 10534 2005-04-11 15:06:02Z dreamcatcher $
$Id: zcml.py 12915 2005-05-31 10:23:19Z philikon $
"""
import os
from zope.configuration import xmlconfig
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment