示例#1
0
 async def test_parse_watson(self):
     with OpsDroid() as opsdroid:
         opsdroid.config["parsers"] = {"watson": {"enabled": True}}
         watson_intent = ""
         skill = amock.CoroutineMock()
         mock_connector = Connector({}, opsdroid=opsdroid)
         match_watson(watson_intent)(skill)
         message = Message("Hello world", "user", "default", mock_connector)
         with amock.patch("opsdroid.parsers.watson.parse_watson"):
             tasks = await opsdroid.parse(message)
             self.assertEqual(len(tasks), 2)
    async def test_parse_watson_APIException(self):
        with OpsDroid() as opsdroid:
            opsdroid.config["parsers"] = [{
                "name": "watson",
                "access-token": "test",
                "gateway": "gateway",
                "min-score": 0.3,
                "assistant-id": "test",
                "session-id": "12ndior2kld",
            }]
            mock_skill = await self.getMockSkill()
            opsdroid.skills.append(match_watson("hello")(mock_skill))

            mock_connector = amock.CoroutineMock()
            message = Message("hi", "user", "default", mock_connector)

            with amock.patch.object(watson,
                                    "call_watson") as mocked_call_watson:
                mocked_call_watson.side_effect = ApiException(
                    code=404, message="Not Found.")

                skills = await watson.parse_watson(
                    opsdroid, opsdroid.skills, message,
                    opsdroid.config["parsers"][0])
                self.assertEqual([], skills)
                self.assertLogs("_LOGGER", "error")
示例#3
0
async def test_match_watson(opsdroid):
    intent = "myIntent"
    decorator = matchers.match_watson(intent)
    opsdroid.skills.append(decorator(await get_mock_skill()))
    assert len(opsdroid.skills) == 1
    assert opsdroid.skills[0].matchers[0]["watson_intent"] == intent
    assert asyncio.iscoroutinefunction(opsdroid.skills[0]) is True
    async def test_parse_watson_no_confidence(self):
        with OpsDroid() as opsdroid:
            opsdroid.config["parsers"] = [{
                "name": "watson",
                "access-token": "test",
                "gateway": "gateway",
                "assistant-id": "test",
                "session-id": "12ndior2kld",
            }]
            mock_skill = await self.getMockSkill()
            opsdroid.skills.append(match_watson("hello")(mock_skill))

            mock_connector = amock.CoroutineMock()
            message = Message("hi", "user", "default", mock_connector)

            with amock.patch.object(watson,
                                    "call_watson") as mocked_call_watson:
                mocked_call_watson.return_value = {
                    "output": {
                        "generic": [{
                            "response_type": "text",
                            "text": "Hey hows it going?"
                        }],
                        "intents": [{
                            "intent": "hello"
                        }],
                        "entities": [],
                    }
                }
                skills = await watson.parse_watson(
                    opsdroid, opsdroid.skills, message,
                    opsdroid.config["parsers"][0])
                self.assertEqual(0.0, skills[0]["score"])
示例#5
0
async def test_parse_watson_APIException(opsdroid, caplog):
    opsdroid.config["parsers"] = [
        {
            "name": "watson",
            "token": "test",
            "gateway": "gateway",
            "min-score": 0.3,
            "assistant-id": "test",
            "session-id": "12ndior2kld",
        }
    ]
    mock_skill = await getMockSkill()
    opsdroid.skills.append(match_watson("hello")(mock_skill))

    mock_connector = amock.CoroutineMock()
    message = Message("hi", "user", "default", mock_connector)

    with amock.patch.object(watson, "call_watson") as mocked_call_watson:
        mocked_call_watson.side_effect = ApiException(code=404, message="Not Found.")

        skills = await watson.parse_watson(
            opsdroid, opsdroid.skills, message, opsdroid.config["parsers"][0]
        )
        assert skills == []
        assert "Watson Api error" in caplog.text
示例#6
0
async def test_parse_watson_no_intent(opsdroid, caplog):
    opsdroid.config["parsers"] = [
        {
            "name": "watson",
            "token": "test",
            "gateway": "gateway",
            "min-score": 0.3,
            "assistant-id": "test",
            "session-id": "12ndior2kld",
        }
    ]
    mock_skill = await getMockSkill()
    opsdroid.skills.append(match_watson("hello")(mock_skill))

    mock_connector = amock.CoroutineMock()
    message = Message("how's the weather outside", "user", "default", mock_connector)

    with amock.patch.object(watson, "call_watson") as mocked_call_watson:
        mocked_call_watson.return_value = {
            "output": {
                "generic": [{"response_type": "text", "text": "Hey hows it going?"}],
                "intents": [],
                "entities": [],
            }
        }
        skills = await watson.parse_watson(
            opsdroid, opsdroid.skills, message, opsdroid.config["parsers"][0]
        )
        assert skills == []
        assert "No intent found" in caplog.text
示例#7
0
 async def test_match_watson(self):
     with OpsDroid() as opsdroid:
         intent = "myIntent"
         decorator = matchers.match_watson(intent)
         opsdroid.skills.append(decorator(await self.getMockSkill()))
         self.assertEqual(len(opsdroid.skills), 1)
         self.assertEqual(opsdroid.skills[0].matchers[0]["watson_intent"], intent)
         self.assertTrue(asyncio.iscoroutinefunction(opsdroid.skills[0]))
示例#8
0
async def test_parse_watson_low_score(opsdroid, caplog):
    opsdroid.config["parsers"] = [
        {
            "name": "watson",
            "token": "test",
            "gateway": "gateway",
            "min-score": 0.5,
            "assistant-id": "test",
            "session-id": "12ndior2kld",
        }
    ]
    mock_skill = await getMockSkill()
    opsdroid.skills.append(match_watson("hello")(mock_skill))

    mock_connector = amock.CoroutineMock()
    message = Message("hi", "user", "default", mock_connector)

    with amock.patch.object(watson, "call_watson") as mocked_call_watson:
        mocked_call_watson.return_value = {
            "output": {
                "generic": [{"response_type": "text", "text": "Hey hows it going?"}],
                "intents": [{"intent": "hello", "confidence": 0.3}],
                "entities": [
                    {
                        "entity": "greetings",
                        "location": [0, 2],
                        "value": "hello",
                        "confidence": 1,
                    },
                    {
                        "entity": "greetings",
                        "location": [0, 2],
                        "value": "hi",
                        "confidence": 1,
                    },
                ],
            }
        }
        skills = await watson.parse_watson(
            opsdroid, opsdroid.skills, message, opsdroid.config["parsers"][0]
        )
        assert skills == []
        assert caplog