'Test handling of S3JSON @value attribute'

def testValueParsing(self):

    assertEqual = self.assertEqual
    json_str = '{\n"$_test_resource":    [\n                {\n                                "valuelist":    {\n                                                "@value":    ["value1",    "value2"]\n                                },\n                                "jsonlist":    {\n                                                "@value":    "[\\"value1\\",    \\"value2\\"]"\n                                },\n                                "valuestring":    {\n                                                "@value":    "value1"\n                                },\n                                "valueinteger":    {\n                                                "@value":    2\n                                }\n                }\n]}'
    tree = current.xml.json2tree(StringIO(json_str))
    root = tree.getroot()
    value_list = root.findall('resource/data[@field="valuelist"]')[0]
    v = value_list.get('value')
    assertEqual(v, '["value1",    "value2"]')
    assertEqual(json.loads(v), ['value1', 'value2'])
    value_list = root.findall('resource/data[@field="jsonlist"]')[0]
    v = value_list.get('value')
    assertEqual(v, '["value1",    "value2"]')
    assertEqual(json.loads(v), ['value1', 'value2'])
    value_list = root.findall('resource/data[@field="valuestring"]')[0]
    v = value_list.get('value')
    assertEqual(v, 'value1')
    value_list = root.findall('resource/data[@field="valueinteger"]')[0]
    v = value_list.get('value')
    assertEqual(v, '2')
