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