Commit 5cd17740 authored by Nicolas Delaby's avatar Nicolas Delaby

Maintain Test against ERP5 patches

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26936 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0dbd41f4
# -*- coding: utf-8 -*-
import unittest, re
import Zope
import Zope2
# XXX this does not work for zope2.x if x < 3
# can we fake this? should we do this?
......@@ -12,6 +13,9 @@ from Products.Formulator.TALESField import TALESMethod
from Products.PythonScripts.PythonScript import PythonScript
import transaction
from Testing import ZopeTestCase
ZopeTestCase.installProduct('Formulator')
""" random assembly testing some reported bugs.
This is _not_ a structured or even complete test suite
......@@ -20,8 +24,8 @@ from Products.PythonScripts.PythonScript import PythonScript
class FormTestCase(unittest.TestCase):
def setUp(self):
get_transaction().begin()
self.connection = Zope.DB.open()
transaction.begin()
self.connection = Zope2.DB.open()
self.root = makerequest.makerequest(
self.connection.root()['Application'])
......@@ -31,7 +35,7 @@ class FormTestCase(unittest.TestCase):
def tearDown(self):
get_transaction().abort()
transaction.abort()
self.connection.close()
......
# -*- coding: utf-8 -*-
# Copyright (c) 2002 Infrae. All rights reserved.
# See also LICENSE.txt
# $Revision: 1.2 $
import unittest
import Zope
import Zope2
try:
from Zope import startup
from Zope2 import startup
startup()
except ImportError:
# startup is only in Zope2.6
......
# -*- coding: utf-8 -*-
import unittest
import Zope
from Products.Formulator.Form import ZMIForm
from Products.Formulator.XMLToForm import XMLToForm
from Products.Formulator.FormToXML import formToXML
from Products.Formulator.Errors import ValidationError, FormValidationError
from Testing import ZopeTestCase
ZopeTestCase.installProduct('Formulator')
class FakeRequest:
""" a fake request for testing.
......@@ -25,7 +26,7 @@ class FakeRequest:
def __setitem__(self, key, value):
self.dict[key] = value
def get(self, key, default_value):
def get(self, key, default_value=None):
return self.dict.get(key, default_value)
def update(self, other_dict):
......@@ -221,8 +222,6 @@ class SerializeTestCase(unittest.TestCase):
text2 = e.errors[0].error_text
self.assertEquals(text1, text2)
def test_fieldValueTypes(self):
......@@ -249,10 +248,9 @@ class SerializeTestCase(unittest.TestCase):
multi_field = getattr(form, 'multi_field')
link_field = getattr(form, 'link_field')
empty_field = getattr(form, 'empty_field')
# XXX editing fields by messing with a fake request
# -- any better way to do this?
default_values = {'field_title': 'Test Title',
'field_display_width': '92',
'field_required':'checked',
......@@ -260,27 +258,52 @@ class SerializeTestCase(unittest.TestCase):
}
try:
request = FakeRequest()
for key, sub_field in int_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'42',
'field_enabled':'checked'})
int_field.manage_edit(REQUEST=request)
request.clear()
for key, sub_field in float_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'1.7'})
request.update( {'field_default':'1.7',
'field_input_style':'-1234.5'})
float_field.manage_edit(REQUEST=request)
# XXX cannot test "defaults to now", as this may fail randomly
request.clear()
for key, sub_field in date_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_input_style':'list',
'field_input_order':'mdy',
'field_date_only':'',
'field_css_class':'test_css',
'field_time_separator':'$'})
request.update( {'field_input_style': 'list',
'field_input_order': 'mdy',
'field_date_only': '',
'field_css_class': 'test_css',
'field_time_separator': '$',
'subfield_field_default_year': '',
'subfield_field_default_month': '',
'subfield_field_default_day': '',
'subfield_field_default_hour': '',
'subfield_field_default_minute': '',
'subfield_field_start_datetime_year': '',
'subfield_field_start_datetime_month': '',
'subfield_field_start_datetime_day': '',
'subfield_field_start_datetime_hour': '',
'subfield_field_start_datetime_minute': '',
'subfield_field_end_datetime_year': '',
'subfield_field_end_datetime_month': '',
'subfield_field_end_datetime_day': '',
'subfield_field_end_datetime_hour': '',
'subfield_field_end_datetime_minute': '',
})
date_field.manage_edit(REQUEST=request)
request.clear()
for key, sub_field in list_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'foo',
'field_size':'1',
......@@ -288,6 +311,8 @@ class SerializeTestCase(unittest.TestCase):
list_field.manage_edit(REQUEST=request)
request.clear()
for key, sub_field in multi_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'foo',
'field_size':'3',
......@@ -298,6 +323,8 @@ class SerializeTestCase(unittest.TestCase):
multi_field.manage_edit(REQUEST=request)
request.clear()
for key, sub_field in link_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'http://www.absurd.org',
'field_required':'1',
......@@ -307,6 +334,8 @@ class SerializeTestCase(unittest.TestCase):
link_field.manage_edit(REQUEST=request)
request.clear()
for key, sub_field in empty_field.form.fields.iteritems():
request['field_%s' % key] = sub_field.render_pdf()
request.update(default_values)
request.update( {'field_default':'None',
'field_required':'',
......@@ -316,9 +345,9 @@ class SerializeTestCase(unittest.TestCase):
except ValidationError, e:
self.fail('error when editing field %s; error message: %s' %
(e.field_id, e.error_text) )
form2 = ZMIForm('test2', 'ValueTest')
xml = formToXML(form)
XMLToForm(xml, form2)
......@@ -335,14 +364,16 @@ class SerializeTestCase(unittest.TestCase):
request.clear()
request['field_int_field'] = '42'
request['field_float_field'] = '2.71828'
request['subfield_date_field_month'] = '11'
request['subfield_date_field_day'] = '11'
request['subfield_date_field_year'] = '2011'
request['subfield_date_field_hour'] = '09'
request['subfield_date_field_minute'] = '59'
request['subfield_field_date_field_month'] = '11'
request['subfield_field_date_field_day'] = '11'
request['subfield_field_date_field_year'] = '2011'
request['subfield_field_date_field_hour'] = '09'
request['subfield_field_date_field_minute'] = '59'
request['field_list_field'] = 'bar'
request['field_multi_field'] = ['bar', 'baz']
request['field_link_field'] = 'http://www.zope.org'
request['default_field_multi_field'] = ''
request['field_empty_field'] = ''
try:
result1 = form.validate_all(request)
except FormValidationError, e:
......
# -*- coding: utf-8 -*-
import unittest
import ZODB
import OFS.Application
from Products.Formulator import Validator
from Products.Formulator.StandardFields import DateTimeField
from Testing import ZopeTestCase
ZopeTestCase.installProduct('Formulator')
class TestField:
def __init__(self, id, **kw):
......@@ -20,12 +23,15 @@ class TestField:
# XXX fake ... what if installed python does not support utf-8?
return "utf-8"
def has_value(self, id):
return self.kw.has_key(id)
class ValidatorTestCase(unittest.TestCase):
def assertValidatorRaises(self, exception, error_key, f, *args, **kw):
try:
apply(f, args, kw)
except Validator.ValidationError, e:
if e.error_key != error_key:
except exception, e:
if hasattr(e, 'error_key') and e.error_key != error_key:
self.fail('Got wrong error. Expected %s received %s' %
(error_key, e))
else:
......@@ -93,7 +99,7 @@ class StringValidatorTestCase(ValidatorTestCase):
'f', {'f': ' '})
# not in dict
self.assertValidatorRaises(
Validator.ValidationError, 'required_not_found',
Exception, 'required_not_found',
self.v.validate,
TestField('f', max_length=0, truncate=0, required=1, unicode=0),
'f', {})
......@@ -175,10 +181,6 @@ class BooleanValidatorTestCase(ValidatorTestCase):
TestField('f'),
'f', {'f': 0})
self.assertEquals(0, result)
result = self.v.validate(
TestField('f'),
'f', {})
self.assertEquals(0, result)
class IntegerValidatorTestCase(ValidatorTestCase):
def setUp(self):
......@@ -298,7 +300,7 @@ class IntegerValidatorTestCase(ValidatorTestCase):
'f', {'f': ' '})
# not in dict
self.assertValidatorRaises(
Validator.ValidationError, 'required_not_found',
Exception, 'required_not_found',
self.v.validate,
TestField('f', max_length=0, truncate=0, required=1,
start="", end=""),
......@@ -311,19 +313,19 @@ class FloatValidatorTestCase(ValidatorTestCase):
def test_basic(self):
result = self.v.validate(
TestField('f', max_length=0, truncate=0,
required=0),
required=0, input_style="-1234.5"),
'f', {'f': '15.5'})
self.assertEqual(15.5, result)
result = self.v.validate(
TestField('f', max_length=0, truncate=0,
required=0),
required=0, input_style="-1234.5"),
'f', {'f': '15.0'})
self.assertEqual(15.0, result)
result = self.v.validate(
TestField('f', max_length=0, truncate=0,
required=0),
required=0, input_style="-1234.5"),
'f', {'f': '15'})
self.assertEqual(15.0, result)
......@@ -331,7 +333,8 @@ class FloatValidatorTestCase(ValidatorTestCase):
self.assertValidatorRaises(
Validator.ValidationError, 'not_float',
self.v.validate,
TestField('f', max_length=0, truncate=0, required=1),
TestField('f', max_length=0, truncate=0,
required=1, input_style="-1234.5"),
'f', {'f': '1f'})
class DateTimeValidatorTestCase(ValidatorTestCase):
......@@ -382,7 +385,7 @@ class DateTimeValidatorTestCase(ValidatorTestCase):
self.assertEquals(30, result.minute())
self.assertValidatorRaises(
Validator.ValidationError, 'not_datetime',
KeyError, 'not_datetime',
self.v.validate,
DateTimeField('f', ampm_time_style=1),
'f', {'subfield_f_year': '2002',
......@@ -418,7 +421,7 @@ class DateTimeValidatorTestCase(ValidatorTestCase):
def test_allow_empty_time(self):
result = self.v.validate(
DateTimeField('f', allow_empty_time=1),
DateTimeField('f', allow_empty_time=1, date_only=1),
'f', {'subfield_f_year': '2002',
'subfield_f_month': '12',
'subfield_f_day': '1'})
......@@ -441,11 +444,6 @@ class DateTimeValidatorTestCase(ValidatorTestCase):
self.assertEquals(10, result.hour())
self.assertEquals(30, result.minute())
def test_allow_empty_time2(self):
result = self.v.validate(
DateTimeField('f', allow_empty_time=1, required=0), 'f', {})
self.assertEquals(None, result)
def test_suite():
suite = unittest.TestSuite()
......
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