##############################################################################
#
# 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.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.
#
##############################################################################
"""Int Widget Functional Tests
$Id: test_intwidget.py 67630 2006-04-27 00:54:03Z jim $
"""
import unittest
import transaction
from persistent import Persistent
import zope.security.checker
from zope.interface import Interface, implements
from zope.schema import Int, Choice
from zope.traversing.api import traverse
from zope.app.testing.functional import BrowserTestCase
from zope.app.form.browser.ftests.support import *
class IIntTest(Interface):
i2 = Int(
required=False)
i3 = Choice(
required=False,
values=(0, 1, 2, 3, 5, 7, 11),
missing_value=0)
i1 = Int(
required=True,
min=1,
max=10)
class IIntTest2(Interface):
"""Used to test an unusual care where missing_value is -1 and
not in allowed_values."""
i1 = Choice(
required=False,
missing_value=-1,
values=(10, 20, 30))
class IntTest(Persistent):
implements(IIntTest)
def __init__(self):
self.i1 = None
self.i2 = 1
self.i3 = 2
class IntTest2(Persistent):
implements(IIntTest2)
def __init__(self):
self.i1 = 10
class Test(BrowserTestCase):
def setUp(self):
BrowserTestCase.setUp(self)
registerEditForm(IIntTest)
registerEditForm(IIntTest2)
defineSecurity(IntTest, IIntTest)
defineSecurity(IntTest2, IIntTest2)
def test_display_editform(self):
self.getRootFolder()['test'] = IntTest()
transaction.commit()
# display edit view
response = self.publish('/test/edit.html')
self.assertEqual(response.getStatus(), 200)
# i1 and i2 should be displayed in text fields
self.assert_(patternExists(
'', response.getBody()))
self.assert_(patternExists(
'', response.getBody()))
# i3 should be in a dropdown
self.assert_(patternExists(
'