def test_extract_intent(): dr = DialogRouter(timezone=timezone("Asia/Tokyo")) context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "PizzaIntent" request.entities = {"key1": "value1"} intent, entities = dr.extract_intent(request, context, None) assert intent == "PizzaIntent" assert entities == {"key1": "value1"}
def test_route(): # update topic dr = MyDialogRouter(timezone=timezone("Asia/Tokyo"), default_dialog_service=EchoDialogService) context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "PizzaIntent" ds = dr.route(request, context, None) assert ds is PizzaDialogService # adhoc topic context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "AdhocIntent" request.is_adhoc = True ds = dr.route(request, context, None) assert ds is AdhocDialogService assert context.topic.name == "" # adhoc topic (keep previous topic) context = Context("TEST", "test_user") context.topic.name = "pizza" request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "AdhocIntent" request.is_adhoc = True request.intent_priority = Priority.High ds = dr.route(request, context, None) assert ds is AdhocDialogService assert context.topic.name == "pizza" assert context.topic.keep_on is True # continue topic context = Context("TEST", "test_user") context.topic.name = "pizza" request = Message(channel="TEST", channel_user_id="test_user", text="Hello") ds = dr.route(request, context, None) assert ds is PizzaDialogService assert context.topic.priority == Priority.Normal # not updated by same priority request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" ds = dr.route(request, context, None) assert ds is PizzaDialogService assert context.topic.priority == Priority.Normal # highest topic updated by highest intent context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "PizzaIntent" request.intent_priority = Priority.Highest ds = dr.route(request, context, None) assert ds is PizzaDialogService assert context.topic.priority == Priority.Highest - 1 # next message (not updated by lower than highest) request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" request.intent_priority = Priority.Highest - 1 ds = dr.route(request, context, None) assert ds is PizzaDialogService assert context.topic.priority == Priority.Highest - 1 # last message (updated by highest) request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" request.intent_priority = Priority.Highest ds = dr.route(request, context, None) assert ds is SobaDialogService assert context.topic.priority == Priority.Highest - 1 # no intent context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") ds = dr.route(request, context, None) assert ds is dr.default_dialog_service # unknown intent context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "UnknownIntent" ds = dr.route(request, context, None) assert ds is dr.default_dialog_service # dialog for intent not registered context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "NotRegisteredIntent" ds = dr.route(request, context, None) assert ds is DialogService # update topic by higher priority intent context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "PizzaIntent" ds = dr.route(request, context, None) assert ds is PizzaDialogService context.topic.keep_on = True # intent continue without intent request = Message(channel="TEST", channel_user_id="test_user", text="Hello") ds = dr.route(request, context, None) assert ds is PizzaDialogService context.topic.keep_on = True # soba intent with normal priority (not updated) request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" ds = dr.route(request, context, None) assert ds is PizzaDialogService context.topic.keep_on = True # soba intent with higher priority (updated) request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" request.intent_priority = Priority.High ds = dr.route(request, context, None) assert ds is SobaDialogService # update topic by normal priority intent context = Context("TEST", "test_user") request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "PizzaIntent" request.intent_priority = Priority.Low ds = dr.route(request, context, None) assert ds is PizzaDialogService context.topic.keep_on = True # intent continue without intent request = Message(channel="TEST", channel_user_id="test_user", text="Hello") ds = dr.route(request, context, None) assert ds is PizzaDialogService context.topic.keep_on = True # soba intent with normal priority (updated) request = Message(channel="TEST", channel_user_id="test_user", text="Hello") request.intent = "SobaIntent" ds = dr.route(request, context, None) assert ds is SobaDialogService