Skip to content

Commit

Permalink
Fill more of test_brookline_controller (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
endy-imam authored Apr 28, 2020
1 parent 24b2063 commit 54551d7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
13 changes: 8 additions & 5 deletions brooklinevoiceapp/brookline_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
logger = logging.getLogger(__name__)


LAUNCH_SPEECH = "Welcome to the Brookline Info skill. How can I help you?"
LAUNCH_REPROMPT_SPEECH = "You can ask about the nearest city services."
NO_REQUEST_SPEECH = "Hello from Brookline! We do not support that yet"


def execute_request(mycity_request):
"""
Executes a request to the town of Brookline available intents
Expand All @@ -32,7 +37,7 @@ def execute_request(mycity_request):
response = on_session_ended(mycity_request)
else:
response = MyCityResponseDataModel()
response.output_speech = "Hello from Brookline! We do not support that yet"
response.output_speech = NO_REQUEST_SPEECH

response.session_attributes = mycity_request.session_attributes
return response
Expand Down Expand Up @@ -69,14 +74,12 @@ def get_welcome_response(mycity_request):
mycity_response = MyCityResponseDataModel()
mycity_response.session_attributes = mycity_request.session_attributes
mycity_response.card_title = "Welcome"
mycity_response.output_speech = \
"Welcome to the Brookline Info skill. How can I help you? "
mycity_response.output_speech = LAUNCH_SPEECH

# If the user either does not reply to the welcome message or says
# something that is not understood, they will be prompted again with
# this text.
mycity_response.reprompt_text = \
"You can ask about the nearest city services."
mycity_response.reprompt_text = LAUNCH_REPROMPT_SPEECH
mycity_response.should_end_session = False
return mycity_response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,59 @@
"""

import brookline_controller as bl_con
import mycity.intents.intent_constants as intent_constants
import mycity.test.unit_tests.base as base


class BrooklineControllerUnitTestCase(base.BaseTestCase):
"""
testing:
execute_request
on_intent
get_welcome_response
handle_session_end_request
"""

def test_welcome_response(self):
self.request.is_new_session = False
self.request.request_type = "LaunchRequest"
expected_session_attributes = self.request.session_attributes
expected_output_speech = bl_con.LAUNCH_SPEECH
expected_reprompt_text = bl_con.LAUNCH_REPROMPT_SPEECH
expected_card_title = "Welcome"
response = self.controller.execute_request(self.request)
self.assertEqual(
response.session_attributes,
expected_session_attributes
)
self.assertEqual(response.output_speech, expected_output_speech)
self.assertEqual(response.reprompt_text, expected_reprompt_text)
self.assertFalse(response.should_end_session)

def test_execute_request_with_no_request_speech(self):
self.request.is_new_session = False
self.request.request_type = None
expected_output_speech = bl_con.NO_REQUEST_SPEECH
response = self.controller.execute_request(self.request)
self.assertEqual(response.output_speech, expected_output_speech)

def test_on_intent_AMAZON_StopIntent(self):
expected_attributes = self.request.session_attributes
expected_output_speech = (
"Thank you for using the Brookline Info skill. "
"See you next time!"
)
expected_card_title = "Brookline Info - Thanks"
self.request.request_type = "IntentRequest"
self.request.intent_name = "AMAZON.StopIntent"
response = self.controller.on_intent(self.request)
response = self.controller.execute_request(self.request)
self.assertEqual(response.session_attributes, expected_attributes)
self.assertEqual(response.output_speech, expected_output_speech)
self.assertEqual(response.card_title, expected_card_title)
self.assertIsNone(response.reprompt_text)

def test_unknown_intent(self):
self.request.intent_name = "MadeUpIntent"
self.request.session_attributes[intent_constants.CURRENT_ADDRESS_KEY] = '46 Everdean St'
with self.assertRaises(ValueError):
self.controller.on_intent(self.request)

0 comments on commit 54551d7

Please sign in to comment.