Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include school data in persisted slots #42

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion dbe/actions/actions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Any, Dict, List, Optional, Text, Union

from rasa_sdk import Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from whoosh.index import open_dir
from whoosh.qparser import MultifieldParser
from whoosh.query import FuzzyTerm, Term

from base.actions.actions import ActionExit, ActionSessionStart
from base.actions.actions import ActionExit
from base.actions.actions import ActionSessionStart as BaseActionSessionStart
from base.actions.actions import HealthCheckForm as BaseHealthCheckForm
from base.actions.actions import HealthCheckProfileForm as BaseHealthCheckProfileForm
from base.actions.actions import HealthCheckTermsForm
Expand Down Expand Up @@ -101,10 +103,20 @@ def get_eventstore_data(self, tracker: Tracker, risk: Text) -> Dict[Text, Any]:
return data


class ActionSessionStart(BaseActionSessionStart):
def get_carry_over_slots(self, tracker: Tracker) -> List[Dict[Text, Any]]:
actions = super().get_carry_over_slots(tracker)
carry_over_slots = ("school", "school_confirm", "school_emis")
for slot in carry_over_slots:
actions.append(SlotSet(slot, tracker.get_slot(slot)))
return actions


__all__ = [
"HealthCheckTermsForm",
"HealthCheckProfileForm",
"HealthCheckForm",
"ActionSessionStart",
"ActionExit",
"ActionSessionStart",
]
42 changes: 35 additions & 7 deletions dbe/tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from unittest import TestCase

from rasa_sdk import Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher

from dbe.actions.actions import HealthCheckForm, HealthCheckProfileForm
from dbe.actions.actions import (
ActionSessionStart,
HealthCheckForm,
HealthCheckProfileForm,
)


class HealthCheckProfileFormTests(TestCase):
Expand Down Expand Up @@ -51,9 +56,7 @@ def test_validate_school_confirm_no(self):
Try again getting the name of the school
"""
form = HealthCheckProfileForm()
tracker = Tracker(
"27820001001", {}, {}, [], False, None, {}, "action_listen"
)
tracker = Tracker("27820001001", {}, {}, [], False, None, {}, "action_listen")
dispatcher = CollectingDispatcher()
response = form.validate_school_confirm("no", dispatcher, tracker, {})
self.assertEqual(response, {"school": None, "school_confirm": None})
Expand All @@ -63,9 +66,7 @@ def test_validate_school_confirm_yes(self):
Confirms the name of the school
"""
form = HealthCheckProfileForm()
tracker = Tracker(
"27820001001", {}, {}, [], False, None, {}, "action_listen"
)
tracker = Tracker("27820001001", {}, {}, [], False, None, {}, "action_listen")
dispatcher = CollectingDispatcher()
response = form.validate_school_confirm("yes", dispatcher, tracker, {})
self.assertEqual(response, {"school_confirm": "yes"})
Expand Down Expand Up @@ -148,3 +149,30 @@ def test_eventstore_data(self):
},
},
)


class ActionSessionStartTests(TestCase):
def test_school_details_copied(self):
"""
Should copy over the school details to the new session
"""
action = ActionSessionStart()
events = action.get_carry_over_slots(
Tracker(
"27820001001",
{
"school": "BERGVLIET HIGH SCHOOL",
"school_emis": "105310201",
"school_confirm": "yes",
},
{},
[],
False,
None,
{},
"action_listen",
)
)
self.assertIn(SlotSet("school", "BERGVLIET HIGH SCHOOL"), events)
self.assertIn(SlotSet("school_emis", "105310201"), events)
self.assertIn(SlotSet("school_confirm", "yes"), events)
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if (( $# != 2 )); then
exit 1
fi

black .
isort -rc .
black --check .
isort -rc -c .
mypy "$1"
flake8 .
py.test
Expand Down