コード例 #1
0
    def test_call_GeneralRest(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDREST__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDREST__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._host = TemplateWordNode("hostname")
        node._method = TemplateWordNode("POST")
        node._query = TemplateWordNode('"userid":"1234567890"')
        node._header = TemplateWordNode('"Content-Type":"application/json"')
        node._body = TemplateWordNode("Hello")
        root.append(node)

        self.assertEqual("asked", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        self.assertEqual("asked", node.resolve(self._client_context))
        self.assertEqual("asked", question.property('__SUBAGENT_BODY__'))
コード例 #2
0
    def test_node_GeneralRest(self):
        ServiceFactory.clear()

        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateSRAIXNode()
        self.assertIsNotNone(node)
        node._default = "unknown"

        node._host = TemplateWordNode("hostname")
        node._method = TemplateWordNode("POST")
        node._query = TemplateWordNode('"userid":"1234567890"')
        node._header = TemplateWordNode('"Content-Type":"application/json"')
        node._body = TemplateWordNode("Hello")

        self.assertEqual("hostname", node._host.word)

        root.append(node)
        self.assertEqual(len(root.children), 1)

        with self.assertRaises(Exception):
            node.resolve_to_string(self._client_context)

        self.assertEqual(
            '[SRAIX (host=hostname, default=unknown, method=POST, ' +
            'query={"userid":"1234567890"}, header={"Content-Type":"application/json"}, '
            + 'body=Hello)]', node.to_string())
コード例 #3
0
    def test_to_xml_GeneralRest(self):
        root = TemplateNode()

        node = TemplateSRAIXNode()
        node._default = "unknown"
        root.append(node)

        node._host = TemplateWordNode("hostname")
        node._method = TemplateWordNode("POST")
        node._query = TemplateWordNode('"userid":"1234567890"')
        node._header = TemplateWordNode('"Content-Type":"application/json"')
        node._body = TemplateWordNode("Hello")

        with self.assertRaises(Exception):
            node.resolve_to_string(self._client_context)

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual(
            '<template><sraix default="unknown"><host>hostname</host><method>POST</method><query>"userid":"1234567890"</query>'
            +
            '<header>"Content-Type":"application/json"</header><body>Hello</body>'
            + '</sraix></template>', xml_str)