diff --git a/.gitignore b/.gitignore index b601c41..91c63b8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,71 +3,9 @@ __pycache__/ *.py[cod] *$py.class -# C extensions -*.so # Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ *.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# IPython Notebook -.ipynb_checkpoints # pyenv .python-version @@ -82,21 +20,8 @@ celerybeat-schedule venv/ ENV/ -# Spyder project settings -.spyderproject - -# Rope project settings -.ropeproject - -# Vagrant -.vagrant - # Misc .DS_Store temp .idea/ -# Project -backups -settings.cfg -fabfile/settings.py diff --git a/flask_ask/core.py b/flask_ask/core.py index a641173..00ffc8b 100644 --- a/flask_ask/core.py +++ b/flask_ask/core.py @@ -804,6 +804,22 @@ def _map_player_request_to_func(self, player_request_type): return partial(view_func, *arg_values) + def _get_slot_value(self, slot_object): + slot_name = slot_object.name + slot_value = getattr(slot_object, 'value', None) + resolutions = getattr(slot_object, 'resolutions', None) + + if resolutions is not None: + resolutions_per_authority = getattr(resolutions, 'resolutionsPerAuthority', None) + if resolutions_per_authority is not None and len(resolutions_per_authority) > 0: + values = resolutions_per_authority[0].get('values', None) + if values is not None and len(values) > 0: + value = values[0].get('value', None) + if value is not None: + slot_value = value.get('name', slot_value) + + return slot_value + def _map_params_to_view_args(self, view_name, arg_names): arg_values = [] @@ -819,7 +835,7 @@ def _map_params_to_view_args(self, view_name, arg_names): if intent.slots is not None: for slot_key in intent.slots.keys(): slot_object = getattr(intent.slots, slot_key) - request_data[slot_object.name] = getattr(slot_object, 'value', None) + request_data[slot_object.name] = self._get_slot_value(slot_object=slot_object) else: for param_name in self.request: diff --git a/tests/test_integration_support_entity_resolution.py b/tests/test_integration_support_entity_resolution.py new file mode 100644 index 0000000..10b5055 --- /dev/null +++ b/tests/test_integration_support_entity_resolution.py @@ -0,0 +1,114 @@ +import unittest +import json +import uuid + +from flask_ask import Ask, statement +from flask import Flask + + +play_request = { + "version": "1.0", + "session": { + "new": False, + "sessionId": "amzn1.echo-api.session.f6ebc0ba-9d7a-4c3f-b056-b6c3f9da0713", + "application": { + "applicationId": "amzn1.ask.skill.26338c44-65da-4d58-aa75-c86b21271eb7" + }, + "user": { + "userId": "amzn1.ask.account.AHR7KBC3MFCX7LYT6HJBGDLIGQUU3FLANWCZ", + } + }, + "context": { + "AudioPlayer": { + "playerActivity": "IDLE" + }, + "Display": { + "token": "" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.26338c44-65da-4d58-aa75-c86b21271eb7" + }, + "user": { + "userId": "amzn1.ask.account.AHR7KBC3MFCX7LYT6HJBGDLIGQUU3FLANWCZ", + }, + "device": { + "deviceId": "amzn1.ask.device.AELNXV4JQJMF5QALYUQXHOZJ", + "supportedInterfaces": { + "AudioPlayer": {}, + "Display": { + "templateVersion": "1.0", + "markupVersion": "1.0" + } + } + }, + "apiEndpoint": "https://api.amazonalexa.com", + } + }, + "request": { + "type": "IntentRequest", + "requestId": "amzn1.echo-api.request.4859a7e3-1960-4ed9-ac7b-854309346916", + "timestamp": "2018-04-04T06:28:23Z", + "locale": "en-US", + "intent": { + "name": "TestCustomSlotTypeIntents", + "confirmationStatus": "NONE", + "slots": { + "child_info": { + "name": "child_info", + "value": "friends info", + "resolutions": { + "resolutionsPerAuthority": [ + { + "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.26338c44-65da-4d58-aa75-c86b21271eb7.child_info_type", + "status": { + "code": "ER_SUCCESS_MATCH" + }, + "values": [ + { + "value": { + "name": "friend_info", + "id": "FRIEND_INFO" + } + } + ] + } + ] + }, + "confirmationStatus": "NONE" + } + } + }, + "dialogState": "STARTED" + } +} + + +class AudioIntegrationTests(unittest.TestCase): + """ Integration tests of the Audio Directives """ + + def setUp(self): + self.app = Flask(__name__) + self.app.config['ASK_VERIFY_REQUESTS'] = False + self.ask = Ask(app=self.app, route='/ask') + self.client = self.app.test_client() + + @self.ask.intent('TestCustomSlotTypeIntents') + def custom_slot_type_intents(child_info): + return statement(child_info) + + def tearDown(self): + pass + + def test_play_intent(self): + """ Test to see if we can properly play a stream """ + response = self.client.post('/ask', data=json.dumps(play_request)) + self.assertEqual(200, response.status_code) + + data = json.loads(response.data.decode('utf-8')) + self.assertEqual('friend_info', + data['response']['outputSpeech']['text']) + + +if __name__ == '__main__': + unittest.main()