Fixes action result serialization

Attempt to serialize value that contained array of strings caused
endless recursion.

Change-Id: I5fe5b30b6d7ad6521a00ac3cbad21dccd812791d
Closes-Bug: #1435437
This commit is contained in:
Stan Lagun 2015-03-24 15:56:43 +03:00
parent bcb142cf7d
commit 4e54b4ef4c
3 changed files with 33 additions and 1 deletions

View File

@ -26,7 +26,8 @@ class ObjRef(object):
def serialize_object(obj):
if isinstance(obj, (collections.Sequence, collections.Set)):
if isinstance(obj, (collections.Sequence, collections.Set)) and not \
isinstance(obj, types.StringTypes):
return [serialize_object(t) for t in obj]
elif isinstance(obj, collections.Mapping):
result = {}

View File

@ -4,3 +4,15 @@ Properties:
class2Property:
Contract: $.string().notNull()
Methods:
testMethod:
Body:
Return:
key1: abc
key2: [a, b, c]
key3: null
key4: false
key5:
x: y
key6:
- w: q

View File

@ -17,6 +17,7 @@ import types
from testtools import matchers
from murano.dsl import serializer
from murano.tests.unit.dsl.foundation import object_model as om
from murano.tests.unit.dsl.foundation import test_case
@ -123,3 +124,21 @@ class TestResultsSerializer(test_case.DslTestCase):
self.assertEqual(
'John Snow',
runner2.on(self._class1).testAttributes('John'))
def test_value_deserialization(self):
"""Test serialization of arbitrary values that can be returned
from action methods
"""
runner = self.new_runner(self._class2)
result = runner.testMethod()
self.assertEqual(
{
'key1': 'abc',
'key2': ['a', 'b', 'c'],
'key3': None,
'key4': False,
'key5': {'x': 'y'},
'key6': [{'w': 'q'}]
},
serializer.serialize_object(result))