Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaumb authored and Jaumb committed Jul 17, 2019
2 parents cfed989 + 35c77d0 commit 856d286
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 134 deletions.
5 changes: 3 additions & 2 deletions brooklinevoiceapp/brookline_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
Dispatches MyCityRequestsObjects to the appropriate Brookline intent
"""

from mycity.mycity_response_data_model import MyCityResponseDataModel
import logging

from mycity.intents.police_station_intent import find_closest_police_station
from mycity.intents.trash_day_intent import get_trash_pickup_info
from mycity.intents.polling_stations_intent import get_polling_location_info
import logging
from mycity.mycity_response_data_model import MyCityResponseDataModel

logger = logging.getLogger(__name__)

Expand Down
29 changes: 15 additions & 14 deletions brooklinevoiceapp/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"""

import logging
from mycity.mycity_request_data_model import MyCityRequestDataModel

from brookline_controller import execute_request

from mycity.mycity_request_data_model import MyCityRequestDataModel

logger = logging.getLogger(__name__)


Expand All @@ -18,7 +19,7 @@ def lambda_handler(event, context):
:param event: JSON object containing the raw request information received
from the Alexa service platform
:param context: a LambdaContext object containing runtime info
:return: JSON response object to be sent to the Alexa service platform
:return: JSON response object to be sent to the Alexa service platform
"""
# Handle logger configuration here at the first use of the logger
while len(logging.root.handlers) > 0:
Expand All @@ -30,7 +31,7 @@ def lambda_handler(event, context):
logger.debug('Amazon request received: ' + str(event))

model = platform_to_mycity_request(event)
response = mycity_response_to_platform(execute_request(model))
response = mycity_response_to_platform(execute_request(model))
logger.debug(str(response))
return response

Expand All @@ -54,7 +55,7 @@ def platform_to_mycity_request(event):
system_context = event['context']['System']
mycity_request.device_id = system_context.get('device', {}).get('deviceId', "unknown")
mycity_request.api_access_token = system_context.get('apiAccessToken', "none")

if 'attributes' in event['session']:
mycity_request.session_attributes = event['session']['attributes']
else:
Expand Down Expand Up @@ -97,33 +98,33 @@ def mycity_response_to_platform(mycity_response):
'directives': [
mycity_response.dialog_directive
],
'card' : {
'card': {
'type': 'Simple',
'title': str(mycity_response.card_title),
'content': str(mycity_response.output_speech)
}
}
}
else:
else:
response = {
'outputSpeech': {
'type': 'PlainText',
'text': mycity_response.output_speech
},
},
'card': {
'type': 'Simple',
'title': str(mycity_response.card_title),
'content': str(mycity_response.output_speech)
},
'reprompt': {
'outputSpeech': {
'outputSpeech': {
'type': 'PlainText',
'text': mycity_response.reprompt_text
}
},
}
},
'shouldEndSession': mycity_response.should_end_session,
'directives' : [
'directives': [
mycity_response.dialog_directive
]
]
}
else:
response = {
Expand Down
4 changes: 2 additions & 2 deletions brooklinevoiceapp/mycity/intents/intent_constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Constants used across intents"""

# The key used for the current address in session attributes
CURRENT_ADDRESS_KEY = "currentAddress"
ZIP_CODE_KEY = "zipcode"

# Common responses
NO_RESULTS_RESPONSE = \
"Hmm I couldn't find anything for that address."
"Hmm I couldn't find anything for that address."
16 changes: 9 additions & 7 deletions brooklinevoiceapp/mycity/intents/police_station_intent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from mycity.utils.address_utils import set_address_in_session
import logging

from mycity.intents import intent_constants
from mycity.mycity_response_data_model import MyCityResponseDataModel
from mycity.utils.brookline_arcgis_api_utils import \
get_nearest_police_station_json

import logging
from mycity.utils.address_utils import set_address_in_session
from mycity.utils.brookline_arcgis_api_utils import (
get_nearest_police_station_json,
)

logger = logging.getLogger(__name__)

Expand All @@ -18,6 +19,7 @@
NAME_PATH = "NAME"
FULLADDR_PATH = "FULLADDR"


