# Path: chat/ianswer.py
# def answer2xml(data):
#     """XML 封装答案
#     """
#     imgs = ''
#     img_urls = []
#     img_names = []
#     items = ''
#     result = {
#         "question": data['question'],
#         "content": data['content'],
#         "context": data['context'],
#         "url": data['url'],
#         "behavior": data['behavior'],
#         "parameter": data['parameter'],
#         "picurl": ""
#     }
#     # 对于无按钮图片的场景节点和问答节点，picurl 直接返回 '' 而不是格式化为 xml.
#     # Modify：2018-1-8
#     if data['button'] == '' and data['img'] == '':
#         return result
# 
#     if data['img'] != '':
#         for img in json.loads(data['img']):
#             img_urls.append(img['iurl'])
#             img_names.append(img['content'])
#         if img_names:
#             imgs = '|'.join(img_names)
#         if len(img_urls) > 1:
#             xml_items = [item.format(img_url=url) for url in img_urls[1:]]
#             items = ''.join(xml_items)
#     
#     result['picurl'] = answer.format(
#         timestamp=str(get_timestamp()),
#         news='news',
#         article_count=str(len(img_urls)),
#         content=data['content'], # Modify：场景中要说的话也放到 picurl 中(2018-1-8)
#         context=data['context'],
#         button=data['button'],
#         imgs=imgs,
#         img_url=img_urls[0] if img_urls else '',
#         items=items
#     )
# 
#     return result


import sys
from unittest import TestCase, main
from chat.ianswer import answer2xml

# -*- coding: utf-8 -*-
sys.path.append("../")

class TestMe(TestCase):
    def setUp(self):
        pass

    def test_answer2xml(self):
        data = {
            'question': "看看理财产品", # 用户问题
            'content': "我行的各种理财产品请参考下图，您可以点击图标查看详情，也可以语音或手动选择购买。",
            'context': "理财产品",
            'url': "",
            'behavior': 5376, # 0x1500

# Path: chat/ianswer.py
# def answer2xml(data):
#     """XML 封装答案
#     """
#     imgs = ''
#     img_urls = []
#     img_names = []
#     items = ''
#     result = {
#         "question": data['question'],
#         "content": data['content'],
#         "context": data['context'],
#         "url": data['url'],
#         "behavior": data['behavior'],
#         "parameter": data['parameter'],
#         "picurl": ""
#     }
#     # 对于无按钮图片的场景节点和问答节点，picurl 直接返回 '' 而不是格式化为 xml.
#     # Modify：2018-1-8
#     if data['button'] == '' and data['img'] == '':
#         return result
# 
#     if data['img'] != '':
#         for img in json.loads(data['img']):
#             img_urls.append(img['iurl'])
#             img_names.append(img['content'])
#         if img_names:
#             imgs = '|'.join(img_names)
#         if len(img_urls) > 1:
#             xml_items = [item.format(img_url=url) for url in img_urls[1:]]
#             items = ''.join(xml_items)
#     
#     result['picurl'] = answer.format(
#         timestamp=str(get_timestamp()),
#         news='news',
#         article_count=str(len(img_urls)),
#         content=data['content'], # Modify：场景中要说的话也放到 picurl 中(2018-1-8)
#         context=data['context'],
#         button=data['button'],
#         imgs=imgs,
#         img_url=img_urls[0] if img_urls else '',
#         items=items
#     )
# 
#     return result


# Path: tests/test_ianswer.py
import sys
from unittest import TestCase, main
from chat.ianswer import answer2xml

# -*- coding: utf-8 -*-
sys.path.append("../")

class TestMe(TestCase):
    def setUp(self):
        pass

    def test_answer2xml(self):
        data = {
            'question': "看看理财产品", # 用户问题
            'content': "我行的各种理财产品请参考下图，您可以点击图标查看详情，也可以语音或手动选择购买。",
            'context': "理财产品",
            'url': "",
            'behavior': 5376, # 0x1500

            'parameter': '{"id": 1, "level": 3, "pos": 0.5}',
