-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lambda_aws.py
More file actions
219 lines (170 loc) · 8.65 KB
/
Copy pathtest_lambda_aws.py
File metadata and controls
219 lines (170 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""Test module for the AWS lambda function."""
import pytest
import subprocess
STANDARDS = [
(['version'], '1.0'),
(['response', 'outputSpeech', 'type'], 'PlainText'),
(['response', 'card', 'type'], 'Simple'),
(['response', 'reprompt', 'outputSpeech', 'type'], 'PlainText'),
]
@pytest.mark.parametrize('response, expected', STANDARDS)
def test_launch_standards(launch, result_to_dict, response, expected):
"""Test multiple output as expected are returned from launch of skill."""
if len(response) == 1:
result = result_to_dict[response[0]]
elif len(response) == 3:
result = result_to_dict[response[0]][response[1]][response[2]]
elif len(response) == 4:
result = result_to_dict[response[0]] \
[response[1]][response[2]][response[3]]
assert result == expected
def test_launch_session_attributes(launch, result_to_dict):
"""SessionAttributes should return empty from launch of skill."""
assert result_to_dict['sessionAttributes'] == {}
def test_launch_card_content(launch, result_to_dict):
"""Welcome message should be returned from launch of skill."""
content = result_to_dict['response']['card']['content']
message = "Welcome to AIM messaging"
assert content == message
def test_launch_reprompt_speech(launch, result_to_dict):
"""Welcome message should be returned on launch of skill."""
text = result_to_dict['response']['reprompt']['outputSpeech']['text']
speech = "Do you want to send or receive a message."
assert text == speech
def test_launch_end_session(launch, result_to_dict):
"""End session should be 'False' when returned on launch of skill."""
end_session = result_to_dict['response']['shouldEndSession']
# speech = "Do you want to send or receive a message."
assert not end_session
@pytest.mark.parametrize('response, expected', STANDARDS)
def test_establish_recipient_standards(
launch, result_to_dict, response, expected):
"""Test several expected output are returned from EstablishRecipient."""
if len(response) == 1:
result = result_to_dict[response[0]]
elif len(response) == 3:
result = result_to_dict[response[0]][response[1]][response[2]]
elif len(response) == 4:
result = result_to_dict[response[0]] \
[response[1]][response[2]][response[3]]
assert result == expected
def test_establish_recipient_returns_receiver(establish_recipient,
result_to_dict):
"""Test receiver_name is 'DummyName'."""
assert 'DummyName' in result_to_dict['sessionAttributes']['receiver_name']
def test_establish_recipient_session_attributes(establish_recipient,
result_to_dict):
"""Test that session attributes are not empty dict"""
assert result_to_dict['sessionAttributes']
def test_establish_recipient_returns_output_speech(establish_recipient,
result_to_dict):
"""Test output speech for alexa is correct output."""
expected_output = "OK, send a message to DummyName, right?"
actual_output = result_to_dict['response']['outputSpeech']['text']
assert expected_output == actual_output
@pytest.mark.parametrize('response, expected', STANDARDS)
def test_establish_receive_message_standards(
receive_message, result_to_dict, response, expected):
"""Test several expected output are returned from EstablishRecipient."""
if len(response) == 1:
result = result_to_dict[response[0]]
elif len(response) == 3:
result = result_to_dict[response[0]][response[1]][response[2]]
elif len(response) == 4:
result = result_to_dict[response[0]] \
[response[1]][response[2]][response[3]]
assert result == expected
def test_receive_message_returns_no_messages(receive_message,
result_to_dict):
"""Test no message is returned when receiver has no message."""
speech_output = result_to_dict['response']['outputSpeech']['text']
expected_output = "There are no messages for dummyname. "
assert speech_output == expected_output
@pytest.mark.parametrize('response, expected', STANDARDS)
def test_establish_replay_message_standards(
replay_message, result_to_dict, response, expected):
"""Test several expected output are returned from EstablishRecipient."""
if len(response) == 1:
result = result_to_dict[response[0]]
elif len(response) == 3:
result = result_to_dict[response[0]][response[1]][response[2]]
elif len(response) == 4:
result = result_to_dict[response[0]] \
[response[1]][response[2]][response[3]]
assert result == expected
def test_replay_returns_correct_message(replay_message, result_to_dict):
"""Test replay returns correct_message."""
message = result_to_dict["sessionAttributes"]["message_body"]
expected_message = "I am a test message"
assert message == expected_message
def test_replay_returns_session_false(replay_message, result_to_dict):
"""Test replay returns end_session False."""
end_session = result_to_dict['response']['shouldEndSession']
assert not end_session
def test_no_intent_with_message_body(no_intent, result_to_dict):
"""NoIntent should return empty string because message erased."""
# message_body = "I am a test message"
message_from_aws = result_to_dict["sessionAttributes"]["message_body"]
assert "" == message_from_aws
def test_no_intent_without_message_body(no_intent_no_message, result_to_dict):
"""NoIntent should return empty session attribute.."""
# message_body = "I am a test message"
message_from_aws = result_to_dict["sessionAttributes"]
assert message_from_aws == {}
# def test_delete_message_by_sender_returns_deleted_message(delete_message,
# result_to_dict):
# """Speech output should return correct message."""
# speech_output = result_to_dict['response']['outputSpeech']['text']
# expected_output = "Your message has been deleted."
# assert speech_output == expected_output
@pytest.mark.parametrize('response, expected', STANDARDS)
def test_verify_message(verify_message, result_to_dict, response, expected):
"""Test numerous output as expected are returned from launch of skill."""
if len(response) == 1:
result = result_to_dict[response[0]]
elif len(response) == 3:
result = result_to_dict[response[0]][response[1]][response[2]]
elif len(response) == 4:
result = result_to_dict[response[0]] \
[response[1]][response[2]][response[3]]
assert result == expected
def test_help_function(help_message, result_to_dict):
"""Test that the help function returns proper response."""
response = result_to_dict['response']['outputSpeech']['text']
message = "Here's how to use AIM messaging. For example to send a \
message to Bob, say, send a message to Bob. And then \
follow the prompts. To receive a message, say, play \
messages for Bob. To replay a message, say, replay.\
To delete a message, say, delete a message from Bob."
assert response == message
def test_unsure_function(unsure_message, result_to_dict):
"""."""
card_from_aim = result_to_dict['response']['card']['title']
expected_text = 'AIM - unsure response'
assert card_from_aim == expected_text
def test_stop_function(stop_message, result_to_dict):
"""Test that the stop function returns proper response."""
response = result_to_dict['response']['outputSpeech']['text']
message = "Thank you for using AIM. See you next time!"
assert response == message
def test_delete_function(delete_message_from_db, result_to_dict):
"""Test that the delete function deletes message from DB."""
test = True
for i in delete_message_from_db["Items"]:
if "DummyDeleteName" in i: # pragma: no cover
test = False
assert test
def test_yes_intent_reprompts_for_message(yes_reprompt, result_to_dict):
"""Yes intent should reprompt if no message in slot."""
card = "what is your message"
card_from_aim = result_to_dict['response']['card']['title']
assert card == card_from_aim
def test_delete_no_message_function(delete_no_message, result_to_dict):
"""Test that the delete function returns proper message when there is nothing to delete."""
test = False
for i in delete_no_message["Items"]:
if "DummyDeleteName" in i: # pragma: no cover
test = True
response = result_to_dict['response']['outputSpeech']['text']
message = "You don't have any messages."
assert not test and message == response