def find_closest_police_station(mycity_request):
"""
Finds the closest police station in Brookline
Expand All @@ -31,8 +33,8 @@ def find_closest_police_station(mycity_request):
response = MyCityResponseDataModel()
set_address_in_session(mycity_request)
current_address = \
mycity_request.session_attributes.get(intent_constants.CURRENT_ADDRESS_KEY)
if current_address is None:
mycity_request.session_attributes.get(intent_constants.CURRENT_ADDRESS_KEY)
if current_address is None:
response.dialog_directive = "Delegate"
else:
response.output_speech = _get_output_speech_for_address(current_address)
Expand Down
6 changes: 3 additions & 3 deletions brooklinevoiceapp/mycity/intents/trash_day_intent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
""" Intent for responding to trash day requests """
import logging
from mycity.mycity_response_data_model import MyCityResponseDataModel

from mycity.intents import intent_constants
from mycity.mycity_response_data_model import MyCityResponseDataModel
from mycity.utils.address_utils import set_address_in_session
from mycity.utils.brookline_arcgis_api_utils import get_trash_day_json


LOGGER = logging.getLogger(__name__)

# User facing strings
Expand All @@ -30,7 +30,7 @@ def get_trash_pickup_info(mycity_request):
response = MyCityResponseDataModel()
set_address_in_session(mycity_request)
current_address = \
mycity_request.session_attributes.get(intent_constants.CURRENT_ADDRESS_KEY)
mycity_request.session_attributes.get(intent_constants.CURRENT_ADDRESS_KEY)
if current_address is None:
# Delegate to the Alexa interaction model for getting the user address
LOGGER.debug('Requesting user address')
Expand Down
8 changes: 3 additions & 5 deletions brooklinevoiceapp/mycity/mycity_request_data_model.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""
Data Model for structuring requests to the skill implementation
"""
import json


class MyCityRequestDataModel:
"""
Represents a request from a voice platform.
Standard way requests are structured so they may be acted upon by
the skill implementation.
@todo: Consistent comment format that contains platform-specific terminology
Note:
The property methods below get and set attribute values.
"""
Expand Down Expand Up @@ -142,7 +141,6 @@ def intent_variables(self):
def intent_variables(self, value):
self._intent_variables = value


