Skip to content

Commit

Permalink
unittests/fallback_service
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 30, 2023
1 parent 39cd5e0 commit 76fe6ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
60 changes: 23 additions & 37 deletions test/end2end/session/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ def wait_for_n_messages(n):
# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance",
# Converse
"skill.converse.ping",
"skill.converse.pong",
# FallbackV2
"ovos.skills.fallback.ping",
"ovos.skills.fallback.pong",
# skill executing
f"ovos.skills.fallback.{self.skill_id}.request",
f"ovos.skills.fallback.{self.skill_id}.start",
"enclosure.active_skill",
"speak",
f"ovos.skills.fallback.{self.skill_id}.response",
# intent service post fallback
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"ovos.session.update_default"
Expand Down Expand Up @@ -80,42 +84,24 @@ def wait_for_n_messages(n):
self.assertEqual(messages[4].context["skill_id"], self.skill_id)
self.assertTrue(messages[4].data["can_handle"])

return
# high prio fallback
self.assertEqual(messages[3].msg_type, "mycroft.skills.fallback")
self.assertEqual(messages[3].data["fallback_range"], [0, 5])
self.assertEqual(messages[4].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[4].data["handler"], "fallback")
self.assertEqual(messages[5].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[5].data["handler"], "fallback")
self.assertEqual(messages[6].msg_type, "mycroft.skills.fallback.response")
self.assertFalse(messages[6].data["handled"])

# medium prio fallback
self.assertEqual(messages[7].msg_type, "mycroft.skills.fallback")
self.assertEqual(messages[7].data["fallback_range"], [5, 90])
self.assertEqual(messages[8].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[8].data["handler"], "fallback")
self.assertEqual(messages[9].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[9].data["handler"], "fallback")
self.assertEqual(messages[10].msg_type, "mycroft.skills.fallback.response")
self.assertFalse(messages[10].data["handled"])

# low prio fallback
self.assertEqual(messages[11].msg_type, "mycroft.skills.fallback")
self.assertEqual(messages[11].data["fallback_range"], [90, 101])
self.assertEqual(messages[12].msg_type, "mycroft.skill.handler.start")
self.assertEqual(messages[12].data["handler"], "fallback")
self.assertEqual(messages[13].msg_type, "mycroft.skill.handler.complete")
self.assertEqual(messages[13].data["handler"], "fallback")
self.assertEqual(messages[14].msg_type, "mycroft.skills.fallback.response")
self.assertFalse(messages[14].data["handled"])

# complete intent failure
self.assertEqual(messages[15].msg_type, "mycroft.audio.play_sound")
self.assertEqual(messages[15].data["uri"], "snd/error.mp3")
self.assertEqual(messages[16].msg_type, "complete_intent_failure")
# verify skill executes
self.assertEqual(messages[5].msg_type, f"ovos.skills.fallback.{self.skill_id}.request")
self.assertEqual(messages[5].data["skill_id"], self.skill_id)
self.assertEqual(messages[6].msg_type, f"ovos.skills.fallback.{self.skill_id}.start")
self.assertEqual(messages[7].msg_type, "enclosure.active_skill")
self.assertEqual(messages[7].data["skill_id"], self.skill_id)
self.assertEqual(messages[8].msg_type, "speak")
self.assertEqual(messages[8].data["meta"]["dialog"], "unknown")
self.assertEqual(messages[8].data["meta"]["skill"], self.skill_id)
self.assertEqual(messages[9].msg_type, f"ovos.skills.fallback.{self.skill_id}.response")
self.assertTrue(messages[9].data["result"])
self.assertEqual(messages[9].data["fallback_handler"], "UnknownSkill.handle_fallback")

# verify skill is activated
self.assertEqual(messages[10].msg_type, "intent.service.skills.activated")
self.assertEqual(messages[10].data["skill_id"], self.skill_id)
self.assertEqual(messages[11].msg_type, f"{self.skill_id}.activate")

# verify default session is now updated
self.assertEqual(messages[17].msg_type, "ovos.session.update_default")
self.assertEqual(messages[17].data["session_data"]["session_id"], "default")
self.assertEqual(messages[12].msg_type, "ovos.session.update_default")
self.assertEqual(messages[12].data["session_data"]["session_id"], "default")
3 changes: 3 additions & 0 deletions test/end2end/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,10 @@ def wait_for_n_messages(n):
# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance",
# Converse
"skill.converse.ping",
"skill.converse.pong",
# FallbackV1
"mycroft.skills.fallback",
"mycroft.skill.handler.start",
"mycroft.skill.handler.complete",
Expand All @@ -349,6 +351,7 @@ def wait_for_n_messages(n):
"mycroft.skill.handler.start",
"mycroft.skill.handler.complete",
"mycroft.skills.fallback.response",
# complete intent failure
"mycroft.audio.play_sound",
"complete_intent_failure",
"ovos.session.update_default"
Expand Down

0 comments on commit 76fe6ec

Please sign in to comment.