Commit ee96876d authored by Jérome Perrin's avatar Jérome Perrin

Fix the behaviour of string accessors when setter is called with unicode and

add some tests for string accessors conversion



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23032 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1bbb2393
...@@ -91,10 +91,11 @@ def asString(value): ...@@ -91,10 +91,11 @@ def asString(value):
try: try:
if value is None: if value is None:
result = '' result = ''
else:
if isinstance(value, unicode):
result = value.encode('utf-8')
else: else:
result = str(value) result = str(value)
if isinstance(result, unicode):
result = result.encode('utf-8')
except TypeError: except TypeError:
result = type_definition['string']['default'] result = type_definition['string']['default']
return result return result
......
############################################################################## ##############################################################################
# # -*- coding: utf8 -*-
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Yoshinori Okuji <yo@nexedi.com> # Yoshinori Okuji <yo@nexedi.com>
# #
...@@ -944,6 +944,21 @@ class TestPropertySheet: ...@@ -944,6 +944,21 @@ class TestPropertySheet:
self.assertTrue(person.hasProperty('dummy_ps_prop')) self.assertTrue(person.hasProperty('dummy_ps_prop'))
self.assertEquals('a value', person.getDummyPsProp()) self.assertEquals('a value', person.getDummyPsProp())
# string accessors converts the data type, if provided an unicode, it
# will store an utf-8 encoded string
person.setDummyPsProp(u'type convérsion')
self.assertEquals('type convérsion', person.getDummyPsProp())
# if provided anything else, it will store it's string representation
person.setDummyPsProp(1)
self.assertEquals('1', person.getDummyPsProp())
class Dummy:
def __str__(self):
return 'string representation'
person.setDummyPsProp(Dummy())
self.assertEquals('string representation', person.getDummyPsProp())
def test_17_WorkflowStateAccessor(self): def test_17_WorkflowStateAccessor(self):
"""Tests for workflow state. assumes that validation state is chained to """Tests for workflow state. assumes that validation state is chained to
the Person portal type and that this workflow has 'validation_state' as the Person portal type and that this workflow has 'validation_state' as
......
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