@property
def device_id(self):
"""
Expand All @@ -163,4 +161,4 @@ def api_access_token(self):

@api_access_token.setter
def api_access_token(self, value):
self._api_access_token = value
self._api_access_token = value
13 changes: 6 additions & 7 deletions brooklinevoiceapp/mycity/mycity_response_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@


class MyCityResponseDataModel:

"""
Represents a response to a voice platform.
Standard way of structuring responses from the skill implementation.
@todo: Consistent comment format that contains platform-specific terminology
Note:
Expand Down Expand Up @@ -128,7 +127,7 @@ def dialog_directive(self):
"""
String indicating the voice platform should modify the course of the
dialog with the user in some way.
In the case of "Dialog.Delegate", this signals that the Alexa platform
should "take charge" of this response to the user according to the
intent's dialog model.(usually involves prompting the user to
Expand All @@ -151,7 +150,7 @@ def dialog_directive(self, value):
if value == "Delegate":
self._dialog_directive = {'type': 'Dialog.Delegate'}
elif value == "ElicitSlotAddress":
self._dialog_directive = {
'type': 'Dialog.ElicitSlot',
'slotToElicit': 'Address'
}
self._dialog_directive = {
'type': 'Dialog.ElicitSlot',
'slotToElicit': 'Address'
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import typing
import unittest
from unittest import mock

import requests
import typing
import unittest.mock as mock

import brookline_controller as my_controller
import mycity.intents.intent_constants as intent_constants
import mycity.mycity_request_data_model as req
import mycity.utils.brookline_arcgis_api_utils as utils
from mycity import mycity_request_data_model as req
from mycity.intents import intent_constants
from mycity.utils import brookline_arcgis_api_utils as utils


###############################################################################
Expand All @@ -28,7 +30,6 @@ def json(self):


class IntentBaseCase(unittest.TestCase):

intent_to_test = None
expected_title = "Unhandled"
returns_reprompt_text = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_returns_correct_title_card(self):
self.assertEqual(response.card_title, self.expected_title)



# there are some intents where it makes sense to write custom tests for error
# messages so we can abstract the most common test as a mix in

Expand All @@ -30,4 +29,3 @@ def test_for_error_message(self):
response = self.controller.on_intent(self.request)
self.assertNotIn("Uh oh", response.output_speech)
self.assertNotIn("Error", response.output_speech)

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import mycity.test.test_constants as test_constants
import mycity.test.integration_tests.intent_base_case as base_case
import mycity.test.integration_tests.intent_test_mixins as mix_ins
import mycity.intents.police_station_intent as ps_intent
import mycity.intents.intent_constants as intent_constants
import copy

from mycity.intents import intent_constants, police_station_intent as ps_intent
from mycity.test import test_constants
from mycity.test.integration_tests import (
intent_base_case as base_case,
intent_test_mixins as mix_ins,
)

############################################
# TestCase class for police_station_intent #
############################################
Expand All @@ -18,10 +20,10 @@
NAME = ps_intent.NAME_PATH
FULLADDR = ps_intent.FULLADDR_PATH

class PoliceStationTestCase(mix_ins.RepromptTextTestMixIn,
mix_ins.CardTitleTestMixIn,
base_case.IntentBaseCase):

class PoliceStationTestCase(mix_ins.RepromptTextTestMixIn,
mix_ins.CardTitleTestMixIn,
base_case.IntentBaseCase):
intent_to_test = "PoliceStationIntent"
expected_title = ps_intent.CARD_TITLE_POLICE_STATION
returns_reprompt_text = False
Expand All @@ -40,7 +42,6 @@ def testResponseContainsNameAndFullAddress(self):
self.assertIn(feature[ATTRIBUTES][FULLADDR], response.output_speech)
self.assertIn(feature[ATTRIBUTES][NAME], response.output_speech)


def testNoFeatureResults(self):
self.mock_requests(get_data=copy.deepcopy(test_constants.GET_ADDRESS_CANDIDATES_API_MOCK),
post_data=copy.deepcopy(test_constants.NO_RESULTS_GET_POLICE_STATION_API_MOCK))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
""" Integration tests for TrashDayIntent """
import mycity.test.test_constants as test_constants
import mycity.test.integration_tests.intent_base_case as base_case
import mycity.test.integration_tests.intent_test_mixins as mix_ins
import mycity.intents.trash_day_intent as trash_intent
import mycity.intents.intent_constants as intent_constants
import copy

from mycity.intents import intent_constants, trash_day_intent as trash_intent
from mycity.test import test_constants
from mycity.test.integration_tests import (
intent_base_case as base_case,
intent_test_mixins as mix_ins,
)

MOCK_RESPONSE = test_constants.GET_TRASH_PICKUP_API_MOCK


class TrashPickupTestCase(mix_ins.RepromptTextTestMixIn,
mix_ins.CardTitleTestMixIn,
base_case.IntentBaseCase):

intent_to_test = "TrashDayIntent"
expected_title = trash_intent.CARD_TITLE_TRASH_DAY
returns_reprompt_text = False
Expand Down
25 changes: 1 addition & 24 deletions brooklinevoiceapp/mycity/test/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

##################################################################
# Mocked returns for patched functions that access web resources #
##################################################################
Expand Down Expand Up @@ -230,7 +229,7 @@
{
"attributes": {
"OBJECTID": 1,
"NAME": "Young Israel of Brookline, 62 Green St",
"NAME": "Young Israel of Brookline, 62 Green St (Side En",
"POLLINGID": "8",
"FULLADD": "345 HARVARD ST",
"CITY": "Brookline",
Expand Down Expand Up @@ -284,25 +283,3 @@
]
}

NO_RESPONSE_POLLING_LOCATIONS_API_MOCK = {
"displayFieldName": "NAME",
"fieldAliases": {
"OBJECTID": "OBJECTID",
"NAME": "Polling Location",
"POLLINGID": "Precinct",
"FULLADD": "Address",
"CITY": "City",
"STATE": "State",
"OPERHOURS": "Polling Hours",
"HANDICAP": "Handicap Accessible",
"NEXTELECT": "Next Election Date",
"REGDATE": "Voter Registration Deadline",
"CONTACT": "Contact Name",
"PHONE": "Phone",
"EMAIL": "Email",
"LASTUPDATE": "Last Update Date",
"LASTEDITOR": "Last Editor",
"PRECINCT": "PRECINCT"
},
"features": []
}
Loading

0 comments on commit 856d286

Please sign in to comment.